For the past few days I have been struggling with creating a GUI for a program I am developing with the aim of extracting index.dat files. The user selects the file they wish to analyse, the program outputs various details to the interface. However, I am having issues trying to implement this with the JLabel 'size'. Others such as the JTextAreas have not yet been attempted.
The program itself runs fine in the background however, none of the details are added to the interface itself.
The following is the code I have so far for implementing the GUI, apologise if this seems messy, however I have been editing it quite abit recently trying to solve the issue. Not all aspects of this program have been implemented yet, such as methods for editing the JTextAreas, as I am currently just trying to solve the setIndexInfo() method when editing the 'size' JLabel.
public class GUInterface extends JFrame implements ActionListener
{
//creating GUI variables
JMenuBar menuBar;
JMenu file;
JMenuItem historyItem, flashItem, exit;
JFileChooser filechoose;
JPanel info, top, output, cacheDisplay;
JTextArea cache, display;
JLabel type, loc, size;
JScrollPane scrollpane;
File f = new File("C:\\");
String locStr;
public void create()
{
guInterface();
}//end create
public void guInterface()
{
//initialising variables
menuBar = new JMenuBar();
file = new JMenu("File");
historyItem = new JMenuItem("Index.dat");
flashItem = new JMenuItem("Flash Cookies");
exit = new JMenuItem("Exit");
filechoose = new JFileChooser();
info = new JPanel();
top = new JPanel();
cacheDisplay = new JPanel();
cache = new JTextArea(9, 10);
type = new JLabel("AnalysisType");
loc = new JLabel("FileLoc");
size = new JLabel("Size");
//creating menu bar
menuBar.add(file);
file.add(historyItem);
file.add(flashItem);
file.addSeparator();
file.add(exit);
//info
info.setLayout(new BoxLayout(info, BoxLayout.Y_AXIS));
type.setFont(new Font("Serif", Font.BOLD, 30));
info.add(type);
info.add(Box.createRigidArea(new Dimension(0,5)));
loc.setFont(new Font("Serif", Font.BOLD, 20));
info.add(loc);
info.add(Box.createRigidArea(new Dimension(0,5)));
size.setFont(new Font("Serif", Font.BOLD, 20));
info.add(size);
//cacheDisplay
cacheDisplay.add(cache);
cache.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
cache.setMaximumSize(new Dimension(200, 200));
cache.setLineWrap(true);
cache.setEditable(false);
cache.setSize(200,100);
//top panel
top.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
top.setLayout(new BoxLayout(top, BoxLayout.X_AXIS));
top.add(info);
top.add(Box.createHorizontalGlue());
top.add(cache);
filechoose.setCurrentDirectory(f);
historyItem.addActionListener(this);
flashItem.addActionListener(this);
exit.addActionListener(this);
setJMenuBar(menuBar);
//JFrame layout
setLayout(new BorderLayout());
add(top, BorderLayout.NORTH);
//creating main area
setSize(1000, 600);
setLocationRelativeTo(null);
setTitle("PrivateBrowse - Private Browsing Recovery Tool");
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}//end guInterface
public void setIndexInfo(String output)
{
size = new JLabel(output);
size.setFont(new Font("Serif", Font.BOLD, 20));
}//end setIndexInfo
public void actionPerformed(ActionEvent evt)
{
if(evt.getSource() == historyItem)
{
filechoose.setDialogTitle("Select index.dat");
filechoose.setFileSelectionMode(JFileChooser.FILES_ONLY);
if(filechoose.showOpenDialog(null) == filechoose.APPROVE_OPTION)
{
type.setText("Index.DAT Analysis");
locStr = filechoose.getSelectedFile().toString();
loc.setText(locStr);
try
{
IndexRecovery idxRcvy = new IndexRecovery();
idxRcvy.readFile(locStr);
}
catch(Exception e)
{
System.out.println("Error: " + e);
}
}
}
else if(evt.getSource() == flashItem)
{
filechoose.setDialogTitle("Select #SharedObjects Directory");
filechoose.setApproveButtonText("Select");
filechoose.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
if(filechoose.showOpenDialog(null) == filechoose.APPROVE_OPTION)
{
type.setText("Flash Cookie Analysis");
locStr = filechoose.getSelectedFile().toString();
loc.setText(locStr);
try
{
FlashRecovery flshRcvy = new FlashRecovery();
flshRcvy.extractFlash(locStr);
}
catch(Exception e)
{
System.out.println("Error: " + e);
}
}
}
else if(evt.getSource() == exit)
{
setVisible(false);
dispose();
System.exit(0);
}
}//end actionPerformed
}
The class IndexRecovery calls setIndexInfo() with the size wanted to be displayed in the JLable 'size'.
I have been looking around and heard of various functions such as repaint() and validate(), however have no clue how to use these should these be the solution.
This has also been posted in the Swing forum.
Any advice on the matter will be greatly appreciated.
Thanks,
David.