Win a copy of Functional Design and Architecture this week in the Functional programming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

AWT components display

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HAve a look at the code:
import java.awt.*;
class jdk extends Frame implements ActionListener
{ Button b2;
public CJjdk12()
{
Button b1 = new Button("one");
b2 = new Button("two");
Button b3 = new Button("three");
b3.addActionListener(this);
setLayout(new FlowLayout());
add(b1);
add(b2);
add(b3);
b2.setVisible(false);
setSize(800,600);
setVisible(true);
validate();
}
public void actionPerformed(ActionEvent ae)
{ b2.setVisible(true);}

public static void main(String a[])
{ jdk p1 = new jdk();
}
}
When b3 is clicked, the button b2 is not displayed.Why???
Thanks!
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anyone Pl. reply me...
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

avn:
i was thinking of doing a little more research and replying..
but since you want an ans fast, I will suggest that you may
have to update the graphics......check out if repaint()
and/or paint() has to be called.....
sorry if i am being very vague...but i really don't have much
time right now....
regds.
- satya
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you need to add a validate() again in your callback function for the button so that the button will show up.
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

call validate() after b2.setVisible(true) inside 'actionPerformed' method
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks! The validate() worked.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic