java gui help!!
hi i need some help creating a gui in java, i have created a file chooser but i need some help in trying to use it, basically the way it should work is when i click the load button it will load a text file, then will display some information in the text file that the user will need to select, which will then open other information in the text file, can anyone help me?
the code i have so far is this:
/*
* Main.java
*
* Created on 09 April 2007, 12:04
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package filechooserframe;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.lang.*;
import javax.swing.*;
import javax.swing.filechooser.FileFilter;
publicclass Mainextends JFrameimplements ActionListener{
private File file;
private JFileChooser fileChooser;
public Main(){
super("File Chooser Demo");
setPreferredSize(new Dimension(300, 200));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.fileChooser =new JFileChooser(System.getProperty("user.dir"));
this.fileChooser.addChoosableFileFilter(new TXTFilter());
JMenuBar menuBar =new JMenuBar();
JMenu fileMenu =new JMenu("File");
JMenuItem loadItem =new JMenuItem("Load");
loadItem.addActionListener(this);
fileMenu.add(loadItem);
JMenuItem quitItem =new JMenuItem("Quit");
quitItem.addActionListener(this);
fileMenu.add(quitItem);
menuBar.add(fileMenu);
this.setJMenuBar(menuBar);
pack();
setVisible(true);
}
publicvoid actionPerformed(ActionEvent e)
{
int selectedOption = this.fileChooser.showDialog(this,"Load file");
switch (selectedOption)
{
case JFileChooser.APPROVE_OPTION:
System.err.println("selected file: "
+ this.fileChooser.getSelectedFile().getName());
File file = this.fileChooser.getSelectedFile();
break;
case JFileChooser.CANCEL_OPTION:
System.err.println("file choice cancelled");
break;
default:
System.err.println("file chooser dialog returned: "
+ selectedOption);
}
}
/**
* @param args the command line arguments
*/
publicstaticvoid main(String[] args)
{
new Main();
}
}
class TXTFilterextends FileFilter
{
publicboolean accept(File file)
{
return (file.getName().endsWith(".txt"));
}
public String getDescription()
{
return ("TXT files");
}
}

