• 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

Can't close window

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This code compiles, but when run buttons don't show up until window is maximized, then I can't close window, Help!!!
import java.awt.*;
class MyButton {
MyButton() {
Frame f = new Frame("Top Teams in the NFL");
f.setLayout(new FlowLayout());
f.setVisible(true);
f.setSize(500,300);
f.setBackground(Color.darkGray);
Button a = new Button("Raiders");
Button b = new Button("Ravens");
Button c = new Button("Rams");
Button d = new Button("Steelers");
Button e = new Button("Niners");
Button g = new Button("Bears");
f.add(a);
f.add(b);
f.add(c);
f.add(d);
f.add(e);
f.add(g);
}

public static void main(String args[])
{ MyButton mf = new MyButton(); }
}
 
Ranch Hand
Posts: 1246
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"This code compiles, but when run buttons don't show up until window is maximized, then I can't close window, Help!!!"
You can't close the window becuase you didn't add the windowlistener. Try adding one.
doesn't show the buttons, try adding the buttons to the frame first then show the Frame.
hope this help.
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Fei is correct, f.setVisible(true) should be the last statement after adding all your GUI components. You also have to add a window listener that will either minimize/close the window or exit the application. There is probably an example somewhere in your textbook.

------------------
Bosun
SCJP for the Java� 2 Platform
 
Mike Kelly
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Fei and Bosun, I very much appreciate your help. I understand now.
reply
    Bookmark Topic Watch Topic
  • New Topic