In my JApplet, I am able to change the background color of the panel but not the currentSurface which is an instance of PaintSurface. Could someone please help me out? Many thanks
public class Tanks extends JApplet { public static final int WIDTH = 400; public static final int HEIGHT = 400; private JButton button1; private PaintSurface currentSurface = new PaintSurface();
public Tanks() { this.add(currentSurface,BorderLayout.CENTER); ButtonListener b1 = new ButtonListener(); JPanel panel = new JPanel(); panel.setBackground(Color.white); currentSurface.setBackground(Color.white); button1 = new JButton("Start"); button1.addActionListener(b1); panel.add(button1); this.add(panel,BorderLayout.NORTH);
}
public void init() { this.setSize(WIDTH, HEIGHT);
this.setVisible(true);
}
private class ButtonListener implements ActionListener {
My codes able to draw the ellipse but not the button("Start"). I added the button to the JComponent. Could someone tell me what I did wrong and help me out? Thanks in advance
The javax.swing.Timer will call my method at every interval time but I only want it delay the time to call my method once. Do you know how could I fix this?