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);
}
}