码迷,mamicode.com
首页 > 其他好文 > 详细

练习2-小学生四则运算系统

时间:2015-04-09 21:32:55      阅读:425      评论:0      收藏:0      [点我收藏+]

标签:

---恢复内容开始---

开发环境:  Eclipse

题目方向:  一个能自动生成小学四则运算题目的程序,一个单机带用户界面(不是控制台)的程序。

题目要求:  

  • 生成题目,单个题目最多不能超过4个运算符,操作数小于100。
  • 用户可以输入答案
  • 若用户输入答案正确,则提示正确;若答案错误,则提示错误,并要提示正确答案是多少。

结对子用时:  3天3夜+1个下午

题目扩展方向:

 

  • 程序设置了登录功能,新用户第一次使用程序时可以进行注册,旧用户使用程序时可以根据历史记录的信息而登录。
  • 程序可以设置皮肤功能,更改界面的颜色。
  • 用户可以设置做题的数目,答题结束后可以显示用户答题的对错数目并记录总分。
  • 表达式里面可以进行计算负数的运算题目。
  • 程序分别对加法、减法、乘法、除法设置了简单、适中和困难这3中程度的题目。
  • 程序出错时,系统会反馈出错误的信息。

 

结对伙伴:

姓名 学号 博客地址
方俊杰 201306114417 http://www.cnblogs.com/imfjj/
余雅诗 201306114453 http://www.cnblogs.com/ys1101/

源程序:  

 

package opar;

import java.awt.EventQueue;

import javax.swing.JFrame;
import java.awt.FlowLayout;
import javax.swing.JTextField;

import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.SwingConstants;

public class Login_Fail implements ActionListener{

    private JFrame frame;
    private JButton button;
    private JTextField textField;



    public Login_Fail() {
        initialize();
    }

    /**
     * Initialize the contents of the frame.
     */
    private void initialize() {
        frame = new JFrame();
        frame.setTitle("\u63D0\u793A");
        frame.setIconImage(Toolkit.getDefaultToolkit().getImage(Login_Fail.class.getResource("/opar/\u6807\u7B7E.jpg")));
        Dimension screenSize =Toolkit.getDefaultToolkit().getScreenSize();
        frame.setSize(200, 200 );
        frame.setLocation((screenSize.width-200 )/2, (screenSize.height-200)/2);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
        
        textField = new JTextField();
        textField.setHorizontalAlignment(SwingConstants.CENTER);
        textField.setEditable(false);
        textField.setText("\u8D26\u6237\u4E0D\u5B58\u5728\u6216\u5BC6\u7801\u9519\u8BEF");
        frame.getContentPane().add(textField);
        textField.setColumns(10);
        
        button = new JButton("\u91CD\u65B0\u767B\u5F55");
        frame.getContentPane().add(button);
        button.addActionListener(this);
        
        
        
    
        
    }
    public void Set_Ssetvial(boolean y)
    {
        this.frame.setVisible(y);
    }
    @Override
    public void actionPerformed(ActionEvent arg0) {
        // TODO Auto-generated method stub
        if(arg0.getSource()==this.button)//重新登录
        {
            
            this.frame.setVisible(false);
        
        }
        
        
    }
    public void Set_T(String x)
    {
        this.textField.setText(x);
    }
}

 

package opar;

import java.awt.EventQueue;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.BorderLayout;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JPanel;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.Color;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;

public class Login_Pupil_Enroll implements ActionListener {

    private JFrame frame;
    private JTextField textField;
    private JTextField textField_3;
    private JTextField textField_4;
    private JPasswordField passwordField;
    private JPasswordField passwordField_1;
    private JButton button_1;
    private JButton button;
    private File Pupil_Path;
    private File Pupil_Information;
    private JPasswordField passwordField_2;

    /**
     * Launch the application.
     */

    /**
     * Create the application.
     * 
     * @throws IOException
     */
    // 构造方法
    public Login_Pupil_Enroll() throws IOException {
        initialize();
        Pupil_Path = new File("D:/Pupil_Path");

        if (!Pupil_Path.exists()) {
            Pupil_Path.mkdirs();

        }
        Pupil_Information = new File(Pupil_Path, "小学生用户.txt");
        Pupil_Information.createNewFile();
    }

