• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

AWT components display

 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • 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
  • 0
  • send pies
  • Quote
  • Report post to moderator
Anyone Pl. reply me...
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
john shen
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
jafarali
Ranch Hand
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

call validate() after b2.setVisible(true) inside 'actionPerformed' method
 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
Thanks! The validate() worked.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic