码迷,mamicode.com
首页 > Windows程序 > 详细

JDialog窗体

时间:2016-05-22 16:41:30      阅读:517      评论:0      收藏:0      [点我收藏+]

标签:

class MyJDialog extends JDialog{
    public MyJDialog(JFrame frame){
    super(frame,"第一个Dialog窗体",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()
    {
        JFrame jf=new JFrame("JFrame窗体");
        Container container=jf.getContentPane();
        container.setLayout(null);
        JLabel ji=new JLabel("这是一个JFrame窗体");
        //将标签的文字至于标签中间
        ji.setHorizontalAlignment(SwingConstants.CENTER);
        container.add(ji);
        JButton bl=new JButton("弹出对话框");
        bl.setBackground(Color.blue);
        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(200,150);
        jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        
        
    }

}

JDialog窗体

标签:

原文地址:http://www.cnblogs.com/douyunqian3520/p/5516818.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!