    /**
     * Initialize the contents of the frame.
     */
    // 初始化方法
    private void initialize() {
        frame = new JFrame();
        frame.setTitle("\u65B0\u7528\u6237\u6CE8\u518C");
        frame.setIconImage(Toolkit.getDefaultToolkit().getImage(Login_Pupil_Enroll.class.getResource("/opar/\u6807\u7B7E.jpg")));
        frame.getContentPane().setBackground(new Color(176, 224, 230));
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        frame.setSize(400, 400);
        frame.setLocation((screenSize.width - 400) / 2,
                (screenSize.height - 400) / 2);
        frame.getContentPane().setLayout(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JPanel panel = new JPanel();
        panel.setBackground(new Color(224, 255, 255));

        JPanel panel_1 = new JPanel();
        panel_1.setToolTipText("\u65B0\u7528\u6237\u6CE8\u518C");
        panel_1.setBackground(new Color(224, 255, 255));
        GroupLayout groupLayout = new GroupLayout(frame.getContentPane());
        groupLayout.setHorizontalGroup(
            groupLayout.createParallelGroup(Alignment.LEADING)
                .addGroup(groupLayout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING, false)
                        .addComponent(panel_1, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(panel, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 365, Short.MAX_VALUE))
                    .addGap(53))
        );
        groupLayout.setVerticalGroup(
            groupLayout.createParallelGroup(Alignment.LEADING)
                .addGroup(groupLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(panel, GroupLayout.PREFERRED_SIZE, 62, GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(ComponentPlacement.UNRELATED)
                    .addComponent(panel_1, GroupLayout.DEFAULT_SIZE, 270, Short.MAX_VALUE)
                    .addContainerGap())
        );
        panel_1.setLayout(null);

        JLabel label = new JLabel("\u7528\u6237\u6635\u79F0\uFF1A");
        label.setBounds(23, 28, 72, 15);
        panel_1.add(label);

        JLabel label_1 = new JLabel("\u7528\u6237\u5BC6\u7801\uFF1A");
        label_1.setBounds(23, 53, 72, 15);
        panel_1.add(label_1);

        JLabel label_2 = new JLabel("\u786E\u8BA4\u5BC6\u7801\uFF1A");
        label_2.setBounds(23, 78, 72, 15);
        panel_1.add(label_2);

        textField = new JTextField();
        textField.setBounds(94, 28, 172, 21);
        panel_1.add(textField);
        textField.setColumns(10);

        textField_3 = new JTextField();
        textField_3.setEditable(false);
        textField_3.setBounds(94, 174, 172, 21);
        panel_1.add(textField_3);
        textField_3.setColumns(10);

        JLabel label_3 = new JLabel("\u53CD\u9988\u6846\uFF1A");
        label_3.setBounds(33, 174, 72, 15);
        panel_1.add(label_3);

        textField_4 = new JTextField();
        textField_4.setBounds(94, 109, 172, 21);
        panel_1.add(textField_4);
        textField_4.setColumns(10);

        JLabel label_4 = new JLabel("\u8EAB\u4EFD\u8BC1\u53F7\uFF1A");
        label_4.setBounds(23, 103, 72, 27);
        panel_1.add(label_4);

        passwordField = new JPasswordField();
        passwordField.setBounds(94, 53, 172, 21);
        panel_1.add(passwordField);

        passwordField_1 = new JPasswordField();
        passwordField_1.setBounds(94, 78, 173, 21);
        panel_1.add(passwordField_1);

        button = new JButton("\u786E\u8BA4");
        button.setBounds(63, 221, 93, 23);
        panel_1.add(button);
        button.addActionListener(this);

        button_1 = new JButton("\u8FD4\u56DE");
        button_1.setBounds(210, 221, 93, 23);
        panel_1.add(button_1);

        JLabel label_5 = new JLabel("\u786E\u8BA4\u4E00\u6B21\uFF1A");
        label_5.setBounds(23, 140, 72, 24);
        panel_1.add(label_5);

        passwordField_2 = new JPasswordField();
        passwordField_2.setBounds(94, 143, 172, 21);
        panel_1.add(passwordField_2);
        
        JLabel label_6 = new JLabel("*/6-12\u4E2A\u5B57\u7B26");
        label_6.setBounds(280, 28, 75, 15);
        panel_1.add(label_6);
        
        JLabel label_7 = new JLabel("*/6\u4E2A\u5B57\u7B26");
        label_7.setBounds(280, 53, 75, 15);
        panel_1.add(label_7);
        
        JLabel label_8 = new JLabel("*/6\u4E2A\u5B57\u7B26");
        label_8.setBounds(280, 78, 75, 15);
        panel_1.add(label_8);
        
        JLabel label_9 = new JLabel("*/18\u4E2A\u6570\u5B57");
        label_9.setBounds(280, 109, 75, 15);
        panel_1.add(label_9);
        
        JLabel label_10 = new JLabel("*/18\u4E2A\u6570\u5B57");
        label_10.setBounds(280, 146, 75, 15);
        panel_1.add(label_10);
        
        JLabel label_11 = new JLabel("*/\u6CE8\u518C\u52A8\u6001");
        label_11.setToolTipText("\u6CE8\u518C\u52A8\u6001");
        label_11.setBounds(280, 174, 75, 15);
        panel_1.add(label_11);
        panel.setLayout(null);
        button_1.addActionListener(this);

        JLabel lblNewLabel = new JLabel("\u7528\u6237\u6CE8\u518C\u4E2D");
        lblNewLabel.setBackground(Color.CYAN);
        lblNewLabel.setFont(new Font("宋体", Font.PLAIN, 30));
        lblNewLabel.setBounds(105, 10, 182, 42);
        panel.add(lblNewLabel);
        frame.getContentPane().setLayout(groupLayout);

    }

    public void Set_Setvial(boolean y) {
        this.frame.setVisible(y);
    }

    @Override
    // 对事件处理接口的方法
    public void actionPerformed(ActionEvent arg0) {
        // TODO Auto-generated method stub
        if (arg0.getSource() == this.button) {
            try {
                FileWriter filew = new FileWriter(Pupil_Information, true);
                if (this.textField.getText().length() <= 12
                        && this.textField.getText().length() >= 6) {
                    if (this.passwordField.getText().length() == 6
                            && this.passwordField.getText().length() == 6) {
                        if (this.passwordField.getText().hashCode() == this.passwordField_1
                                .getText().hashCode()) {
                            if (this.textField_4.getText().matches("[0-9]*")
                                    && this.passwordField_2.getText().matches(
                                            "[0-9]*")) {
                                if (this.textField_4.getText().length() == 18
                                        && this.passwordField_2.getText()
                                                .length() == 18) {
                                    if (this.textField_4.getText().hashCode() == this.passwordField_2
                                            .getText().hashCode()) {
                                        filew.write(this.textField.getText()
                                                + "\t");
                                        filew.write(this.passwordField
                                                .getText() + "\t");
                                        filew.write(this.textField_4.getText()
                                                + "\t\r\n");
                                        
                                        filew.flush() ; //关闭前刷新
                                        filew.close();
                                        this.textField_3.setText(null);
                                        this.textField_3.setText("注册成功!");
                                        
                                        

                                    } else {
                                        this.textField_3.setText(null);
                                        this.textField_3
                                                .setText(this.textField_3
                                                        .getText() + "身份证号不相同!");
                                    }
                                } else {
                                    this.textField_3.setText(null);
                                    this.textField_3.setText(this.textField_3
                                            .getText() + "身份证号应为18位!");
                                }
                            } else {
                                this.textField_3.setText(null);
                                this.textField_3.setText(this.textField_3
                                        .getText() + "身份证号应为数字!");
                            }

                        } else {
                            this.textField_3.setText(null);
                            this.textField_3.setText(this.textField_3.getText()
                                    + "密码不相同!");
                        }
                    } else {
                        this.textField_3.setText(null);
                        this.textField_3.setText(this.textField_3.getText()
                                + "密码不是6位!");
                    }

                } else {
                    this.textField_3.setText(null);
                    this.textField_3.setText(this.textField_3.getText()
                            + "不是6~12个字符");
                }

            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } else if (arg0.getSource() == this.button_1) {
            this.frame.setVisible(false);
            Login l = new Login();
            l.Set_frame(true);

        }

    }
}
package opar;

import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Toolkit;

import javax.swing.JFrame;
import java.awt.FlowLayout;
import javax.swing.JPanel;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JTextField;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.Color;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.awt.SystemColor;
import javax.swing.ImageIcon;
import javax.swing.SwingConstants;

class Login implements ActionListener ,KeyListener{

    private JFrame frame;
    private JPasswordField passwordField;
    private JTextField textField;
    private JButton button;// 确定
    private JButton button_1;// 重置
    private JButton btnNewButton;// 退出
    private JButton btnNewButton_1;// 注册
    private T t;;
    private Login_Fail lf;;
    private Login_Pupil_Enroll l_p_e;
    private File Pupil_Path;
    private File Pupil_Information;
    private FileReader filer;
    private BufferedReader br;
    private String b;
    private static int count = 0;
    private Pupil_Information_save[] Pupil = new Pupil_Information_save[100];
    private static int fig = 0;

    public Login() //
    {
        initialize();
    }

    public void Set_frame(boolean y) // 设置可视性
    {
        frame.setVisible(y);
    }

    private void initialize() {
        frame = new JFrame();
        frame.setTitle("\u65B9\u4FCA\u6770-\u4F59\u96C5\u8BD7");
        frame.setIconImage(Toolkit.getDefaultToolkit().getImage(Login.class.getResource("/opar/\u6807\u7B7E.jpg")));
        frame.getContentPane().setBackground(SystemColor.inactiveCaption);
        frame.setSize(500, 500);
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        frame.setLocation((screenSize.width - 500) / 2,
                (screenSize.height - 500) / 2);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JPanel panel = new JPanel();
        panel.setBackground(Color.PINK);

        JPanel panel_1 = new JPanel();
        panel_1.setBackground(Color.PINK);

        JPanel panel_2 = new JPanel();
        panel_2.setBackground(Color.PINK);
        GroupLayout groupLayout = new GroupLayout(frame.getContentPane());
        groupLayout.setHorizontalGroup(
            groupLayout.createParallelGroup(Alignment.LEADING)
                .addGroup(groupLayout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
                        .addComponent(panel_2, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 464, Short.MAX_VALUE)
                        .addComponent(panel_1, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 464, Short.MAX_VALUE)
                        .addComponent(panel, GroupLayout.DEFAULT_SIZE, 464, Short.MAX_VALUE))
                    .addContainerGap())
        );
        groupLayout.setVerticalGroup(
            groupLayout.createParallelGroup(Alignment.LEADING)
                .addGroup(groupLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(panel, GroupLayout.PREFERRED_SIZE, 85, GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(ComponentPlacement.RELATED)
                    .addComponent(panel_1, GroupLayout.PREFERRED_SIZE, 226, GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(ComponentPlacement.RELATED)
                    .addComponent(panel_2, GroupLayout.DEFAULT_SIZE, 119, Short.MAX_VALUE)
                    .addContainerGap())
        );

        panel_2.setLayout(null);
        
                btnNewButton = new JButton("");
                btnNewButton.setBackground(Color.PINK);
                btnNewButton.setToolTipText("");
                btnNewButton.setBounds(0, 0, 464, 119);
                panel_2.add(btnNewButton);
                btnNewButton.setIcon(new ImageIcon(Login.class.getResource("/opar/exit.png")));
                btnNewButton.addActionListener(this);
        panel_1.setLayout(null);

        JLabel label = new JLabel("\u7528\u6237\u540D\uFF1A");
        label.setFont(new Font("宋体", Font.PLAIN, 15));
        label.setBounds(57, 41, 66, 15);
        panel_1.add(label);

        JLabel label_1 = new JLabel("\u5BC6\u7801\uFF1A");
        label_1.setFont(new Font("宋体", Font.PLAIN, 15));
        label_1.setBounds(57, 87, 66, 15);
        panel_1.add(label_1);

        passwordField = new JPasswordField();
        passwordField.setBounds(133, 84, 237, 21);
        panel_1.add(passwordField);

        textField = new JTextField();
        textField.setBounds(133, 38, 237, 21);
        panel_1.add(textField);
        textField.setColumns(10);

        button = new JButton("\u767B\u5F55");
        button.setBounds(74, 134, 93, 23);
        panel_1.add(button);
        button.addActionListener(this);
        button.addKeyListener(this);

        button_1 = new JButton("\u91CD\u7F6E");
        button_1.setBounds(189, 134, 93, 23);
        panel_1.add(button_1);
        button_1.addActionListener(this);

        JLabel label_2 = new JLabel("^-^ \u52A0\u6CB9 ^-^");
        label_2.setBounds(202, 183, 77, 15);
        panel_1.add(label_2);

        btnNewButton_1 = new JButton("\u6CE8\u518C");
        btnNewButton_1.setBounds(306, 134, 86, 23);
        panel_1.add(btnNewButton_1);
        panel.setLayout(null);
        btnNewButton_1.addActionListener(this);

        JLabel lblNewLabel = new JLabel(
                "\u6B22\u8FCE\u767B\u5F55\u5C0F\u5B66\u751F\u56DB\u5219\u8FD0\u7B97\u7CFB\u7EDF");
        lblNewLabel.setBackground(Color.PINK);
        lblNewLabel.setForeground(SystemColor.inactiveCaptionText);
        lblNewLabel.setFont(new Font("宋体", Font.PLAIN, 30));
        lblNewLabel.setBounds(37, 10, 390, 65);
        panel.add(lblNewLabel);

        t = new T();
        lf = new Login_Fail();
        try {
            l_p_e = new Login_Pupil_Enroll();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            System.out.print("不能够创建小学生用户登录文档");
        }

        frame.getContentPane().setLayout(groupLayout);
        // frame.setVisible(true);
    }

    JButton Get_button() {
        return button;
    }

    JButton Get_button_1() {
        return button_1;
    }

    JButton Get_btnNewButton_1() {
        return btnNewButton_1;
    }

    JButton Get_btnNewButton() {
        return btnNewButton;
    }

    JPasswordField Get_PasswordField() {
        return passwordField;
    }

    JTextField Get_textField() {
        return textField;
    }

    @Override
    public void actionPerformed(ActionEvent arg0) {
        // TODO Auto-generated method stub
        // 登录按钮
        if (arg0.getSource() == this.button) {
            Pupil_Path = new File("D:/Pupil_Path");

            if (!Pupil_Path.exists()) {
                Pupil_Path.mkdirs();

            }
            Pupil_Information = new File(Pupil_Path, "小学生用户.txt");
            try {
                Pupil_Information.createNewFile();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            try {
                filer = new FileReader(Pupil_Information);
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            br = new BufferedReader(filer);

            b = "";
            try {
                while ((b = br.readLine()) != null) {

                    String[] sFirst = b.split("\t");// System.out.print(b);
                    Pupil[count] = new Pupil_Information_save(sFirst[0],
                            sFirst[1], sFirst[2]);

                    count++;

                }
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
           fig=0;//标记初始化
            for (int i = 0; i < count; i++) {

                if (this.textField.getText().hashCode() == Pupil[i].Get_Name()
                        .hashCode()) {fig = 1;
                    if (this.passwordField.getText().hashCode() == Pupil[i]
                            .Get_Code().hashCode()) {
                        t.Set_Setvial(true);
                        this.Set_frame(false);
                        fig=2;
                        

                    }
                    

                }
            

            }

            if (fig == 0)
            {

                lf.Set_T("账户不存在!");
                lf.Set_Ssetvial(true);
            }
            else if (fig == 1) {
    
                lf.Set_T("密码错误!");
                lf.Set_Ssetvial(true);

            }

        }

        // 重置按钮
        else if (arg0.getSource() == this.button_1) {
            this.textField.setText(null);
            this.passwordField.setText(null);
        }
        // 注册按钮
        else if (arg0.getSource() == this.btnNewButton_1) {
            this.Set_frame(false);
            l_p_e.Set_Setvial(true);
        } else if (arg0.getSource() == this.btnNewButton) {
            System.exit(0);
        }

    }

    @Override
    public void keyPressed(KeyEvent arg0) {
        // TODO Auto-generated method stub
        if(arg0.getKeyCode()==KeyEvent.VK_ENTER)
        {
            System.out.print("ssss");
            Pupil_Path = new File("D:/Pupil_Path");

            if (!Pupil_Path.exists()) {
                Pupil_Path.mkdirs();

            }
            Pupil_Information = new File(Pupil_Path, "小学生用户.txt");
            try {
                Pupil_Information.createNewFile();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            try {
                filer = new FileReader(Pupil_Information);
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            br = new BufferedReader(filer);

            b = "";
            try {
                while ((b = br.readLine()) != null) {

                    String[] sFirst = b.split("\t");// System.out.print(b);
                    Pupil[count] = new Pupil_Information_save(sFirst[0],
                            sFirst[1], sFirst[2]);

                    count++;

                }
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
           fig=0;//标记初始化
            for (int i = 0; i < count; i++) {

                if (this.textField.getText().hashCode() == Pupil[i].Get_Name()
                        .hashCode()) {fig = 1;
                    if (this.passwordField.getText().hashCode() == Pupil[i]
                            .Get_Code().hashCode()) {
                        t.Set_Setvial(true);
                        this.Set_frame(false);
                        fig=2;
                        

                    }
                    

                }
            

            }

            if (fig == 0)
            {

                lf.Set_T("账户不存在!");
                lf.Set_Ssetvial(true);
            }
            else if (fig == 1) {
    
                lf.Set_T("密码错误!");
                lf.Set_Ssetvial(true);

            }

        }
        
        
    }

    @Override
    public void keyReleased(KeyEvent arg0) {
        // TODO Auto-generated method stub
        
    }

    @Override
    public void keyTyped(KeyEvent arg0) {
        // TODO Auto-generated method stub
        
    }
}
package opar;

public class Pupil_Information_save {
    private String Name;//昵称
    private String Code;//密码
    private String ID_card_No;//身份证号码
    public Pupil_Information_save(String a,String b,String c)
    {
        this.Name=a;
        this.Code=b;
        this.ID_card_No=c;
    }
    public String Get_Name()
    {
        return this.Name;
    }
    public String Get_Code()
    {
        return this.Code;
    }
    String Get_ID_card_No()
    {
        return ID_card_No;
    }

}
package opar;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class T_Event implements ActionListener, KeyListener {

    static int t = 0;
    static int f = 0;
    static int con = 1;// 默认适中
    static int del = 0;
    private static int sum=1000;
    private static int times=0;
    void Set_t(int t) {
        this.t = this.t + 1;
    }

    void Set_f(int f) {
        this.f = this.f + 1;
    }

    void Set_del() {
        while (new T().Get_T2() == 0 || new T().Get_T() % new T().Get_T2() != 0) {
            if (con == 0)
                new T().Set_rom_rom1(0, 20);

            else if (con == 1)
                new T().Set_rom_rom1(11, 500);

            else if (con == 2)
                new T().Set_rom_rom1(501, 10000);

            new T().set_T_T1_T2_T3();

        }
    }

    int Get_t() {
        return t;
    }

    int Get_f() {
        return f;
    }

    public void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub

        if (e.getSource() == new T().button_1)// 加法
        {
            del = 0;
            new T().Set_T1("+");
        }
        if (e.getSource() == new T().button_2)// 减法
        {
            del = 0;
            new T().Set_T1("-");
        }
        if (e.getSource() == new T().button_3)// 乘法
        {
            del = 0;
            new T().Set_T1("*");
        }
        if (e.getSource() == new T().btnNewButton_3)// 除法
        {
            this.Set_del();
            del = 1;
            new T().Set_T1("/");

        }
        if(e.getSource()==new T().Get_btnNewButton_4())
        {
            this.t=0;//初始化
            this.f=0;//初始化
            this.times=0;
            
            //new T().Get_T12().setText();
            this.sum=10000;
            new T().set_T_T1_T2_T3();
            
            
            new T().Set_T_T1_T2_T3(true);
        }
        if (e.getSource() == new T().Get_btnNewButton())// 简单
        {
            new T().Set_rom_rom1(0, 20);
            new T().set_T_T1_T2_T3();
            con = 0;
            if (del == 1)
                this.Set_del();

        }
        if (e.getSource() == new T().Get_btnNewButton_1())// 适中
        {
            new T().Set_rom_rom1(11, 500);
            new T().set_T_T1_T2_T3();
            con = 1;
            if (del == 1)
                this.Set_del();

        }
        if (e.getSource() == new T().Get_btnNewButton_2())// 困难
        {
            new T().Set_rom_rom1(501, 10000);
            new T().set_T_T1_T2_T3();
            con = 2;
            if (del == 1)
                this.Set_del();

        }
        if (e.getSource() == new T().button)
            System.exit(0);
        if (e.getSource() == new T().Get_Com()) {
            int index = new T().Get_Com().getSelectedIndex();
            switch (index) {
            case 0:

                new T().Get_frame().getContentPane().setBackground(Color.RED);
                break;
            case 1:
                new T().Get_frame().getContentPane()
                        .setBackground(Color.orange);
                break;
            case 2:
                new T().Get_frame().getContentPane()
                        .setBackground(Color.yellow);
                break;
            case 3:
                new T().Get_frame().getContentPane().setBackground(Color.green);
                break;
            case 4:
                new T().Get_frame().getContentPane().setBackground(Color.blue);
                break;

            }
        }

    }

    @Override
    public void keyPressed(KeyEvent arg0) {
       //判断是回车
        
        if (arg0.getKeyCode() == KeyEvent.VK_ENTER) {
           if(new T().Get_T12().getText().length()!=0)
               {
               sum=Integer.parseInt(new T().Get_T12().getText());//回车初始化题目数量
               }
           
            // Pattern pattern=Pattern.compile("[0-9]*");!isNum.matches()||
            // Matcher isNum=pattern.matcher(new T().Get_T3());
            if(this.sum>times)
            {
            if (new T().Get_T3().matches("-?[0-9]+.*[0-9]*")) {
                new T().Set_T4_T5_T6_T7();
                if (new T().Get_n() == Integer.parseInt(new T().Get_T3())) {
                    Set_t(t);
                    new T().Set_T9("你很厉害,答对了!");
                }

                else {
                    Set_f(f);
                    new T().Set_T9("你太大意了!答错了");
                    System.out.print(new T().Get_n()+"    "+Integer.parseInt(new T().Get_T3()));
                }

                new T().Set_T8_T10_T11();
                
                times++;
                
                //加减乘除的
                if (con == 0) {
                    new T().Set_rom_rom1(0, 20);
                    this.Set_del();
                } else if (con == 1) {
                    new T().Set_rom_rom1(21, 500);
                    this.Set_del();
                } else if (con == 2) {
                    new T().Set_rom_rom1(501, 10000);
                    this.Set_del();
                }
                
                
                
                
                new T().set_T_T1_T2_T3();
                
                if (del == 1)
                    this.Set_del();
            } else {
                new T().Set_T9("你输入的 “ " + new T().Get_T3() + " ”是非法数值");
                new T().Set_T3();

            }
            
            
            }
            else
            {
                new T().Set_T9(new T().Get_T9().getText()+"你已经完成"+new T().Get_T12().getText()+"道题目");
                new T().Set_T_T1_T2_T3(false);
            }

        }

    }
    
    
    

    public void keyReleased(KeyEvent arg0) {
    }

    public void keyTyped(KeyEvent arg0) {
    }
}
package opar;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionListener;
import java.util.*;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.Color;
import java.awt.Font;

public class T {
    private static JTextField textField;
    private static JTextField textField_1;
    private static JTextField textField_2;
    private static JTextField textField_3;
    private static JTextField textField_4;
    private static JTextField textField_5;
    private static JTextField textField_6;
    private static JLabel label;
    private static JTextField textField_7;
    private static JLabel label_1;
    private static JLabel label_2;
    private static JLabel label_3;
    private static JTextField textField_8;
    private static JTextField textField_9;
    private static JLabel label_4;
    private static JTextField textField_10;
    private static JTextField textField_11;
    private static JFrame frame;
    static Random r = new Random();
    static JButton button_1;
    static JButton button_2;
    static JButton button_3;
    static JButton btnNewButton_3;
    static JButton btnNewButton;
    static JButton btnNewButton_1;
    static JButton btnNewButton_2;
    static JButton button;
    static int n=0;
    static int rom=r.nextInt(501);
    static int rom1=r.nextInt(501);
    private static JLabel label_7;
    private static JLabel lblNewLabel_1;
    private static Login l;
    private static String []Skin={"红色","橙色","黄色","绿色","蓝色"};
    private static JComboBox comboBox ;
    private static String []Number={" 整数","小数"};
    private static JTextField textField_12;
    private static JButton btnNewButton_4;

    void Set_T_T1_T2_T3(boolean y)
    {
        
        this.textField_3.setEditable(y);
    }
    void Set_T3()
    {
        this.textField_3.setText(null);
    }
    
    void Set_Setvial(boolean y)
    {
        frame.setVisible(y);
    }
    void Set_T1(String x)
    {
        textField_1.setText(x);    
        
    }
    
    void Set_T4_T5_T6_T7()
    {
        
        
            textField_4.setText(textField.getText());
            textField_5.setText(textField_1.getText());    
            textField_6.setText(textField_2.getText());
            if(textField_1.getText().equals("+")==true)    
             n=Integer.parseInt(textField.getText())+Integer.parseInt(textField_2.getText());
            else if(textField_1.getText().equals("-")==true)    
                 n=Integer.parseInt(textField.getText())-Integer.parseInt(textField_2.getText());
            else if(textField_1.getText().equals("*")==true)    
                 n=Integer.parseInt(textField.getText())*Integer.parseInt(textField_2.getText());
            else if(textField_1.getText().equals("/")==true)    
                 n=Integer.parseInt(textField.getText())/Integer.parseInt(textField_2.getText());
            textField_7.setText(String.valueOf(n));
            System.out.print("n"+n);
            
    }
    void set_T_T1_T2_T3()
    {
        
        textField.setText(String.valueOf(rom));
        textField_2.setText(String.valueOf(rom1));
        textField_3.setText(null);
    }
    void set_T_T1_T2_T3_(boolean t)
    {
        
        textField.setEditable(t);
        textField_1.setEditable(t);
        this.textField_2.setEditable(t);
        textField_3.setEditable(t);
    }
    void Set_T8_T10_T11()
    {
        textField_8.setText(String.valueOf(new T_Event().Get_t()));
        textField_10.setText(String.valueOf(new T_Event().Get_f()));
        textField_11.setText(    String.valueOf(   new T_Event().Get_t()    *100  / (new T_Event().Get_f()+new T_Event().Get_t()))+"%");
    }
    void Set_rom_rom1(int x1,int x2)
    {
        rom=r.nextInt(x2-x1)+x1;
         rom1=r.nextInt(x2-x1)+x1;
        
    }
    void Set_T9(String s)
    {
         textField_9.setText(s);
    }
    void Set_Login_l(boolean y)
    {
        l.Set_frame(y);
    }
    
    public JComboBox Get_Com()
    {
        return comboBox;
    }
   
    
    String Get_T3()
    {
        return textField_3.getText();
    }
    int Get_n()
    {
        return n;
    }
    int Get_T()
    {
        return Integer.parseInt(textField.getText());
    }
    int Get_T2()
    {
        return Integer.parseInt(textField_2.getText());
    }
    JButton Get_btnNewButton()
    {
        return btnNewButton;
    }
    JButton Get_btnNewButton_1()
    {
        return btnNewButton_1;
    }
    JButton Get_btnNewButton_2()
    {
        return btnNewButton_2;
    }
    JButton Get_button()
    {
        return button;
    }
    public JFrame Get_frame()
    {
        return this.frame;
    }
    public JTextField Get_T12()
    {
        return textField_12;
    }
    public JButton Get_btnNewButton_4()
    {
        return btnNewButton_4;
    }
    public JTextField Get_T9()
    {
        return textField_9;
    }
    
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        
        frame=new JFrame("小学生四则运算器");
        frame.setTitle("\u5929\u751F\u6211\u6750\u5FC5\u6709\u7528\uFF0C\u52A0\u6CB9\u54E6......");
        frame.setIconImage(Toolkit.getDefaultToolkit().getImage(T.class.getResource("/opar/\u6807\u7B7E.jpg")));
        frame.getContentPane().setBackground(Color.RED);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Dimension screenSize =Toolkit.getDefaultToolkit().getScreenSize();
        frame.setSize(500, 500 );
        frame.setLocation((screenSize.width-500 )/2, (screenSize.height-500)/2);
        frame.getContentPane().setLayout(null);
        
        textField = new JTextField(String.valueOf(rom));
        textField.setEditable(false);
        textField.setBounds(96, 152, 66, 21);
        frame.getContentPane().add(textField);
        textField.setColumns(10);
        
        textField_1 = new JTextField(" +");
        textField_1.setEditable(false);
        textField_1.setBounds(199, 152, 24, 21);
        frame.getContentPane().add(textField_1);
        textField_1.setColumns(10);
        
        textField_2 = new JTextField(String.valueOf(rom1));
        textField_2.setEditable(false);
        textField_2.setBounds(257, 152, 66, 21);
        frame.getContentPane().add(textField_2);
        textField_2.setColumns(10);
      
        
        JLabel lblNewLabel = new JLabel("=");
    
        lblNewLabel.setBounds(348, 152, 24, 15);
        frame.getContentPane().add(lblNewLabel);
        
        textField_3 = new JTextField();
        textField_3.setBounds(379, 152, 66, 21);
        frame.getContentPane().add(textField_3);
        textField_3.setColumns(10);
        textField_3.addKeyListener(new T_Event());
        
        textField_4 = new JTextField(textField.getText());
        textField_4.setEditable(false);
        textField_4.setBounds(96, 198, 66, 21);
        frame.getContentPane().add(textField_4);
        textField_4.setColumns(10);
        
        textField_5 = new JTextField(" +");
        textField_5.setEditable(false);
        textField_5.setBounds(199, 198, 24, 21);
        frame.getContentPane().add(textField_5);
        textField_5.setColumns(10);
        
        textField_6 = new JTextField(textField_2.getText());
        textField_6.setEditable(false);
        textField_6.setBounds(257, 198, 66, 21);
        frame.getContentPane().add(textField_6);
        textField_6.setColumns(10);
        
        label = new JLabel("=");
       
        label.setBounds(348, 198, 24, 15);
        frame.getContentPane().add(label);
        
        textField_7 = new JTextField();
        textField_7.setEditable(false);
        textField_7.setBounds(379, 198, 66, 21);
        frame.getContentPane().add(textField_7);
        textField_7.setColumns(10);
        
        label_1 = new JLabel("\u6B63\u786E\u7B54\u6848");
        label_1.setFont(new Font("宋体", Font.PLAIN, 14));
        label_1.setBounds(10, 200, 66, 15);
        frame.getContentPane().add(label_1);
        
        label_2 = new JLabel("\u8BF7\u89E3\u7B54");
        label_2.setFont(new Font("宋体", Font.PLAIN, 14));
        label_2.setBounds(10, 152, 58, 18);
        frame.getContentPane().add(label_2);
        
        label_3 = new JLabel("\u6B63\u786E\u6570\u76EE");
        label_3.setFont(new Font("宋体", Font.PLAIN, 14));
        label_3.setBounds(12, 245, 66, 15);
        frame.getContentPane().add(label_3);
        
        textField_8 = new JTextField();
        textField_8.setEditable(false);
        textField_8.setBounds(96, 243, 66, 21);
        frame.getContentPane().add(textField_8);
        textField_8.setColumns(10);
        
        label_4 = new JLabel("\u9519\u8BEF\u6570\u76EE");
        label_4.setBounds(189, 246, 54, 15);
        frame.getContentPane().add(label_4);
        
        textField_10 = new JTextField();
        textField_10.setEditable(false);
        textField_10.setBounds(257, 243, 66, 21);
        frame.getContentPane().add(textField_10);
        textField_10.setColumns(10);
        
        JLabel label_5 = new JLabel("\u6B63\u786E\u7387");
        label_5.setBounds(334, 246, 54, 15);
        frame.getContentPane().add(label_5);
        
        textField_11 = new JTextField();
        textField_11.setEditable(false);
        textField_11.setBounds(379, 243, 66, 21);
        frame.getContentPane().add(textField_11);
        textField_11.setColumns(10);
        
        btnNewButton = new JButton("\u7B80\u5355");
        btnNewButton.setBounds(81, 85, 108, 23);
        frame.getContentPane().add(btnNewButton);
        btnNewButton.addActionListener(new T_Event());
        
        btnNewButton_1 = new JButton("\u9002\u4E2D");
        btnNewButton_1.setBounds(209, 85, 109, 23);
        frame.getContentPane().add(btnNewButton_1);
        btnNewButton_1.addActionListener(new T_Event());
        
        btnNewButton_2 = new JButton("\u56F0\u96BE");
        btnNewButton_2.setBounds(336, 85, 109, 23);
        frame.getContentPane().add(btnNewButton_2);
        btnNewButton_2.addActionListener(new T_Event());
        
        button = new JButton("\u9000\u51FA");
        button.setBounds(96, 390, 93, 23);
        frame.getContentPane().add(button);
        button.addActionListener(new T_Event());
        
        button_1 = new JButton("\u52A0\u6CD5");
        button_1.setBounds(64, 39, 93, 23);
        frame.getContentPane().add(button_1);
        button_1.addActionListener(new T_Event());
        
        button_2 = new JButton("\u51CF\u6CD5");
        button_2.setBounds(164, 39, 93, 23);
        frame.getContentPane().add(button_2);
        button_2.addActionListener(new T_Event());
        
        button_3 = new JButton("\u4E58\u6CD5");
        button_3.setBounds(267, 39, 93, 23);
        frame.getContentPane().add(button_3);
        button_3.addActionListener(new T_Event());
        
        
        btnNewButton_3 = new JButton("\u9664\u6CD5");
        btnNewButton_3.setBounds(369, 39, 93, 23);
        frame.getContentPane().add(btnNewButton_3);
        
        textField_9 = new JTextField();
        textField_9.setEditable(false);
        textField_9.setBounds(84, 340, 368, 21);
        frame.getContentPane().add(textField_9);
        textField_9.setColumns(10);
        
        JLabel label_6 = new JLabel("\u53CD\u9988\u6846");
        label_6.setBounds(10, 346, 54, 15);
        frame.getContentPane().add(label_6);
        
        label_7 = new JLabel("\u83DC\u5355\u680F");
        label_7.setFont(new Font("宋体", Font.PLAIN, 14));
        label_7.setBounds(10, 43, 44, 15);
        frame.getContentPane().add(label_7);
        
        lblNewLabel_1 = new JLabel("\u96BE\u4EE5\u7A0B\u5EA6");
        lblNewLabel_1.setFont(new Font("宋体", Font.PLAIN, 14));
        lblNewLabel_1.setBounds(10, 89, 64, 15);
        frame.getContentPane().add(lblNewLabel_1);
        
        comboBox = new JComboBox(Skin);
        comboBox.setBounds(96, 292, 66, 21);
        frame.getContentPane().add(comboBox);
        comboBox.addActionListener(new T_Event());
        
        JLabel lblNewLabel_2 = new JLabel("\u8BBE\u7F6E");
        lblNewLabel_2.setFont(new Font("宋体", Font.PLAIN, 14));
        lblNewLabel_2.setBounds(12, 294, 44, 15);
        frame.getContentPane().add(lblNewLabel_2);
        
        textField_12 = new JTextField();
        textField_12.setBounds(257, 292, 66, 21);
        frame.getContentPane().add(textField_12);
        textField_12.setColumns(10);
        
        
        JLabel label_8 = new JLabel("\u9898\u91CF");
        label_8.setBounds(189, 295, 54, 15);
        frame.getContentPane().add(label_8);
        
         btnNewButton_4 = new JButton("\u518D\u6765\u4E00\u6B21");//再来一次
        
        btnNewButton_4.setBounds(295, 390, 93, 23);
        frame.getContentPane().add(btnNewButton_4);
        btnNewButton_4.addActionListener(new T_Event());
        
        //frame.setVisible(true);//184696141
        btnNewButton_3.addActionListener(new T_Event());
        
        l=new Login();
        l.Set_frame(true);
        
        
        
        
    }
}

 

 

演示过程:

技术分享技术分享技术分享技术分享技术分享技术分享技术分享

收获与感悟:

        (  在这一次结对子小项目中  )

  • 我主要充当领航员的作用,我的同伴充当着驾驶员的作用。
  • 我的同伴主要是对程序进行编码,然后由我来后期调试。
  • 一开始,我们两个分别独立完成一部分,后来发现,彼此的思想很难沟通且达成共识,于是,我们决定在课堂上好好珍惜面对面交流的时间,在课下利用QQ、微信、电话和远程操控的方式来进行深入探讨。
  • 翅膀只剩一边是飞翔不起来的,尽管很努力的飞到半空,也不够双翅滑翔的轻松自如,所以合作真的很重要。在合作中,只有互相交流、交换思想,才会发现自己的优势和不足之处在哪里。因为有了时间的限制,所以有了无形的压力,所以我们更深的领悟到了时间观念的重要性。
  • 我们在完成这次项目的时候,我们彼此改正缺点,彼此进步,得到的一点一滴的努力和进步,都会颇感欣慰。
  • 由于有了同伴的监督,让我不敢偷懒,让我更认真的去查看和更正程序的不足,有了一个方向和目标,让我们更有追求。
  • 当完成程序的所有测试后,很有成就感。
  • 非常期待下一次的结对项目。

结对工作过程:

技术分享

技术分享技术分享

 

---恢复内容结束---

练习2-小学生四则运算系统

标签:

原文地址:http://www.cnblogs.com/ys1101/p/4411052.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!