Some time it’s become very
difficult to access any application or to execute commands in java applet. And
many of us don’t know how to do this, so I am going to explain how to access or
execute any command in Applet. Consider the following program, when you execute
it, it will directly open a Firefox application, and you can also replace it
with any commands of Linux or windows.
import java.awt.*; // Packages
import
java.io.IOException;
import
java.io.InputStream.*;
import
java.awt.event.*;
import
java.applet.*;
public
class Firefox extends Applet
{
String command="firefox";
public void init()
{
// Construct the button
Button browser = new
Button("Browser");
// add the button to the layout
this.add(browser);
// specify that action events sent by this
browser.addActionListener(new
BeepAction());
try
{
Runtime.getRuntime().exec(command);
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
If you don’t have any idea about Applet programming then just follow the following link and just downloads PDF files as per your requirement.
Every Java application has a single instance of class
Runtime
that allows the application to interface
with the environment in which the application is running. The current runtime
can be obtained from the getRuntime
method.
Prints the throwable and
the throwable’s call trace. The call stack shows the sequence of method calls
that brought you to the point at which exception was thrown.
The first version prints to standard error, the second
prints to a stream of your choice. If you’re working under Windows, you can’t
redirect standard error so you might want to use the second version and send
the results to System.out; that way the output can be redirected any way
you want.
No comments:
Post a Comment