package com.js;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
class MyJDialog extends JDialog{
public MyJDialog(MyFrame frame){
super(frame,"第一个Dialog窗体",true);
Container container = getContentPane();
container.add(new JLabel("这是一个对话框"));
setBounds(120,120,100,100);
}
}
public class MyFrame extends JFrame{
/**
* 系统主函数
* @param args
*/
public static void main(String[] args) {
new MyFrame();
}
public MyFrame(){
JFrame jf = new JFrame("测试对话框的窗体");
Container container = jf.getContentPane();
container.setLayout(null);
JLabel jl = new JLabel("这是一个JFrame 窗体");
jl.setHorizontalAlignment(SwingConstants.CENTER);
container.add(jl);
JButton bl = new JButton("弹出对话框");
bl.setBounds(10,10,100,21);
bl.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
new MyJDialog(MyFrame.this).setVisible(true);
}
});
container.add(bl);
jf.setVisible(true);
jf.setSize(300, 300);
jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
}
