[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 2875 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 200 days
Recommended Popular Threads Controvertial Threads
ANA and AJAY KUMAR DEV. RAPISTS CONVENTION
NRN card pros and cons?
TPS To F-1 COS
Got my F1 reinstatement approved within 3 months(was out of F1 for almost 2 years)
2020 : Why No Trump !
Trump’s “Big Beautiful Bill” is straight-up xenophobic class warfare. Let’s call it what it is.
TPS to F1 Status.
Business Ideas in Nepal?
Leave messages on US congressman's facebook to support TPS
A legit Non-Profit organization "United For TPS Nepal "
legal Query for married nepali girl now have taken US citizenship
Democrat lies revealed
#MAGA#FAFO is delicious
TPS Sakiyo Tara Case is in Court.
Nepal Likely to Get 60-Day TPS Notice
मुद्दा हाल्छन होला र ?
NEPAL TPS IS GONE
TPS cancel bho bhane k garne?
Nepal TPS Extension Possible as Court Reviews Late Notice Issue
🛡️ Nepal TPS Holders: Don’t Panic About August 5 — DHS Screwed Up (Maybe on Purpose)
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