1.Swing
1.窗口,面板
package com.GUI.Swing;
import javax.swing.*;
import java.awt.*;
public class JFrameDemo extends JFrame{
//init();初始化
public void init(){
//顶级面板
JFrame jFrame = new JFrame("JFrame窗口");
jFrame.setVisible(true);
jFrame.setBounds(200,200,400,300);
//关闭事件
jFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
//创建一个容器,让配置生效
Container contentPane = jFrame.getContentPane();
contentPane.setBackground(Color.BLUE);
Label label = new Label();
label.setText("JFrame窗口");
jFrame.add(label);
}
public static void main(String[] args) {
new JFrameDemo().init();
}
}
2.弹窗dialog
package com.GUI.Swing;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class JDialogDemo extends JFrame {
public JDialogDemo(){
this.setVisible(true);
this.setBounds(100,100,500,500);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
Container container = new Container();
container.setLayout(null);
JButton jButton = new JButton("点击按钮");
jButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
new JDialog();
}
});
this.add(jButton);
}
public static void main(String[] args) {
new JDialogDemo();
}
}
class JDialog extends javax.swing.JDialog {
public JDialog() {
this.setVisible(true);
this.setBounds(50,50,300,300);
//this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
Container container = new Container();
//container.setLayout(null);
Label label = new Label();
label.setText("你点击了按钮");
container.add(label);
}
}
3.标签 label,icon
package