zoukankan      html  css  js  c++  java
  • 编程的乐趣

    闲来无事,自学了java的GUI,用windowsbuilder做了一个小型计算器,哈哈,开心!

    package javatest;

    import java.awt.BorderLayout;
    import java.awt.EventQueue;

    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.border.EmptyBorder;

    import org.omg.CORBA.PUBLIC_MEMBER;

    import javax.swing.JLabel;
    import javax.swing.JTextField;
    import javax.swing.JComboBox;
    import javax.swing.JButton;
    import javax.swing.DefaultComboBoxModel;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import java.awt.event.ItemListener;
    import java.nio.file.StandardCopyOption;
    import java.awt.event.ItemEvent;

    public class computer extends JFrame {
     public String s="";
     private JPanel contentPane;
     private JTextField textField;
     private JTextField textField_1;
     private JTextField textField_2;

     /**
      * Launch the application.
      */
     public static void main(String[] args) {
      EventQueue.invokeLater(new Runnable() {
       public void run() {
        try {
         computer frame = new computer();
         frame.setVisible(true);
        } catch (Exception e) {
         e.printStackTrace();
        }
       }
      });
     }

     /**
      * Create the frame.
      */
     public computer() {
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      setBounds(100, 100, 491, 373);
      contentPane = new JPanel();
      contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
      setContentPane(contentPane);
      contentPane.setLayout(null);
      
      JLabel lblA = new JLabel("A");
      lblA.setBounds(79, 35, 36, 21);
      contentPane.add(lblA);
      
      JLabel label = new JLabel("u8FD0u7B97u7B26");
      label.setBounds(188, 25, 81, 21);
      contentPane.add(label);
      
      JLabel lblB = new JLabel("B");
      lblB.setBounds(291, 25, 104, 21);
      contentPane.add(lblB);
      
      textField = new JTextField();
      textField.setBounds(69, 71, 115, 43);
      contentPane.add(textField);
      textField.setColumns(10);
      
      textField_1 = new JTextField();
      textField_1.setBounds(291, 71, 112, 43);
      contentPane.add(textField_1);
      textField_1.setColumns(10);
      
      JComboBox comboBox = new JComboBox();
      comboBox.addItemListener(new ItemListener() {
       public void itemStateChanged(ItemEvent e) {
        if(e.getStateChange()==ItemEvent.SELECTED){
         s=comboBox.getSelectedItem().toString();
        }
       }
      });
      comboBox.setModel(new DefaultComboBoxModel(new String[] {"+", "-", "*", "/"}));
      comboBox.setBounds(180, 71, 112, 43);
      contentPane.add(comboBox);
      
      textField_2 = new JTextField();
      textField_2.setBounds(69, 113, 334, 83);
      contentPane.add(textField_2);
      textField_2.setColumns(10);
      
      JButton btnNewButton = new JButton("u8BA1u7B97");
      btnNewButton.addActionListener(new ActionListener() {
       public void actionPerformed(ActionEvent e) {
        int ai=Integer.parseInt(textField.getText());
        int bi=Integer.parseInt(textField_1.getText());
        if(s.equals("+")){
         String result=String.valueOf(ai+bi);
         textField_2.setText("A+B= "+result);
        }
        if(s.equals("-")){
         String result=String.valueOf(ai-bi);
         textField_2.setText("A-B= "+result);
        }
        if(s.equals("*")){
         String result=String.valueOf(ai*bi);
         textField_2.setText("A*B= "+result);
        }
        if(s.equals("/")){
         String result=String.valueOf(ai/bi);
         textField_2.setText("A/B= "+result);
        }
        
       }
      });
      btnNewButton.setBounds(69, 196, 123, 29);
      contentPane.add(btnNewButton);
      
      JButton btnNewButton_1 = new JButton("u9000u51FA");
      btnNewButton_1.addActionListener(new ActionListener() {
       public void actionPerformed(ActionEvent e) {
        System.exit(0);
       }
      });
      btnNewButton_1.setBounds(280, 196, 123, 29);
      contentPane.add(btnNewButton_1);
     }
    }

  • 相关阅读:
    广告小程序后端开发(8.发布免费广告或店铺,以及上传图片)
    广告小程序后端开发(7.获取价格表数据)
    广告小程序后端开发(6.获取类别逻辑)
    广告小程序后端开发(5.安装配置django-rest-framework,编写后台登录逻辑)
    广告小程序后端开发(4.导入地区数据,修改adminx,修改models,手动添加模拟数据)
    广告小程序后端开发(3.xadmin的引入)
    广告小程序后端开发(2.Models设计)
    使用django执行数据更新命令时报错:django.db.migrations.exceptions.InconsistentMigrationHistory: Migration admin.0001_initial is applied before its dependency users.00 01_initial on database 'default'.
    广告小程序后端开发(1.新建项目、连接数据库)
    pycharm的Database连接新的Mysql5.7报错[08001]
  • 原文地址:https://www.cnblogs.com/yfz1552800131/p/5450726.html
Copyright © 2011-2022 走看看