[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 3751 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 30 days
Recommended Popular Threads Controvertial Threads
TPS Re-registration case still pending ..
and it begins - on Day 1 Trump will begin operations to deport millions of undocumented immigrants
I hope all the fake Nepali refugee get deported
ढ्याउ गर्दा दसैँको खसी गनाउच
To Sajha admin
Travel Document for TPS (approved)
All the Qatar ailines from Nepal canceled to USA
MAGA मार्का कुरा पढेर दिमाग नखपाउनुस !
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