wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Button" Watch "Button" New topic
Author

Button

josephine chen
Ranch Hand

Joined: Oct 29, 2002
Posts: 216
<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

Joined: Jan 30, 2000
Posts: 18671
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'm not back." - Bill Harding, Twister
 
 
subject: Button
 
Similar Threads
Default Font
labels
Label
About pop up a window
Layouts