0

I'm very new to the Java playing field. I was doing this tutorial exercise, and I'm unable to figure out how to run the class.

import java.awt.*;
import java.awt.event.*;

class Party {
    public void buildInvite(){

    }
    public static void main(String[] args){
        Frame f = new Frame();
        Label l = new Label("Party at Tim's");
        Button b = new Button("You bet");
        Button c = new Button("Shoot me");
        Panel p = new Panel();
        p.add(l);
    }
}

It compiles without any errors. I just run java Party but nothing happens. I'm assuming it is supposed to pop up with a window that has text that says "Party at Tim's" and two buttons with "You bet" and "Shoot me." Unless I misinterpreted what I wrote. Will someone inform me with what I'm missing. Any help will be appreciated (Please make it nooby so I can understand), Thank you.

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
  • Why use AWT? See [this answer](http://stackoverflow.com/questions/6255106/java-gui-listeners-without-awt/6255978#6255978) for many good reasons to abandon AWT using components in favor of Swing. – Andrew Thompson Sep 11 '15 at 13:00

1 Answers1

3

You never add any components to the top level window, the Frame, and you never display the Frame by calling setVisible(true) or show() on it, and so while your code will run, nothing will show up.

On a side note, I strongly recommend that you avoid this current tutorial since it's teaching you use of AWT GUI coding, a library that's already 3-4 generations out of date, and has been out of date for the past 10+ years.

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373