This article describes the Java JFrame outputs Helloworld method. Share it for your reference. The details are as follows:
The basic idea of JAVA's GUI program is based on JFrame, which is an object of the window on the screen, which can be maximized, minimized and closed. Swing is a development toolkit for developing the user interface of Java applications. Based on the Abstract Window Toolkit (AWT) enables cross-platform applications to use any pluggable appearance style. Swing developers can use Swing’s rich, flexible features and modular components to create an elegant user interface with very little code.
To put it bluntly, you only need a little code to use JAVA to write a WINDOWS form program. Of course, this code is not small, but compared with the strange objects of WIN32 in VC6, this JAVA SWING program is considered small of. Moreover, if you use JFrame, you don’t need to introduce any packages, JDK1.6 has this thing by default.
For example, the following JFrame Helloworld:
Its code looks like this:
import javax.swing.*; public class JFhelloworld{ public static void main(String args[]){ // Create a new JFrame object frame, and its title bar is No Title JFrame frame=new JFrame("No Title"); / /Create a new JLabel component label, the content in it is Hello world! JLabel label=new JLabel("Hello world!"); //Create a new JPanel panel panel, which is used to place things on it JPanel panel=new JPanel(); // Place label panel.add(label); //Set the layout of the panel to any null layout, so that the setBounds statement below can take effect, and the label is in the (125, 75) position of this panel and the size is 100x20px panel .setLayout(null); label.setBounds(125,75,100,20); //Add panel frame.getContentPane().add(panel); //Set the size of the frame to 300x200, and the visible default is invisible frame.setSize(300,200); frame.setVisible(true); // Make the close button in the upper right corner effective. If this sentence is not available, clicking the close button in the upper right corner can only close the window and cannot end the process frame.setDefaultCloseOperation(JFrame. EXIT_ON_CLOSE); } }
I hope this article will be helpful to everyone's Java programming.