[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 2591 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 30 days
Recommended Popular Threads Controvertial Threads
TPS To F-1 COS
TPS Sakiyo Tara Case is in Court.
Nepal Likely to Get 60-Day TPS Notice
NEPAL TPS IS GONE
#MAGA#FAFO is delicious
ЁЯЫбя╕П Nepal TPS Holders: DonтАЩt Panic About August 5 тАФ DHS Screwed Up (Maybe on Purpose)
TPS cancel bho bhane k garne?
рдореБрджреНрджрд╛ рд╣рд╛рд▓реНрдЫрди рд╣реЛрд▓рд╛ рд░ ?
Nepal TPS Extension Possible as Court Reviews Late Notice Issue
Bill to Protect TPS and DED Recipients
рдХреЛрд░реНрдЯрдорд╛ рдЬрд╛рдБрджрд╛ рдЖрдЗрд╕рд▓реЗ рд╕рдорд╛рддреНрд▓рд╛ рднрдиреНрдиреЗ рдбрд░ рдЫ рднрдиреЗ рдпрд╕реНрддреЛ рдЧрд░реНрдиреБрд╣реЛрд▓рд╛
A legit Non-Profit organization "United For TPS Nepal "
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