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编程介绍


    鲜花会生锈,盐巴会腐烂
  • 相关阅读:
    cookie和session。
    K3cloud Web API对接---单据保存接口(有源单)
    K3 wise kis 防火墙设置
    新单序时簿插件
    mssqlserver中排序规则冲突的问题解决
    读取金蝶图片
    金蝶wise委外订单关闭简述
    存储过程加锁
    判断存储过程是否存在
    解除死锁
  • 原文地址:https://www.cnblogs.com/hunterxing/p/9709308.html
Copyright © 2011-2022 走看看