zoukankan      html  css  js  c++  java
  • java swing FlowLayout 简易计算器布局,无功能实现

    import java.awt.*;
    import javax.swing.*;
    
    public class A_simple_caculator {
    
        private static void addComponentsToPane(Container pane) {
    
        	 JComboBox<String> box =  new JComboBox();
        	 box.addItem("+");
        	 box.addItem("-");
        	 box.addItem("*");
        	 box.addItem("/");
        	 
            pane.setLayout(new FlowLayout());  // content pane默认是BorderLayout,现在设置为Flowlayout
           
            pane.add(new JTextField(8)); 
            pane.add(box);
            pane.add(new JTextField(8));
            pane.add(new JButton("="));
            pane.add(new JTextField(8));
    
        }
    
        private static void createAndShowGUI() {
    
            //Create and set up the window.
            JFrame frame = new JFrame("A_simple_caculator");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            //Set up the content pane.
            addComponentsToPane(frame.getContentPane());
            //Display the window.
            frame.pack();
            frame.setVisible(true);
        }
    
        public static void main(String[] args) {              
            
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
                }
            });
        }
    }
    public static void main(String args[]) {
            // Create the frame on the main thread
            // which is not event dispatching thread.
            createAndShowGUI(); 
        }          
    //main函数这样写也可以成功运行,但是基于线程安全考虑,不能这样写。


    参考资料 : java swing编程介绍


    鲜花会生锈,盐巴会腐烂
  • 相关阅读:
    C盘的可用空间忽大忽小
    安装软件时不能指定软件的安装目录
    MySQL安装排坑
    Butterfly主题目录生成不了问题
    apache+php安装配置的各种问题
    环境变量配置不成功
    http模块
    Node.js
    Spring Boot入门
    代码优化笔记
  • 原文地址:https://www.cnblogs.com/hunterxing/p/9709308.html
Copyright © 2011-2022 走看看