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