• 求和计算器


    package day46;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    import javax.swing.*;
    public class windows implements ActionListener {
        JFrame jf;
        JPanel jp,jp1;
        JButton jb1,jb2;
        JTextField  jt1,jt2,jt3;
        JLabel  jl,jl1;
        public windows() {
             jf=new JFrame("求和");
             jp=new JPanel(new GridLayout(2,2,10,10));
             jp1=new JPanel();
             jl=new JLabel("加数1");
             jl1=new JLabel("加数2");
             jt1=new JTextField(10);
             jt2=new JTextField(10);
             jp.add(jl);
             jp.add(jt1);
             jp.add(jl1);
             jp.add(jt2);
             jb1=new JButton("求和");
             jt3=new JTextField(10);
             jb2=new JButton("清除");
             jp1.add(jb1);
             jb1.addActionListener(this);
             jp1.add(jt3);
             jp1.add(jb2);
             jb2.addActionListener(this);
             
            
            jf.add(BorderLayout.SOUTH,jp1);
            jf.add(BorderLayout.CENTER,jp);
            jf.setSize(300,200);
            jf.setVisible(true);
            
        }
        public void actionPerformed(ActionEvent e) {
            if(e.getActionCommand().equals("求和")) {
                String a=jt1.getText();
                String b=jt2.getText();
                int a1=Integer.parseInt(a);
                int b1=Integer.parseInt(b);
                 String c =String.valueOf(a1+b1);
                jt3.setText(c);
            }
            else {
                jt1.setText(null);
                jt2.setText(null);
                jt3.setText(null);
            }
            
            
        }
        public static void main(String[] args) {
            new windows();
            
        }
        
        
        
    
    }

  • 相关阅读:
    分布式中各种概念汇总
    JMS
    spring boot jpa mysql
    spring boot 视图层(JAVA之学习-2)
    idea+spring boot的初学(JAVA学习之1)
    Yii在cli模式下执行一些脚本的配置
    在centos下安装django
    python简单的发送邮件
    ElasticSearch-PHP的API使用(二)
    Elasticsearch的PHP的API使用(一)
  • 原文地址:https://www.cnblogs.com/Lwl2019/p/11031517.html
Copyright © 2020-2023  润新知