[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 3747 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
शीर्षक जे पनि हुन सक्छ।
डीभी परेन भने खुसि हुनु होस् ! अमेरिकामाधेरै का श्रीमती अर्कैसँग पोइला गएका छन् !
What are your first memories of when Nepal Television Began?
Sajha Poll: नेपालका सबैभन्दा आकर्षक महिला को हुन्?
ChatSansar.com Naya Nepal Chat
NRN card pros and cons?
TPS Re-registration case still pending ..
Basnet or Basnyat ??
TPS Re-registration
निगुरो थाहा छ ??
Nas and The Bokas: Coming to a Night Club near you
Toilet paper or water?
Anybody gotten the TPS EAD extension alert notice (i797) thing? online or via post?
अमेरिकामा छोरा हराएको सूचना
ढ्याउ गर्दा दसैँको खसी गनाउच
Sajha Poll: Who is your favorite Nepali actress?
Problems of Nepalese students in US
nrn citizenship
TPS EAD auto extended to June 2025 or just TPS?
अमेरिकामा बस्ने प्राय जस्तो नेपालीहरु सबै मध्यम बर्गीय अथवा माथि (higher than middle class)
Nas and The Bokas: Coming to a Night Club near you
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