Hi,
I've developed an application that uses two classes. The first class displays a very simple GUI with a start button. When the use presses the button an instance of the second class is created that reads the contents of a database and writes this to a file. I would like the second class to show the progress of the database read, with the help of a simple dialog that contains a JProgressBar.
My problem however is that what ever I tried to do so far), I only managed to display an empty frame that is only repainted when my database read is finished.
Thanks in advance for your help,
Tom
Pseudocode example:
Class 1:
public static void main(String[] args)
{
//Create and set up the window.
frame = new JFrame("GUI for Class1"
;
//Create and set up the content pane.
JPanel newTest = new JPanel();
newTest.add(StartButton);
frame.setContentPane(newTest);
//Display the window.
frame.pack();
frame.setVisible(true);
}
// ActionListener for start button
public void actionPerformed(ActionEvent e)
{
frame.setVisible(false);
Class2 databaseReader = new Class2();
databaseReader.start();
frame.setVisible(true);
}
Class 2:
private JFrame frame = null;
private int currentRecord = 0;
public JProgressBar progressBar = null;
public Class2()
{
openDatabase();
int myTotalRecords = getTotalDatabaseRecords();
frame = new JFrame("Processing....."
;
ProcessMonitor monitor = new ProcessMonitor();
progressBar.setMaximum(myTotalRecords);
progressBar.setValue(0);
monitor.setOpaque(true);
frame.setContentPane(monitor);
frame.pack();
frame.setVisible(true); // shows empty frame!!!
}
public start()
{
while (not databaseEOF)
{
readNextDatabaseRecord();
currentRecord++;
progressBar.setValue(currentRecord);
}
}
class ProcessMonitor extends JPanel
{
public ProcessMonitor()
{
progressBar = new JProgressBar();
progressBar.setStringPainted(true);
add(progressBar);
}
}
I've developed an application that uses two classes. The first class displays a very simple GUI with a start button. When the use presses the button an instance of the second class is created that reads the contents of a database and writes this to a file. I would like the second class to show the progress of the database read, with the help of a simple dialog that contains a JProgressBar.
My problem however is that what ever I tried to do so far), I only managed to display an empty frame that is only repainted when my database read is finished.
Thanks in advance for your help,
Tom
Pseudocode example:
Class 1:
public static void main(String[] args)
{
//Create and set up the window.
frame = new JFrame("GUI for Class1"
//Create and set up the content pane.
JPanel newTest = new JPanel();
newTest.add(StartButton);
frame.setContentPane(newTest);
//Display the window.
frame.pack();
frame.setVisible(true);
}
// ActionListener for start button
public void actionPerformed(ActionEvent e)
{
frame.setVisible(false);
Class2 databaseReader = new Class2();
databaseReader.start();
frame.setVisible(true);
}
Class 2:
private JFrame frame = null;
private int currentRecord = 0;
public JProgressBar progressBar = null;
public Class2()
{
openDatabase();
int myTotalRecords = getTotalDatabaseRecords();
frame = new JFrame("Processing....."
ProcessMonitor monitor = new ProcessMonitor();
progressBar.setMaximum(myTotalRecords);
progressBar.setValue(0);
monitor.setOpaque(true);
frame.setContentPane(monitor);
frame.pack();
frame.setVisible(true); // shows empty frame!!!
}
public start()
{
while (not databaseEOF)
{
readNextDatabaseRecord();
currentRecord++;
progressBar.setValue(currentRecord);
}
}
class ProcessMonitor extends JPanel
{
public ProcessMonitor()
{
progressBar = new JProgressBar();
progressBar.setStringPainted(true);
add(progressBar);
}
}