GUI:DialogDemo.java


import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
//如果想要实现icon,不能直接getContentPane()
public class DialogDemo extends JFrame{
    public DialogDemo(){
        this.setVisible(true);
        this.setSize(700,500);

        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

        //JFrame 放东西的容器
        Container container=this.getContentPane();

        //绝对布局
        container.setLayout(null);

        //按钮
        JButton button=new JButton("点击弹出弹窗");
        button.setBounds(30,30,200,50);

        //点击弹出弹窗
        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new MyDialogDemo();
            }
        });
        container.add(button);
    }
    public static void main(String[] args) {
        new DialogDemo();
        //测试 new MyDialogDemo();
    }

}

//弹窗
class MyDialogDemo extends JDialog{
    public MyDialogDemo(){
        this.setVisible(true);
        this.setBounds(100,100,200,300);


       // this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        //获得容器
        Container container=this.getContentPane();

        container.setLayout(null);//设置绝对布局(清除默认布局)后添加布局需要明确添加的位置

        JLabel label=new JLabel("study java!");
        label.setBounds(20,20,100,50);
        container.add(label);

    }
}

 

 

你可能感兴趣的:(Gui,java,python,开发语言)