Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Button

 
josephine chen
Ranch Hand
Posts: 216
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<pre>
import java.awt.*;
import java.awt.event.*;
class btn extends Button implements ActionListener{
public static void main(String s[]){
Frame w = new Frame();
w.setVisible(true);
w.setSize(200,200);

Button b = new Button("ok");

btn bt = new btn();
b.addActionListener(bt);
w.add(b);
w.setLayout(new FlowLayout());

}
public void actionPerformed(ActionEvent e){
System.out.println("hai");
}
}
</pre>
once i run the program only when i resize or drag or maximize the window do i get the button .What should i do to get the button the moment i run?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like the problem is that you're adding the Button to the Frame after the Frame is made visible - Java doesn't bother redrawing unless you tel it to. The simplest solution is to move setVisible(true) to the end of the constructor.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic