Swing组件的分类
(1)顶层容器:JFrame , JApplet , JDialog , JWindow
(2)中间容器:JPanel , JScrollPane , JSplitPane , JToolBar
(3)特殊容器:JInternal, JFrame , JLayeredPane , JRootPane…
(4)基本控件:JButton , JComboBox , JMenu , JSlider , JTextField…
(5)不可编辑信息的显示:JLabel , JProgressBar , JTextField
(6)可编辑信息的显示:JColorChooser , JFileChoose , JFileChooser , JTable , JTextArea…
常用方法
- JFrame(): 创建无标题窗口
- JFrame(String a):创建标题命名为a的窗口
设置关闭窗口按钮的方法
setDefaultCloseOperation
- JFrame.DO_NOTHING_ON_CLOSE
- JFrame.HIDE_ON_CLOSE
- JFrame.DISPOSE_ON_CLOSE
- JFrame.EXIT_ON_CLOSE
import javax.swing.*;
public class JFrame_exam1 {
public static void main(String[] args) {
JFrame f=new JFrame();
f.setTitle("JFrame窗口");//设置或修改框架内的标题;此处为设置
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置“close”窗体时的默认操作
f.setSize(300,300);//设置窗体大小【组件类component】
f.setVisible(true);//设置组件是否显示------true:可视 ; false:不可视【组件类component】
f.setLocation