Java jframe output HelloWorld instance _java

Source: Internet
Author: User
Tags java jframe

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.