• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Button

 
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
An elephant? An actual elephant. Into the apartment. How is the floor still here. Hold this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic