Reputation: 1
I'm creating a Loading Page for our group project, but every time I call the loading page class, it is invisible.
Here is my Main class:
public static void main(String[] args) {
new caller();
}
Here is the button that when you click you will go into the loading page class.
JFrame frame = new JFrame();
JButton btn = new JButton("Press me!");
caller(){
btn.setBounds(20, 30, 120, 50);
btn.setFocusable(false);
btn.addActionListener(this);
frame.setSize(420, 420);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setLayout(null);
frame.add(btn);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==btn) {
frame.dispose();
new loading_page();
}
}
And here is the loading page class
JLabel lablab = new JLabel();
JProgressBar bar = new JProgressBar();
JFrame frame = new JFrame();
loading_page(){
lablab.setBackground(Color.WHITE);
lablab.setHorizontalAlignment(SwingConstants.CENTER);
lablab.setIcon(new ImageIcon("C:\\Users\\KHAdmin\\Documents\\Pictures\\giphy.gif"));
lablab.setBounds(65, 40, 367, 215);
bar.setForeground(Color.cyan);
bar.setBounds(10, 300, 480, 17);
bar.setValue(0);
bar.setStringPainted(true);
bar.setFont(new Font("MV Boli", Font.BOLD, 15));
bar.setForeground(Color.CYAN);
bar.setBackground(Color.BLACK);
frame.setUndecorated(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setBounds(400, 200, 500, 335);
frame.setVisible(true);
frame.setLayout(null);
frame.getContentPane().setBackground(Color.BLACK);
frame.getContentPane().add(lablab);
frame.getContentPane().add(bar);
int counter =0;
while(counter<=100) {
bar.setValue(counter);
try {
Thread.sleep(50);
if(counter==100) {
frame.dispose();
}
} catch (InterruptedException e) {
e.printStackTrace();
}
counter +=1;
}
{
new caller();
}
}
I think it's in the while(counter<==100) statement. I used the frame dispose to dispose the frame from the previous class, but when the system call the 3rd class which is the loading page class, it's invisible.
Upvotes: 0
Views: 47