This article describes the Java JFrame output HelloWorld method. Share to everyone for your reference. Specifically as follows:
The basic idea of Java GUI program is based on JFrame, it is the object of window on screen, can maximize, minimize, close. Swing is a development toolkit for developing the Java application user interface. Based on the Abstract Window Toolkit (AWT), enables Cross-platform applications to use any pluggable styling. Swing developers can use the rich, flexible features and modular components of swing to create elegant user interfaces with little code.
Plainly, you only need a little code, you can use Java to write Windows Forms programs, of course, this code is not very small, but compared to VC6 's WIN32 those strange objects, this Java swing program is less. Also, you don't have to introduce any packages using JFrame, JDK1.6 this thing by default.
For example, one of the following jframe Helloworld:
The code for this is this:
Import javax.swing.*;
public class jfhelloworld{public
static void Main (String args[]) {
//Create a new JFrame object frame with its title bar no
title JFrame frame=new JFrame ("No Title");
Creates a new JLabel component label with the contents of Hello world!
JLabel label=new JLabel ("Hello world!");
Create a new panel of JPanel panels, which is used to put things
JPanel panel=new JPanel ();
On the Panel, label
Panel.add (label);
Set the layout of the panel to any null layout so that the following SetBounds statement takes effect, and the label is in the (125,75) position of the Panel, and the size is 100x20px
panel.setlayout (null);
Label.setbounds (125,75,100,20);
In the frame, add a panel
Frame.getcontentpane (). Add (panel);
Sets the size of the frame to be 300x200 and visible by default is invisible
frame.setsize (300,200);
Frame.setvisible (true);
To make the Close button in the upper right corner effective, if not, click the Close button in the upper-right corner to close the window only, unable to end the process
frame.setdefaultcloseoperation (jframe.exit_on_close);
}
I hope this article will help you with your Java programming.