My first Java graphics program

Source: Internet
Author: User

From the book to see the example, oneself did a little expansion, do a look to play.

The content is slightly adjusted, summed up a little bit of usage, wrote a few notes, for reference only.

Package Swingexample;import Java.awt.color;import Java.awt.container;import java.awt.font;import javax.swing.JFrame ; Import Javax.swing.jlabel;import Javax.swing.swingconstants;import Javax.swing.windowconstants;public class swingexample {public static void main (string[] args) {//TODO auto-generated method Stubswingexample example = new Swingex Ample (); Example.createjframe ("My first Java graphics program! ");} public void Createjframe (String strtitle) {JFrame JF = new JFrame (strtitle);//Create a JFrame object (instantiation) Container Container = JF.G Etcontentpane ();//Get a window container from jframe JLabel JL = new JLabel (strtitle);//Create a JLabel label jl.sethorizontalalignment ( Swingconstants.center);//Set JLabel Horizontal center jl.setverticalalignment (swingconstants.center);// Set JLabel Vertical Center Container.add (JL);//Add the JLabel tag you just created to the container Jl.setfont (new Font ("Times New Roman", Font.Italic, 48));// Set the body, style, size jl.setforeground (color.blue) of the label text,//Set the foreground color Container.setbackground (color.white) of the label texts;// Sets the background color of the entire container jf.setvisible (true);//Settings window visible jf.setsize (640, 480);//Resize window Jf.setdefaUltcloseoperation (windowconstants.exit_on_close);//Set the action when the Close button is clicked}} 

The above code runs through on the MAC, Environment eclipse. Such as:



My first Java graphics program

Related Article

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.