• 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

basic question from GUI beginner

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,

Till now I never Tried GUI on my machine,except reading thhrough different tutorials in the net.

TOday I tried to create a frame and just onebutton in it.

When i compile it is warning me to recompile with -Xlint and I did the same.
Here is the code for my simple program

import java.awt.*;
public class createButton
{

public static void main(String ar[])
{
Frame f = new Frame("First Frame");

Button b = new Button();
b.setLabel("Button 1");
f.add(b);
f.show();
System.exit(0);

}

}


It is compiling succesfully,but when I run the newly created frame is not visible anywhere.

though it is giving 2 warnings I run the program.
Is this the reason for my newly created frame invisibility?

One more thing that is confusing me is, in variuos tutorials in some code, the class is extending APPLET and some are using JFRAME from javax.swing class.

I am a beginner for GUI programming as I never tried before.

I just want to create some compenents in a container.


I want to create containers in my main()only and want to add components to it.

Is that not possible without extending Appplet claass or Swing classes?

If you find this silly,please spare me as a beginner in GUI.

Thanks in advance.
 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well - for a start, your call to System.exit(0) is exiting the application, and so, not surprisingly, closing the frame also.

I'm surprised you've managed to go 57 posts and a year without finding the [code] tags...
 
Marshal
Posts: 79409
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
. . . and show() has been deprecated for ages. That is probably why it is suggesting you use Xlint.
Another reason for not seeing much is that you have not given the frame a size.
 
Campbell Ritchie
Marshal
Posts: 79409
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There ought to be instructions for setting up a GUI in any Java book except the very smallest, and here in the Java� tutorial.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic