Running the. exe file in the Java implementation file Selector

Source: Internet
Author: User

Import java.awt.*;


import java.awt.event.*;


import javax.swing.*;


import java.io.*;


class Chooserrun extends JFrame implements ActionListener


{


JButton button;


JTextArea text;


Jtextpane TextPane;


FileInputStream ReadFile;


JScrollPane Scroll;


//Container con;


Jpanel con;


jfilechooser chooser=new jfilechooser ();


//==========================================


public Chooserrun ()


{


super ("window with file selector");


button=new JButton ("Open file selector");


Button.addactionlistener (this);


textpane=new Jtextpane ();


jfilechooser chooser=new jfilechooser ();


scroll=new JScrollPane (TextPane);


//JFileChooser chooser=new jfilechooser ();


Cannot initialize here!


this.setsize (New Dimension (200,200));


setvisible (TRUE);


con= (Jpanel) This.getcontentpane ();


Con.add (Button,borderlayout.north);


Con.add (Scroll,borderlayout.center);


Addwindowlistener (New Windowadapter () {


public void windowclosing (WindowEvent e) {


Dispose (); System.exit (0);}});


}


//====================================================


public void actionperformed (ActionEvent e)


{


if (E.getsource () ==button)


{


String S;


int State =chooser.showopendialog (NULL);


File file=chooser.getselectedfile ();


{


Try


{Runtime ce=runtime.getruntime ();


ce.exec (file.tostring ());


}


catch (IOException E1)


{


E1.printstacktrace ();


}


}


}


}


//--------------------------------------


}


import Javax.swing.UIManager;


import java.awt.*;


public class MyTest


{


public static void Main (String args[])


{


chooserrun run=new chooserrun ();


Run.pack ();


Dimension screensize = Toolkit.getdefaulttoolkit (). Getscreensize ();


Dimension framesize = Run.getsize ();


if (Framesize.height > Screensize.height) {


framesize.height = screensize.height;


}


if (Framesize.width > Screensize.width) {


framesize.width = screensize.width;


}


run.setlocation (screensize.width-framesize.width)/2, (Screensize.height-framesize.height)/2);


}


}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.