• 四则运算


    package sy11;
    
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    
    public class ChengFa {
        public static void main(String[] args) {
            new MulJframe();
        }
    }
    
    class ChengfaMul {// 定义全局变量
        public static int mul = 0;
    }
    
    class MulJframe extends JFrame {
        MulJframe() {
            setLayout(null);
            Container con = getContentPane();// 创建一个内容面板容器
            bank1();// 获得题目
            bank2();// 确认答案
            setTitle("100以內的乘法测试");
            setBounds(200, 200, 600, 300);// 设置出现位置和窗口大小
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 设置关闭方式
            setVisible(true);// 设置是否展示窗口
            con.setBackground(Color.lightGray);
        }
    
        void bank1() {// 获得题目按钮区
            JTextField jt = new JTextField();// 文本框1
            jt.setBounds(120, 40, 200, 30);
            JButton jb1 = new JButton();// 按钮1
            jb1.setBounds(20, 40, 100, 30);
            jb1.setText("获得题目");
            jb1.addActionListener(new ActionListener() {
    
                public void actionPerformed(ActionEvent e) {
    
                    int chengshu1 = (int) (Math.random() * 100 + 1);
                    int chengshu2 = (int) (Math.random() * 100 + 1);
                    String cs1 = "" + chengshu1;
                    String cs2 = "" + chengshu2;
                    ChengfaMul.mul = chengshu1 * chengshu2;
                    jt.setText(cs1 + "X" + cs2 + "=" + "");
                }
            });
            add(jt);
            add(jb1);
        }
    
        void bank2() {// 确认答案按钮区
            JTextField jt2 = new JTextField();// 文本框2
            jt2.setBounds(120, 75, 200, 30);
            JButton jb2 = new JButton();// 按钮1
            jb2.setBounds(20, 75, 100, 30);
            jb2.setText("确认答案");
            jb2.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    int mul = ChengfaMul.mul;
                    String inputMul = jt2.getText();
                    int inputmul = Integer.parseInt(inputMul);
                    System.out.println("mul=" + mul);
                    System.out.println("inputMul=" + inputMul);
                    if (inputmul == mul) {
    
                        JOptionPane.showMessageDialog(null, "答案正确", "消息对话框", JOptionPane.INFORMATION_MESSAGE);
                    } 
                    else {
                        JOptionPane.showMessageDialog(null, "答案错误", "消息对话框", JOptionPane.WARNING_MESSAGE);
                    }
                }
            });
            add(jt2);
            add(jb2);
        }
    }
    package sy11;
    
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    
    public class ChuFa {
    	public static void main(String[] args) {
    		new ChuFaJframe();
    	}
    }
    
    class ChufaDiv {// 定义全局变量
    	public static int division = 0;
    }
    
    class ChuFaJframe extends JFrame {
    	ChuFaJframe() {
    		setLayout(null);
    		Container con = getContentPane();// 创建一个内容面板容器
    		bank1();// 获得题目
    		bank2();// 确认答案
    		setTitle("100以內的除法测试");
    		setBounds(200, 200, 600, 300);// 设置出现位置和窗口大小
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 设置关闭方式
    		setVisible(true);// 设置是否展示窗口
    		con.setBackground(Color.lightGray);
    	}
    
    	void bank1() {// 获得题目按钮区
    		JTextField jt = new JTextField();// 文本框1
    		jt.setBounds(120, 40, 200, 30);
    		JButton jb1 = new JButton();// 按钮1
    		jb1.setBounds(20, 40, 100, 30);
    		jb1.setText("获得题目");
    		jb1.addActionListener(new ActionListener() {
    
    			public void actionPerformed(ActionEvent e) {
    
    				int beichushu = (int) (Math.random() * 100 + 1);
    				int chushu = (int) (Math.random() * beichushu + 1);
    				String js1 = "" + beichushu;
    				String js2 = "" + chushu;
    				ChufaDiv.division = beichushu / chushu;
    				jt.setText(js1 + "➗" + js2 + "=" + "");
    			}
    		});
    		add(jt);
    		add(jb1);
    	}
    
    	void bank2() {// 确认答案按钮区
    		JTextField jt2 = new JTextField();// 文本框2
    		jt2.setBounds(120, 75, 200, 30);
    		JButton jb2 = new JButton();// 按钮1
    		jb2.setBounds(20, 75, 100, 30);
    		jb2.setText("确认答案");
    		jb2.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
    				int div = ChufaDiv.division;
    				String inputDiv = jt2.getText();
    				int inputdiv = Integer.parseInt(inputDiv);
    				System.out.println("division=" + div);
    				System.out.println("inputDiv=" + inputDiv);
    				if (inputdiv == div) {
    
    					JOptionPane.showMessageDialog(null, "答案正确", "消息对话框", JOptionPane.INFORMATION_MESSAGE);
    				} 
    				else {
    					JOptionPane.showMessageDialog(null, "答案错误", "消息对话框", JOptionPane.WARNING_MESSAGE);
    				}
    			}
    		});
    		add(jt2);
    		add(jb2);
    	}
    }
    

      

    package sy11;
    
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    
    public class JiaFa {
        public static void main(String[] args) {
            new NumJframe();
        }
    }
    
    class JiafaSum {// 定义全局变量
        public static int sum = 0;
    }
    
    class NumJframe extends JFrame {
        NumJframe() {
            setLayout(null);
            Container con = getContentPane();// 创建一个内容面板容器
            bank1();// 获得题目
            bank2();// 确认答案
            setTitle("100以內的加法测试");
            setBounds(200, 200, 600, 300);// 设置出现位置和窗口大小
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 设置关闭方式
            setVisible(true);// 设置是否展示窗口
            con.setBackground(Color.lightGray);
        }
    
        void bank1() {// 获得题目按钮区
            JTextField jt = new JTextField();// 文本框1
            jt.setBounds(120, 40, 200, 30);
            JButton jb1 = new JButton();// 按钮1
            jb1.setBounds(20, 40, 100, 30);
            jb1.setText("获得题目");
            jb1.addActionListener(new ActionListener() {
    
                public void actionPerformed(ActionEvent e) {
    
                    int jiashu1 = (int) (Math.random() * 100 + 1);
                    int jiashu2 = (int) (Math.random() * 100 + 1);
                    String js1 = "" + jiashu1;
                    String js2 = "" + jiashu2;
                    JiafaSum.sum = jiashu1 + jiashu2;
                    jt.setText(js1 + "+" + js2 + "=" + "");
                }
            });
            add(jt);
            add(jb1);
        }
    
        void bank2() {// 确认答案按钮区
            JTextField jt2 = new JTextField();// 文本框2
            jt2.setBounds(120, 75, 200, 30);
            JButton jb2 = new JButton();// 按钮1
            jb2.setBounds(20, 75, 100, 30);
            jb2.setText("确认答案");
            jb2.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    int sum = JiafaSum.sum;
                    String inputSum = jt2.getText();
                    int inputsum = Integer.parseInt(inputSum);
                    System.out.println("sum=" + sum);
                    System.out.println("inputSum=" + inputSum);
                    if (inputsum == sum) {
    
                        JOptionPane.showMessageDialog(null, "答案正确", "消息对话框", JOptionPane.INFORMATION_MESSAGE);
                    } else {
                        JOptionPane.showMessageDialog(null, "答案错误", "消息对话框", JOptionPane.WARNING_MESSAGE);
                    }
                }
            });
            add(jt2);
            add(jb2);
        }
    }
    package sy11;
    
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    
    public class JianFa {
        public static void main(String[] args) {
            new jianfaJframe();
        }
    }
    
    class jianfaDiff {// 定义全局变量
        public static int diff = 0;
    }
    
    class jianfaJframe extends JFrame {
        jianfaJframe() {
            setLayout(null);
            Container con = getContentPane();// 创建一个内容面板容器
            bank1();// 获得题目
            bank2();// 确认答案
            setTitle("100以內的减法测试");
            setBounds(200, 200, 600, 300);// 设置出现位置和窗口大小
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 设置关闭方式
            setVisible(true);// 设置是否展示窗口
            con.setBackground(Color.lightGray);
        }
    
        void bank1() {// 获得题目按钮区
            JTextField jt = new JTextField();// 文本框1
            jt.setBounds(120, 40, 200, 30);
            JButton jb1 = new JButton();// 按钮1
            jb1.setBounds(20, 40, 100, 30);
            jb1.setText("获得题目");
            jb1.addActionListener(new ActionListener() {
    
                public void actionPerformed(ActionEvent e) {
    
                    int beijianshu = (int) (Math.random() * 100 + 1);
                    int jianshu = (int) (Math.random() * beijianshu + 1);
                    String bjs = "" + beijianshu;
                    String js = "" + jianshu;
                    jianfaDiff.diff = beijianshu - jianshu;
                    jt.setText(bjs + "-" + js + "=" + "");
                }
            });
            add(jt);
            add(jb1);
        }
    
        void bank2() {// 确认答案按钮区
            JTextField jt2 = new JTextField();// 文本框2
            jt2.setBounds(120, 75, 200, 30);
            JButton jb2 = new JButton();// 按钮1
            jb2.setBounds(20, 75, 100, 30);
            jb2.setText("确认答案");
            jb2.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    int diff = jianfaDiff.diff;
                    String inputDiff = jt2.getText();
                    int inputdiff = Integer.parseInt(inputDiff);
                    System.out.println("diff=" + diff);
                    System.out.println("inputSum=" + inputDiff);
                    if (inputdiff == diff) {
    
                        JOptionPane.showMessageDialog(null, "答案正确", "消息对话框", JOptionPane.INFORMATION_MESSAGE);
                    } 
                    else {
                        JOptionPane.showMessageDialog(null, "答案错误", "消息对话框", JOptionPane.WARNING_MESSAGE);
                    }
                }
            });
            add(jt2);
            add(jb2);
        }
    }
  • 相关阅读:
    Scrapy爬虫的基本使用
    scrapy 常见问题
    yield 关键字的使用
    Scrapy 爬虫框架
    股票数据爬虫
    为什么CNN需要固定输入图像的尺寸
    实战 7 淘宝商品信息定向爬虫
    正则表达式
    w​x​F​o​r​m​B​u​i​l​d​e​r​初​体​验
    wxwidget wxpython 可视化开发工具
  • 原文地址:https://www.cnblogs.com/study007/p/15350015.html
Copyright © 2020-2023  润新知