Could you please any one of them explain how run the executable jar files using JButton from another class file.
I need, when i click the button then the executable jar file should be and display the output.
Thanks!
Bhas
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Could you please any one of them explain how run the executable jar files using JButton from another class file.
I need, when i click the button then the executable jar file should be and display the output.
Thanks!
Bhas
Last edited by Bhas; August 8th, 2014 at 12:27 AM.
Either put the jars on your classpath and call their main method, or use a ProcessBuilder to run the jars from the command line.
Post an MCVE showing exactly where you're stuck, and we'll go from there.
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
1) add an action listener to the JButton
2) in the ActionListener implementation
a) Create a process using ProcessBuilder or Runtime.exec or and get the results
b) Read in the jar contents using reflection, calling the appropriate method
My jar file name is test1.jar (run able jar file)
how to call a run-able jar file (test1.jar) when i select the Radio button (Test1) in swing
could you please send me a sample code for how to call the jar file using ActionListener'
Here is my code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Convertor {
private JFrame mainFrame;
private JLabel headerLabel;
private JLabel statusLabel;
private JPanel controlPanel;
static String str="";
public Convertor(){
prepareGUI();
}
public static void main(String[] args){
Convertor swingControlDemo = new Convertor();
swingControlDemo.showRadioButtonDemo();
}
private void prepareGUI(){
mainFrame = new JFrame("Define.xml");
mainFrame.setSize(400,400);
mainFrame.setLayout(new GridLayout(3, 1));
mainFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent windowEvent){
System.exit(0);
}
});
headerLabel = new JLabel("", JLabel.CENTER);
statusLabel = new JLabel("",JLabel.CENTER);
statusLabel.setSize(350,100);
controlPanel = new JPanel();
controlPanel.setLayout(new FlowLayout());
mainFrame.add(headerLabel);
mainFrame.add(controlPanel);
mainFrame.add(statusLabel);
mainFrame.setVisible(true);
}
private void showRadioButtonDemo(){
headerLabel.setText("Select the Standard");
final JRadioButton Test1 = new JRadioButton("Test1");
final JRadioButton Test2 = new JRadioButton("Test2");
Test1.setMnemonic(KeyEvent.VK_C);
Test2.setMnemonic(KeyEvent.VK_M);
Test1.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
statusLabel.setText("Test1 RadioButton: "
+ (e.getStateChange()==1?"checked":"unchecked"));
}
});
Test2.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
statusLabel.setText("Test1 RadioButton: "
+ (e.getStateChange()==1?"checked":"unchecked"));
}
});
controlPanel.add(Test1);
controlPanel.add(Test2);
//Group the radio buttons.
ButtonGroup group = new ButtonGroup();
group.add(Test1);
group.add(Test2);
mainFrame.setVisible(true);
}
}
Thanks!
Bhas
Last edited by Bhas; August 8th, 2014 at 03:57 AM.
When posting code, please use the highlight tags to preserve formatting.
We gave you a few suggestions. What happened when you tried one of them? What exactly are you confused about?
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
Which part is confusing you? Do you know how to add an ActionListener to a JButton? If not, start there. Google is your friend.
If you do know how to use ActionListeners, then we've given you a few ways to call a jar from an ActionListener. Which approach have you tried? What are you confused about that approach? Where is your updated code?
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
Ok. Thanks!
I will try to find in google, if not I will ask you.