?? second.java~3~
字號(hào):
package testsystem;
import java.awt.Color;
import java.awt.Container;
import java.awt.Image;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.Border;
import java.awt.Rectangle;
import javax.swing.JToggleButton;
public class second extends JFrame{
public second(){
//獲得窗口的容器
Container con = this.getContentPane();
//設(shè)置容器的布局管理器,當(dāng)為null表示絕對(duì)布局
con.setLayout(null);
//文本框?qū)ο? JTextField jtxt = new JTextField();
//設(shè)置當(dāng)前組件的大小和位置 ,
//其中前兩個(gè)參數(shù)代表位置,后兩個(gè)參數(shù)代表大小
jtxt.setBounds(80,20,100,20);
//將組件加入容器
con.add(jtxt);
//標(biāo)簽組件
JLabel jl = new JLabel();
//設(shè)置標(biāo)簽顯示文本
jl.setText("姓名");
jl.setBounds(10,20,60,20);
con.add(jl);
//產(chǎn)生邊框?qū)ο? Border border = BorderFactory.createLineBorder(Color.blue);
//設(shè)置標(biāo)簽組件的邊框
jl.setBorder(border);
//圖片標(biāo)簽
JLabel jlImage = new JLabel();
//圖片對(duì)象
ImageIcon imgIcon = new ImageIcon("1.jpg");
//獲得當(dāng)前圖片對(duì)象對(duì)應(yīng)的圖形對(duì)象
Image img = imgIcon.getImage();
//得到縮放之后的圖形對(duì)象,100,100表示壓縮圖像的寬和高
img = img.getScaledInstance(100, 100, 0);
//設(shè)置標(biāo)簽的圖片
jlImage.setIcon(new ImageIcon(img));
jlImage.setBounds(10,70,100,100);
con.add(jlImage);
//按鈕
JButton jb = new JButton("添加");
jb.setBounds(10,180,80,20);
con.add(jb);
//文本域
JTextArea jta = new JTextArea();
jta.setBounds(10,210,100,100);
con.add(jta);
//復(fù)選框
JCheckBox jcb = new JCheckBox("體育");
jcb.setText("體育");
jcb.setBounds(120,210,100,20);
con.add(jcb);
//單選鈕
JRadioButton jrb1 = new JRadioButton("男");
jrb1.setBounds(120,240,80,20);
con.add(jrb1);
JRadioButton jrb2 = new JRadioButton("女");
jrb2.setBounds(200,240,60,20);
con.add(jrb2);
JRadioButton jrb3 = new JRadioButton("李宇春");
jrb3.setBounds(270,240,100,20);
con.add(jrb3);
//按鈕組
ButtonGroup bg = new ButtonGroup();
bg.add(jrb1);
bg.add(jrb2);
bg.add(jrb3);
//容器組件
JPanel jp = new JPanel();
jp.setBounds(120,270,200,200);
con.add(jp);
jp.setBorder(border);
jp.setLayout(null);
JLabel jlImg = new JLabel(new ImageIcon("1.jpg"));
//滾動(dòng)面板
JScrollPane jsp = new JScrollPane(jlImg);
jsp.setBounds(330,270,200,200);
con.add(jsp);
//下拉框
JComboBox jcbox = new JComboBox();
//添加下拉框的選項(xiàng)
jcbox.addItem("高中");
jcbox.addItem("大專");
jcbox.addItem("本科");
jcbox.setBounds(10,10,100,20);
jp.add(jcbox);
this.setSize(600,600);
this.setTitle("測(cè)試");
this.setVisible(true);
//設(shè)置容器的背景色,改變窗口的顯示背景
//con.setBackground(Color.red);
//設(shè)置窗體位置
//this.setLocation(100, 100);
//設(shè)置窗體居中,必須放在setVisible之下
this.setLocationRelativeTo(null);
//設(shè)置窗口大小不可調(diào)整
this.setResizable(false);
//設(shè)置窗口關(guān)閉時(shí),程序結(jié)束
this.setDefaultCloseOperation(3);
try {
jbInit();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static void main(String[] args) {
new second();
}
private void jbInit() throws Exception {
jTextField1.setText("jTextField1");
jTextField1.setBounds(new Rectangle(216, 113, 221, 91));
this.getContentPane().add(jTextField1);
this.getContentPane().add(jToggleButton1);
jToggleButton1.setText("jToggleButton1");
jToggleButton1.setBounds(new Rectangle(287, 44, 97, 25));
}
JTextField jTextField1 = new JTextField();
JToggleButton jToggleButton1 = new JToggleButton();
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -