Importjava.awt.*;//can be changed into import javax.swing.*; Public classFirstframe { Public Static voidMain (string[] args) {Frame F=NewFrame ();//can be changed to JFrame f = new JFrame ();F.setsize (300, 200 ); F.setvisible (true); }} //frame means that the framework
Importjava.awt.*; Public classFirstextendsFrame { PublicFirst () {//Super ("new text"); //Set Title//this.setbounds (200, 1111, 1024,500); //Set Size//this.setdefaultcloseoperation (jframe.exit_on_close);//setting offSetSize (100, 100); This. setvisible (true);//Set Visible } Public Static voidMain (string[] args) {NewFirst (); } }
The results of the operation are as follows: minimized maximized but not closed
One of the problems: Add a title
Importjava.awt.*;//can be changed into import javax.swing.*; Public classFirstframe { Public Static voidMain (string[] args) {Frame F=NewFrame ();//can be changed to JFrame f = new JFrame ();F.setsize (300, 200 ); F.setvisible (true); F.settitle ("New title");//You can also change the window caption like thisF.setvisible (true); }}
Link: You can add a logo next to the title
Icon Link: http://wangyali90516.blog.163.com/blog/static/117205101201231632140788/
Solving the problem: How to close a window
ImportJavax.swing.JFrame;Import Staticjavax.swing.jframe.*;//Static constants that introduce jframed Public classFirst { Public Static voidMain (string[] args) {JFrame Window1=NewJFrame ("Window A");//Create a window with a captionJFrame Window2=NewJFrame ("Window B"); Window1.setbounds (600, 100, 180, 100);//left, upper, wide, highWindow2.setbounds (260, 100, 180, 100); Window1.setvisible (true); Window2.setvisible (true); Window1.setdefaultcloseoperation (Dispose_on_close); Window2.setdefaultcloseoperation (Exit_on_close); }}
The results of the operation are as follows:
Click Windows B two to close
If you click a first, it only closes its own window.
Small knowledge:
Assumption: The screen resolution is 1024x768
The coordinates of the top left corner of the screen are (0,0) the coordinates of the bottom right corner are (1024,768)
The coordinates of the northeast direction are (1024,0)
JAVA (1) – First GUI program Add Caption Close window screen position import icon