File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes AWT components display Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "AWT components display" Watch "AWT components display" New topic
Author

AWT components display

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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

Joined: Nov 22, 2008
Posts: 18944
Anyone Pl. reply me...
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040

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

Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
john shen
Greenhorn

Joined: Jul 23, 2000
Posts: 14
you need to add a validate() again in your callback function for the button so that the button will show up.
jafarali
Ranch Hand

Joined: Jul 15, 2000
Posts: 37

call validate() after b2.setVisible(true) inside 'actionPerformed' method
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Thanks! The validate() worked.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: AWT components display