Swing (Java): Difference between revisions

Content deleted Content added
m The program: Fixing the code list
Updated Sourcecode, less obscure, more modern.
Line 13:
<pre>
import javax.swing.*;
public class HelloWorldSwing {extends JFrame
{
/**
* Constructs a new Window
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
public HelloWorldSwing()
private static void createAndShowGUI() {
{
//Make sure we have nice window decorations.
//Sets the size and makes the window close when you press the X
JFrame.setDefaultLookAndFeelDecorated(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(500,500);
 
//CreateAdds andHelloWorld setText upto the window.
JFrameJLabel framelabel = new JFrameJLabel("HelloWorldSwingHello World!");
frame.getContentPane().add(label);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
});
 
//AddMakes the ubiquitouswindow "Hello World" label.Visible
JLabel label = new JLabelsetVisible("Hello World"true);
frame.getContentPane().add(label);
 
//Display the window.
frame.pack();
frame.setVisible(true);
}
/**
 
* Main Method
public static void main(String[] args) {
*/
//Schedule a job for the event-dispatching thread:
public static void main(String[] args) {
//creating and showing this application's GUI.
{
javax.swing.SwingUtilities.invokeLater(new Runnable() {
new public void runHelloWorldSwing() {;
createAndShowGUI();
}
});
}
}