package JAVASwing;
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;
public class TestingT {
public static void main(String[] args) {
MyFrame aa=new MyFrame();
}
}
class MyJDialog extends JDialog
{
public MyJDialog()
{
super(new MyFrame(),"第一个JDialog窗体",true);
Container container=getContentPane();
container.add(new JLabel("这是一个对话框"));
container.setBackground(Color.black);
setSize(100,100);
}
}
class MyFrame extends JFrame
{
public MyFrame()
{
setSize(1000,1000);
setVisible(true);
Container container=getContentPane();
container.setLayout(null);
JLabel jl=new JLabel("这是一个JFrame窗体");
jl.setHorizontalAlignment(SwingConstants.CENTER);
container.add(jl);
JButton bl=new JButton("弹出对话框");
container.add(bl);
bl.setSize(100,100);
bl.addActionListener
(
new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
new MyJDialog().setVisible(true);
}
}
);
}
}