zoukankan      html  css  js  c++  java
  • 图形界面系列教材 (三)- Swing 的容器 JFrame和JDialog

    java的图形界面中,容器是用来存放 按钮,输入框等组件的。 

    窗体型容器有两个,一个是JFrame,一个是JDialog

    步骤1:JFrame
    步骤2:JDialog
    步骤3:模态JDialog
    步骤4:窗体大小不可变化
    步骤5:练习-模态与大小变化
    步骤6:答案-模态与大小变化

    步骤 1 : JFrame

    JFrame是最常用的窗体型容器,默认情况下,在下载区(点击进入)有最大化最小化按钮

    JFrame

    package gui;

    import javax.swing.JButton;

    import javax.swing.JFrame;

    public class TestGUI {

        public static void main(String[] args) {

             

            //普通的窗体,带最大和最小化按钮

            JFrame f = new JFrame("LoL");

            f.setSize(400300);

            f.setLocation(200200);

            f.setLayout(null);

            JButton b = new JButton("一键秒对方基地挂");

            b.setBounds(505028030);

            f.add(b);

            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            f.setVisible(true);

        }

    }

    步骤 2 : JDialog

    JDialog也是窗体型容器,下载区(点击进入)没有最大和最小化按钮

    JDialog

    package gui;

    import javax.swing.JButton;

    import javax.swing.JDialog;

    public class TestGUI {

        public static void main(String[] args) {

             

            //普通的窗体,带最大和最小化按钮,而对话框却不带

            JDialog d = new JDialog();

            d.setTitle("LOL");

            d.setSize(400300);

            d.setLocation(200200);

            d.setLayout(null);

            JButton b = new JButton("一键秒对方基地挂");

            b.setBounds(505028030);

            d.add(b);

            d.setVisible(true);

        }

    }

    步骤 3 : 模态JDialog

    当一个对话框被设置为模态的时候,其背后的父窗体,是不能被激活的,除非该对话框被关闭

    package gui;

    import javax.swing.JButton;

    import javax.swing.JDialog;

    import javax.swing.JFrame;

    public class TestGUI {

        public static void main(String[] args) {

            JFrame f = new JFrame("外部窗体");

            f.setSize(800600);

            f.setLocation(100100);

            // 根据外部窗体实例化JDialog

            JDialog d = new JDialog(f);

            // 设置为模态

            d.setModal(true);

            d.setTitle("模态的对话框");

            d.setSize(400300);

            d.setLocation(200200);

            d.setLayout(null);

            JButton b = new JButton("一键秒对方基地挂");

            b.setBounds(505028030);

            d.add(b);

            f.setVisible(true);

            d.setVisible(true);

        }

    }

    步骤 4 : 窗体大小不可变化

    通过调用方法 setResizable(false); 做到窗体大小不可变化

    package gui;

    import javax.swing.JButton;

    import javax.swing.JFrame;

    public class TestGUI {

        public static void main(String[] args) {

            JFrame f = new JFrame("LoL");

            f.setSize(400300);

            f.setLocation(200200);

            f.setLayout(null);

            JButton b = new JButton("一键秒对方基地挂");

            b.setBounds(505028030);

            f.add(b);

            // 窗体大小不可变化

            f.setResizable(false);

            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            f.setVisible(true);

        }

    }


    更多内容,点击了解: https://how2j.cn/k/gui/gui-container/404.html

  • 相关阅读:
    政府信息化建设重点——服务、多元化
    随便聊聊水面效果的2D实现(一)
    【Oracel 基础】小结
    漫话Unity(二)
    Codeforces Round #265 (Div. 2) C. No to Palindromes!
    C99中的restrict和C89的volatilekeyword
    开源 java CMS
    JavaScript--基于对象的脚本语言学习笔记(二)
    小试“以图搜图”
    计算几何 《模板》
  • 原文地址:https://www.cnblogs.com/Lanht/p/12615455.html
Copyright © 2011-2022 走看看