[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 1702 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 60 days
Recommended Popular Threads Controvertial Threads
What are your first memories of when Nepal Television Began?
TPS Re-registration case still pending ..
मन भित्र को पत्रै पत्र!
TPS Work Permit/How long your took?
काेराेना सङ्क्रमणबाट बच्न Immunity बढाउन के के खाने ?How to increase immunity against COVID - 19?
Guess how many vaccines a one year old baby is given
अमेरिकामा बस्ने प्राय जस्तो नेपालीहरु सबै मध्यम बर्गीय अथवा माथि (higher than middle class)
चितवनको होस्टलमा १३ वर्षीया शालिन पोखरेल झुण्डिएको अवस्था - बलात्कार पछि हत्याको शंका - होस्टेलहरु असुरक्षित
Travelling to Nepal - TPS AP- PASSPORT
Nepali doctors future black or white usa ?
ढ्याउ गर्दा दसैँको खसी गनाउच
TPS Reregistration and EAD Approval Timeline.......
nrn citizenship
They are openly permitting undocumented immigrants to participate in federal elections in Arizona now.
Morning dharahara
Another Song Playing In My Mind
TPS Renewal Reregistration
WHAT DO YOU GUYS THINK ABOUT THIS?
हेर अमेरिकामा नेपालीहरुको बेज्जत
Alert: Turbo Cancers: A Rising Global Threat
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