zoukankan      html  css  js  c++  java
  • java jFrame

    简介

    java核心编程示例代码

    code

    
    /*
     * @Author: your name
     * @Date: 2020-10-28 17:06:45
     * @LastEditTime: 2020-10-28 19:09:28
     * @LastEditors: Please set LastEditors
     * @Description: In User Settings Edit
     * @FilePath: /java/SimpleFrameTest.java
     */
    import java.awt.*;
    import javax.swing.*;
    
    public class SimpleFrameTest {
        public static void main(String[] args) {
            EventQueue.invokeLater(() -> {
                SimpleFrame frame = new SimpleFrame();
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setVisible(true);
            }); 
        }
    }
    
    class SimpleFrame extends JFrame {
        private static final int DEFAULT_WIDTH = 300;
        private static final int DEFAULT_HEIGHT = 200;
    
        public SimpleFrame() {
            setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
        }
    }
    
    

    code

    获得屏幕大小设定程序为1/2大小显示

    
    /*
     * @Author: your name
     * @Date: 2020-10-28 19:42:14
     * @LastEditTime: 2020-10-28 19:46:43
     * @LastEditors: Please set LastEditors
     * @Description: In User Settings Edit
     * @FilePath: /java/SizedFrameTest.java
     */
    import java.awt.*;
    import javax.swing.*;
    
    public class SizedFrameTest {
        public static void main(String[] args) {
            EventQueue.invokeLater(() -> {
                JFrame frame = new SizedFrame();
                frame.setTitle("SizedFrame");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setVisible(true);
            });
        }
    }
    
    class SizedFrame extends JFrame {
        public SizedFrame() {
            Toolkit kit = Toolkit.getDefaultToolkit();
            Dimension screenSize = kit.getScreenSize();
            int screenHeight = screenSize.height;
            int screenWidth = screenSize.width;
    
            setSize(screenWidth / 2, screenHeight / 2);
            setLocationByPlatform(true);
    
            Image img = new ImageIcon("icon.gif").getImage();
            setIconImage(img);
        }
    }
    
    
    Hope is a good thing,maybe the best of things,and no good thing ever dies.----------- Andy Dufresne
  • 相关阅读:
    线程私有关键字配合static使用
    对定义局部变量位置的思考
    获取文件的md5值
    JNI接口的整理
    数兔子问题
    使用XML布局文件和java代码混合控制UI界面
    应用程序类型
    android组成
    封装
    接口
  • 原文地址:https://www.cnblogs.com/eat-too-much/p/13892971.html
Copyright © 2011-2022 走看看