package com.hai.week2;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
class MyDialog extends JFrame{
public MyDialog(){
setSize(500,500);
setVisible(true);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
JButton jButton = new JButton("点击弹出一个窗口");
jButton.setBounds(50,30,200,100);
jButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
new DemoJdialog().init();
}
});
Container container = this.getContentPane();
container.add(jButton);
container.setLayout(null);
}
}
public class Demo09 {
public static void main(String[] args) {
new MyDialog();
}
}
class DemoJdialog extends JDialog{
public void init(){
setSize(200,200);
setVisible(true);
Container container =this.getContentPane();
JLabel jLabel = new JLabel("魈太帅了");
jLabel.setBounds(20,20,200,100);
jLabel.setHorizontalAlignment(SwingConstants.CENTER);
container.add(jLabel);
container.setLayout(null);
}
}