Dear All,
I made a GUI based on java.... what is the code for button that opens a a program for you ..
lets say I want to press button and this will open excel or what ever program for me..
How can I achieve this ?
Printable View
Dear All,
I made a GUI based on java.... what is the code for button that opens a a program for you ..
lets say I want to press button and this will open excel or what ever program for me..
How can I achieve this ?
There are two parts to your project:
One - recognize and handle button presses - look at Action and ActionListeners.
Two - invoking another program - look at Process and Runtime
Please give me more detail... what to search for ?
answered in the sun java forums.
Code:JButton exec=new JButton("Open Excel");
exec.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
try {
// Execute a command 'excel'
String command = "excel";
Process child = Runtime.getRuntime().exec(command);
} catch (IOException e) {
}
}
});
[/code]