Java JFrame Graphical interface----a simple window

Source: Internet
Author: User
Tags java jframe

#开始

It's been a while since I've been applying for a blog, but I haven't had time to write blog posts (or couch potato).

Recently learning JFrame do Windows encountered a lot of problems in order to solve the problem also murdered a lot of brain cells in order to make more friends do not die a lot of brain cells I put in the study of the problems encountered in the writing came to be my own memo

Meng new big guy do not spray the learning process referred to a lot of online blog here thank you for sharing knowledge also hope my code and experience can help more people:)

#代码

Using Java to do the window I found a significant feature is the way to implement the window function is not unique or a lot of first to do a jframe Hello,world bar

1  Packagewindow;2 3 ImportJava.awt.Container;4 5 ImportJavax.swing.JFrame;6 ImportJavax.swing.JLabel;7 8  Public classJframewindowextendsjframe{//need to inherit JFrame9 Ten      PublicJframewindow (String title) One     { AJFrame JF =NewJFrame (title);  -Container conn = Jf.getcontentpane ();//Get the window container -JLabel L1 =NewJLabel ("hello,world!");//Create a label and set the initial content the          - Conn.add (L1); -          -Jf.setbounds (200,200,300,200);//To set the window's Properties window position and window size +Jf.setvisible (true);//The Settings window is visible -Jf.setdefaultcloseoperation (Dispose_on_close);//set shutdown if not set, it appears that the program does not exit after closing the window +     } A      at      Public Static voidMain (string[] args) { -         NewJframewindow ("window");//Create Window -     } -  -}

This allows you to get a window:

  

#技巧

If you're using ecplise, if you don't know what you're using for that package, you can press Ctrl+shift+o to import the package you want (so if there's a red line, try this shortcut)

Another shortcut is CTRL +/all rows that can be annotated with the mouse selected

#遇到的问题:

1. The name of the main class has been wrong all the time to find the error and then found that the main class name is JFrame obvious conflict has not been found (probably only I will make such a mistake:-))

2. The 20th line of code is not written this leads to the problem that the program does not appear to completely exit after clicking the Close window

    

This is the red stop button that's always lit.

#环境

Ecplise EE JDK1.8 (all x64)

    

Java JFrame Graphical interface----a simple window

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.