After I moved the JFrame things from a driver to Drum.java, it stopped working.
code:
public class Drum extends JFrame {
private JButton hihat,snare,tom1,tom2,base,floortom, ridecymbal,crashcymbal;
private JLabel label1,label2,label3,label4,label5,label6,label7,label8,label9,part1,part2,part3,part4,part5,part6,part7,part8;
private ImageIcon I1,I2,I3,I4,I5,I6,I7,I8;
private JPanel p1,p2;
public Drum(){
JFrame frame= new JFrame("Drumset");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Drum panel2 = new Drum();
frame.getContentPane().add(panel2);
frame.setVisible(true);
frame.pack();
frame.setVisible(true);
p1= new JPanel();
hihat= new JButton();
hihat.setIcon(new ImageIcon("Snare.PNG"));
p1.add(hihat);
add(p1);</pre>
}
}
What I have tried:
I have tried moving the Jframe things to the bottom and doing this:
public static void main(String[]
args){
<pre> JFrame frame= new JFrame("Drumset");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Drum panel2 = new Drum();
frame.getContentPane().add(panel2);
frame.setVisible(true);
frame.pack();
frame.setVisible(true);
}
}
}