Calling javascript code from applet
Tuesday, November 27, 2007
Sometimes you may want your applet to interact with javascript.
Apply this code to your applet class.
private void alert(){
try{
getAppletContext().showDocument(
new URL("javascript:doAlert()"));
}catch (MalformedURLException ex) { }
}
When running this code you'll execute the javascript doAlert() placed in the htm file where the <applet> tag is located.
<script language="javascript" type="text/javascript">
function doAlert() {
//some code to be executed...
alert('doAlert() exevcuted!');
}
</script>
-OR-
Using the netscape.javascript package in your java code and the mayscript option in your applet tag. For this you need a Netscape JAR file name java40.jar to compile the javascript code.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import netscape.javascript.*;
public class jsobject extends Applet implements ActionListener
{
Button button;
public void init()
{
button = new Button("hello");
button.addActionListener(this);
add(button);
}
public void actionPerformed(ActionEvent event)
{
JSObject obj = JSObject.getWindow(this);
obj.call("hello", null);
}
}
Regards,
Manesh Koovappillil
Labels: applet, code, java, javascript, Netscape JAR
posted by MIGHTYMAK @ 2:05 AM, ,
Opening Notepad (or any other external application) with JAVA
Wednesday, November 21, 2007
public class test {
public static void main(String args[])
{
System.out.println("\nSuccess");
Runtime r= Runtime.getRuntime();
Process p=null;
try {
p=r.exec("notepad.exe");
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Labels: java
posted by MIGHTYMAK @ 7:52 AM, ,
Nth highest Retrieval
Sunday, November 4, 2007
Consider a schema EMPLOYEE(name, salary). Now I want to find the employee name having nth highest salary.
For example "Find the name of the employee having 3rd highest salary?"
select salary
from (select rownum rn,b.salary from ( select unique salary from employee a order by salary desc) b)
where rn=N
-- OR --
[using aggregate function (min)]
select min(e.salary)
from(select salary from employee order by salary desc) e
where rownum <= N
Labels: Nth Highest Salary, Oracle interview questions, SQL Server
posted by MIGHTYMAK @ 5:25 AM, ,