[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 queston.
[VIEWED 2599 TIMES]
SAVE! for ease of future access.
Posted on 12-08-06 9:08 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Hi can someone help me disappear the button on click..... i have the windowDestroyer and the driver class

mport javax.swing.*;
import java.awt.*;
import java.awt.event.*;

/**
Simple demonstration of putting buttons in a JFrame.
*/
public class ButtonDemo extends JFrame implements ActionListener
{
public static final int WIDTH = 400;
public static final int HEIGHT = 300;

public ButtonDemo( )
{
setSize(WIDTH, HEIGHT);
WindowDestroyer listener = new WindowDestroyer( );
addWindowListener(listener);

Container contentPane = getContentPane( );
contentPane.setBackground(Color.WHITE);

contentPane.setLayout(new FlowLayout( ));

JButton sunnyButton = new JButton("Sunny");
sunnyButton.addActionListener(this);
contentPane.add(sunnyButton);
sunnyButton.setVisible(false);

JButton cloudyButton = new JButton("Cloudy");
cloudyButton.addActionListener(this);
contentPane.add(cloudyButton);
}

public void actionPerformed(ActionEvent e)
{

String actionCommand = e.getActionCommand( );
Container contentPane = getContentPane( );
JButton sunnyButton = new JButton("Sunny");

JButton cloudyButton = new JButton("Cloudy");


if (actionCommand.equals("Sunny"))
contentPane.setBackground(Color.BLUE);

sunnyButton.setVisible(false);/*SHOULDN'T THIS METHOD MAKE BUTTON DISAPPEAR BUT IT DOESN'T WORK!!!! HELP PLZ*/
else if (actionCommand.equals("Cloudy"))
contentPane.setBackground(Color.GRAY);

else
System.out.println("Error in button interface.");
}
 
Posted on 12-08-06 10:44 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

hope this helps

http://www.cse.sc.edu/~vargasje/CSCE145_Fall2003/Docs/Chapter12.pdf
 
Posted on 12-08-06 11:19 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

This might give a better answer to you.

http://forum.java.sun.com/thread.jspa?threadID=779711&messageID=4436227

I have faced similar problems too when I tried to add buttions outside of init(). So I choose to do the Enable and Disable. You dont have to change the layout too. But what when to want to show a picture upon clicking the button? The picture will come on the way.

It seems setVisible doesnt work anywhere outside.
 
Posted on 12-09-06 4:48 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

class{
Define all the swing variables as globals
main()
decideWhereToPlaceAllComponents();
updatewindow();//set visible
class ButtonListener{
onclick(){
container.remove(button);
updatewindow();
}
}

I think it will work even without updating but if it doesnt just update it.
 


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 to F1 Status.
TPS To F-1 COS
TPS Sakiyo Tara Case is in Court.
Got my F1 reinstatement approved within 3 months(was out of F1 for almost 2 years)
Has anyone here successfully reinstated to F-1 status after a year-long gap following a drop from F-1?
Need Help of IT consultancies
Nepal TPS decision
Supreme Court allows Trump to end TPS for Venezuelans
Any input on remote jobs(IT related or Sales or Marketing)?
Nepal Likely to Get 60-Day TPS Notice
Nepal TPS has been Extended !!!
#MAGA#FAFO is delicious
नेपाल मा B. sc गरियो यहाँ फेरी ७० -८० क्रेडिट पढ्नु पर्ने भो
NEPAL TPS IS GONE
Genuine Question.... Why so many folks still in TPS after 10 years. Is the statistics wrong?
🛡️ Nepal TPS Holders: Don’t Panic About August 5 — DHS Screwed Up (Maybe on Purpose)
The New Color of Her Flag
Don’t Just Read—Join the Conversation
Travelling to Nepal with expiration less than 6 months
US citizen Petitioning my wife who was out of status when she was in H1B. What to do ?
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