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.

Results 1 to 8 of 8

Thread: How to call the executable jars using Jbutton

  1. #1
    Junior Member
    Join Date
    Aug 2014
    Posts
    4
    My Mood
    Amused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lightbulb How to call the executable jars using Jbutton

    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 01:27 AM.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,606
    My Mood
    Hungover
    Thanks
    145
    Thanked 658 Times in 563 Posts

    Default Re: How to call the executable jars using Jbutton

    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!

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,369
    Thanks
    183
    Thanked 836 Times in 779 Posts
    Blog Entries
    5

    Default Re: How to call the executable jars using Jbutton

    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

  4. #4
    Junior Member
    Join Date
    Aug 2014
    Posts
    4
    My Mood
    Amused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to call the executable jars using Jbutton

    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 04:57 AM.

  5. #5
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,606
    My Mood
    Hungover
    Thanks
    145
    Thanked 658 Times in 563 Posts

    Default Re: How to call the executable jars using Jbutton

    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!

  6. #6
    Junior Member
    Join Date
    Aug 2014
    Posts
    4
    My Mood
    Amused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to call the executable jars using Jbutton

    Quote Originally Posted by KevinWorkman View Post
    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?
    am new to java swing, so i don"t know where i have to call my jar file and how to include in the program

  7. #7
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,606
    My Mood
    Hungover
    Thanks
    145
    Thanked 658 Times in 563 Posts

    Default Re: How to call the executable jars using Jbutton

    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!

  8. #8
    Junior Member
    Join Date
    Aug 2014
    Posts
    4
    My Mood
    Amused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to call the executable jars using Jbutton

    Ok. Thanks!

    I will try to find in google, if not I will ask you.

Similar Threads

  1. Call windowClosing from JButton
    By iHank in forum AWT / Java Swing
    Replies: 3
    Last Post: December 27th, 2013, 11:38 AM
  2. Question about External Jars
    By Azurit3 in forum Java Theory & Questions
    Replies: 6
    Last Post: August 27th, 2012, 02:41 PM
  3. OS Specific Jars
    By sinistaDev80 in forum Java Theory & Questions
    Replies: 0
    Last Post: March 26th, 2011, 10:29 AM
  4. Programmatically Creating Jars
    By aussiemcgr in forum Java Theory & Questions
    Replies: 8
    Last Post: October 6th, 2010, 12:51 PM
  5. Making executable JAR more "executable"
    By ni4ni in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 1st, 2010, 02:19 PM

Tags for this Thread