thelordoftherings
Programmer
Hello,
I have a simple GUI which contains a progress bar.
The problem is that the progress bar is reaching to 100% and only than the Window loads. I would like that the progress bar will be working with the GUI and not after it. What do I need to change in the following code in order to acheive this:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Main extends JFrame
{
public Main()
{
getContentPane().add(new MyContainer());
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
public static void main(String[] args)
{
Main dasFenster = new Main();
dasFenster.setSize(600,200);
dasFenster.setTitle("Partitionsimage");
dasFenster.setVisible(true);
}
}
class MyContainer extends Container
{
public MyContainer()
{
setLayout(new BorderLayout(10,10));
setBackground(Color.darkGray);
NordPanel nord = new NordPanel();
add(nord, BorderLayout.NORTH );
SuedPanel sued =new SuedPanel();
add(sued, BorderLayout.SOUTH );
}
}
class NordPanel extends JPanel
{
private JTextField dasEingabeFeld = new JTextField(5);
private JButton derSicherungsButton = new JButton("Sichern");
private JButton derRestoreButton = new JButton("Restaurieren");
private JLabel dasStatusLabel = new JLabel("Keine Aktion");
public NordPanel()
{
setBackground(Color.green);
setLayout(new FlowLayout());
add(new JLabel("Partition # "));
add(dasEingabeFeld);
add(derSicherungsButton);
add(derRestoreButton);
add(new JLabel("Status: "));
add(dasStatusLabel);
derSicherungsButton.addMouseListener(new java.awt.event.MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
int g = Integer.parseInt(dasEingabeFeld.getText());
}
});
}
}
class SuedPanel extends JPanel
{
public SuedPanel()
{
setBackground(Color.blue);
setLayout(new FlowLayout());
final int max = 10;
final JProgressBar balken = new JProgressBar( 0, max );
add( balken );
for ( int i = 1; i <= 10; i++ )
{
try
{
Thread.sleep( 1500 );
}
catch ( InterruptedException e ) { }
final int j = i;
SwingUtilities.invokeLater(
new Runnable()
{
public void run()
{
balken.setValue( j );
balken.paint(balken.getGraphics());
balken.setStringPainted(true);
}
}
);
}
}
}
I have a simple GUI which contains a progress bar.
The problem is that the progress bar is reaching to 100% and only than the Window loads. I would like that the progress bar will be working with the GUI and not after it. What do I need to change in the following code in order to acheive this:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Main extends JFrame
{
public Main()
{
getContentPane().add(new MyContainer());
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
public static void main(String[] args)
{
Main dasFenster = new Main();
dasFenster.setSize(600,200);
dasFenster.setTitle("Partitionsimage");
dasFenster.setVisible(true);
}
}
class MyContainer extends Container
{
public MyContainer()
{
setLayout(new BorderLayout(10,10));
setBackground(Color.darkGray);
NordPanel nord = new NordPanel();
add(nord, BorderLayout.NORTH );
SuedPanel sued =new SuedPanel();
add(sued, BorderLayout.SOUTH );
}
}
class NordPanel extends JPanel
{
private JTextField dasEingabeFeld = new JTextField(5);
private JButton derSicherungsButton = new JButton("Sichern");
private JButton derRestoreButton = new JButton("Restaurieren");
private JLabel dasStatusLabel = new JLabel("Keine Aktion");
public NordPanel()
{
setBackground(Color.green);
setLayout(new FlowLayout());
add(new JLabel("Partition # "));
add(dasEingabeFeld);
add(derSicherungsButton);
add(derRestoreButton);
add(new JLabel("Status: "));
add(dasStatusLabel);
derSicherungsButton.addMouseListener(new java.awt.event.MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
int g = Integer.parseInt(dasEingabeFeld.getText());
}
});
}
}
class SuedPanel extends JPanel
{
public SuedPanel()
{
setBackground(Color.blue);
setLayout(new FlowLayout());
final int max = 10;
final JProgressBar balken = new JProgressBar( 0, max );
add( balken );
for ( int i = 1; i <= 10; i++ )
{
try
{
Thread.sleep( 1500 );
}
catch ( InterruptedException e ) { }
final int j = i;
SwingUtilities.invokeLater(
new Runnable()
{
public void run()
{
balken.setValue( j );
balken.paint(balken.getGraphics());
balken.setStringPainted(true);
}
}
);
}
}
}