Hi, I am new to Java. Better yet I'm new to programming PERIOD.
I have to write my Hello World program for my class and have it exit with an "Exit" button.
I cannot get it to work properly.
Can someone please help!!!!
This is what I have. It runs smoothly just cannot figure out how to add the button.
import javax.swing.*;
public class HelloWorldGUI
{
private static void createAndShowGUI() {
JFrame frame = new JFrame("");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel label = new JLabel("Hello World!!!");
frame.getContentPane().add(label);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
createAndShowGUI();
}
}
I have to write my Hello World program for my class and have it exit with an "Exit" button.
I cannot get it to work properly.
Can someone please help!!!!
This is what I have. It runs smoothly just cannot figure out how to add the button.
import javax.swing.*;
public class HelloWorldGUI
{
private static void createAndShowGUI() {
JFrame frame = new JFrame("");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel label = new JLabel("Hello World!!!");
frame.getContentPane().add(label);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
createAndShowGUI();
}
}