Reputation: 11
So far:
TFDemo
public.import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SwingDemo {
SwingDemo() {
// Create a new JFrame container
JFrame jfrm = new JFrame("A Simple Swing Application");
// Gives the frame an initial size
jfrm.setSize(275, 100);
// Terminate the program when the user closes the application
jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Create a text-based label
JLabel jlab = new JLabel(" GUI programming with Swing.");
// Add the label to the content pane
jfrm.add(jlab);
// Display the frame
jfrm.setVisible(true);
}
public static void main(String[] args) {
// Create the frame on the event dispatching thread
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
}
});
}
}
Upvotes: 0
Views: 96
Reputation: 201409
You didn't create the frame at the commented block!
public static void main(String[] args) {
// Create the frame on the event dispatching thread
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new SwingDemo();
}
});
}
Also, here it would seem a good idea to let your program exit when you close the primary frame... so add something like,
// Add the label to the content pane
jfrm.add(jlab);
// Exit on close
jfrm.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
// Display the frame
jfrm.setVisible(true);
And running on a mac
Upvotes: 1