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


    鲜花会生锈,盐巴会腐烂
  • 相关阅读:
    点击复制的代码
    色彩浅谈——同色系的变化
    网页设计中色彩的运用
    网页设计中透明效果的使用技巧
    基于栅格的网站设计
    页面之门——登录页的设计分析
    错误变惊喜,10个有趣的404页面设计(转)
    jQuery load()方法用法集锦!
    RPM命令用法
    如何使iframe透明
  • 原文地址:https://www.cnblogs.com/hunterxing/p/9709308.html
Copyright © 2020-2023  润新知