JAVA学习38-Swing弹窗

tech2024-03-21  69

弹窗 JDialog

//主窗口 public class JDialogdemo01 extends JFrame { public JDialogdemo01() { setVisible(true); setSize(800,600); this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);//关闭窗口 //JFrame 放东西 容器 Container container=this.getContentPane(); //绝对布局 container.setLayout(null); //创建按钮 JButton jButton = new JButton("这是一个弹出窗口"); jButton.setBounds(100,100,300,300);//绝对位置按钮 container.add(jButton); jButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //弹窗 new MyJDilog(); } }); } public static void main(String[] args) { new JDialogdemo01(); } } //弹窗 class MyJDilog extends JDialog{ public MyJDilog() { setVisible(true); setBounds(100,100,400,400); //弹窗默认有 //this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); Container container = getContentPane(); container.setLayout(null); container.add(new Label("学习java很好")); } }
最新回复(0)