First SWING program

xiaoxiao2021-03-06  117

Thank you for your encouragement! I am ready to temporarily don't use NetBeans, because writing a small program to create a project, quite a waste of resources, huh.

There are very few Swing information on the Internet, I have to go to the English website to find. From today, I will slowly post the information you found (after translation).

Public Class HelloWorldswing

{

Private static void createandshowgui ()

{

Jframe.SetDefault (TRUE);

JFrame frame = new

JFrame ("HelloWorldString");

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 [])

{

Javax.swing.swingutilities.Invokelater (New Runnable ()

{

Public void Run ()

{

CreateandShowgui ();

}

});

}

}

This is the simplest Swing program, which explains below.

JFrame.setDefault (True); This sentence is the form of the form, only 1.4 version or update version is supported.

Javax.swing.swingutilities.invokelater (New Runnable () ..... This sentence looks very troubles, but it is recommended to do this because it is the reason for thread safety, don't use the setvisible () method directly.

The above is translated English, but why is the last point written, the younger brother don't know, huh, huh. Which is bigger?

转载请注明原文地址:https://www.9cbs.com/read-101756.html

New Post(0)