import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.WindowConstants;
class MyDialog extends JDialog{
public MyDialog(MyFrame frame){
super(frame,"第一个Jdialog窗口",true);
Container container=getContentPane();
container.add(new JLabel("这是与各对话框"));
setBounds(120,120,100,100);
}
}
public class MyFrame extends JFrame {
public static void main(String[] args) {
new MyFrame();
}
public MyFrame(){
Container container=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(){
public void actionPerformed(ActionEvent e){
new MyDialog(MyFrame.this).setVisible(true);
}
});
container.add(bl);
bl.setVisible(true);
jl.setVisible(true);
container.setBackground(Color.blue);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
}
}
RM林夕
慕妹3559746
相关分类