← Back to Kurakani

java help!!

Original Post

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(); } }); } }

pat
Dec 14, 2006 9:34 PM · 8,101 views
2 Replies
bratboy Dec 14, 2006 10:18 PM
You need to maintain a global counter. Initialize the counter on the Main procedure to 0. During each click of the counter increment it by 1. If the counter exceeds or is equal to your MAX_VALUE constant then give a warning message/exit or whatever. cheers brat
HowardRoark Dec 15, 2006 8:45 PM
What was the problem with disapper? Just wanted to know
Login to join the conversation.

You might be interested in...

Recent Classifieds View all
Upcoming Events View all
Service Providers View all
Ask Sajha AI Assistant