[Show all top banners]

pat
Replies to this thread:

More by pat
What people are reading
Subscribers
:: Subscribe
Back to: Kurakani General Refresh page to view new replies
 java help!!
[VIEWED 3906 TIMES]
SAVE! for ease of future access.
Posted on 12-14-06 9:34 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

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();
}
});
}
}
 
Posted on 12-14-06 10:18 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

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
 
Posted on 12-15-06 8:45 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

What was the problem with disapper?
Just wanted to know
 


Please Log in! to be able to reply! If you don't have a login, please register here.

YOU CAN ALSO



IN ORDER TO POST!




Within last 90 days
Recommended Popular Threads Controvertial Threads
TPS Re-registration case still pending ..
Looking for girl
tesla stock OMG !!
ढ्याउ गर्दा दसैँको खसी गनाउच
I hope all the fake Nepali refugee get deported
Those who are in TPS, what’s your backup plan?
Tourist Visa - Seeking Suggestions and Guidance
interesting fact about sajha.
MAGA #FAFO
To Sajha admin
From Trump “I will revoke TPS, and deport them back to their country.”
If you got nothing to lose, fight tooth and nail explore every avenue
wanna be ruled by stupid or an Idiot ?
and it begins - on Day 1 Trump will begin operations to deport millions of undocumented immigrants
Travel Document for TPS (approved)
How to Retrieve a Copy of Domestic Violence Complaint???
Now, more than ever, is it a good idea to apply for advance parole?
TPS Travel Permit Processing time
MAGA मार्का कुरा पढेर दिमाग नखपाउनुस !
POE for TPS travel
Looking for girl
NOTE: The opinions here represent the opinions of the individual posters, and not of Sajha.com. It is not possible for sajha.com to monitor all the postings, since sajha.com merely seeks to provide a cyber location for discussing ideas and concerns related to Nepal and the Nepalis. Please send an email to admin@sajha.com using a valid email address if you want any posting to be considered for deletion. Your request will be handled on a one to one basis. Sajha.com is a service please don't abuse it. - Thanks.

Sajha.com Privacy Policy

Like us in Facebook!

↑ Back to Top
free counters