I can not seem to figure this out for the life of me. Excuse me if there is redundant code but I kept trying and trying and couldn't figure it out. The JFrame
shows up but the button and label are not appearing.
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class ex03 {
int w = 20;
int h = 20;
public ex03() {
JFrame fra = new JFrame("");
fra.setBounds(10, 10, 200, 200);
fra.setLayout(null);
fra.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fra.setVisible(true);
JPanel pan = new JPanel();
pan.setLayout(null);
pan.setVisible(true);
fra.getContentPane().add(pan);
JLabel lab = new JLabel();
lab.setBounds(10, 10, w, h);
lab.setOpaque(true);
lab.setBackground(Color.blue);
lab.setVisible(true);
JButton but = new JButton("Play");
but.setBounds(10, 10, 100, 35);
but.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
w++;
h++;
}
});
but.setVisible(true);
pan.add(lab);
pan.add(but);
}
public static void main (String[] args) {
new ex03();
}
}