[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 2598 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 365 days
Recommended Popular Threads Controvertial Threads
Conservative discussions
TPS Re-registration case still pending ..
TPS for Nepal likely to extend next week
सालीको चाक
ChatSansar.com Naya Nepal Chat
TPS for Venezuela is terminated, only 60 days extension for transition period
TPS to F1 Status.
TPS To F-1 COS
Venezuela TPS lawuit
Toilet paper or water?
tesla stock OMG !!
Those who are in TPS, what’s your backup plan?
Biden out, Trump next president, so what’s gonna happen to TPS, termination?
TPS Sakiyo Tara Case is in Court.
Got my F1 reinstatement approved within 3 months(was out of F1 for almost 2 years)
Homeland Security revokes temporary status for 532,000 Cubans, Haitians, Nicaraguans and Venezuelans
Has anyone here successfully reinstated to F-1 status after a year-long gap following a drop from F-1?
I hope all the fake Nepali refugee get deported
Court Hearing Approval.
and it begins - on Day 1 Trump will begin operations to deport millions of undocumented immigrants
Looking for girl
Who is hottest nepali female?
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