Hi ...I got the Buttons to disappear and reappear on click but can someone helo me get a message " only one more click" after 10 clicks on the buttons ( total for the two) and then the program exits after one click?
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class ButtonDemo1 extends JPanel
implements ActionListener {
JButton Sunny,Cloudy;
public ButtonDemo1() {
Sunny = new JButton("sunny");
Sunny.setActionCommand("sunny");
Cloudy = new JButton("cloudy");
Cloudy.setActionCommand("cloudy");
Cloudy.setEnabled(true);
//Listen for actions on buttons 1 and 3.
Sunny.addActionListener(this);
Cloudy.addActionListener(this);
add(Sunny);
add(Cloudy);
}
public void actionPerformed(ActionEvent e) {
if ("sunny".equals(e.getActionCommand())) {
setBackground(Color.BLUE);
Sunny.setVisible(false);
Cloudy.setVisible(true);
} else {
setBackground(Color.GRAY);
Sunny.setVisible(true);
Cloudy.setVisible(false);
}
}
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("ButtonDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Create and set up the content pane.
ButtonDemo1 newContentPane = new ButtonDemo1();
//
frame.setContentPane(newContentPane);
//Display the window.
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}