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 3281 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 365 days
Recommended Popular Threads Controvertial Threads
Lets play Antakshari...........
शीर्षक जे पनि हुन सक्छ।
NRN card pros and cons?
What are your first memories of when Nepal Television Began?
TPS Re-registration case still pending ..
TPS Re-registration
Democrats are so sure Trump will win
is Rato Bangala school cheating?
Basnet or Basnyat ??
TPS EAD auto extended to June 2025 or just TPS?
nrn citizenship
इन्दिरा जोशीको चिन्ता लौच
Sajha has turned into MAGATs nest
Nas and The Bokas: Coming to a Night Club near you
श्राद्द
डलराँ कमाएर ने .रु मा उडांउदा !@#
whats wrong living with your parents ?
ChatSansar.com Naya Nepal Chat
डीभी परेन भने खुसि हुनु होस् ! अमेरिकामाधेरै का श्रीमती अर्कैसँग पोइला गएका छन् !
3 most corrupt politicians in the world
Nas and The Bokas: Coming to a Night Club near you
Mr. Dipak Gyawali-ji Talk is Cheap. US sends $ 200 million to Nepal every year.
Harvard Nepali Students Association Blame Israel for hamas terrorist attacks
TPS Update : Jajarkot earthquake
is Rato Bangala school cheating?
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