201771010111 李瑞紅《第十八週學習總結》

一、實驗目的與要求java

(1) 綜合掌握java基本程序結構;git

(2) 綜合掌握java面向對象程序設計特色;編程

(3) 綜合掌握java GUI 程序設計結構;多線程

(4) 綜合掌握java多線程編程模型;併發

(5) 綜合編程練習。app

二、實驗內容和步驟dom

任務1:填寫課程課後調查問卷,網址:https://www.wjx.cn/jq/33108969.aspx。ide

任務2:綜合編程練習工具

練習1:設計一個用戶信息採集程序,要求以下:學習

(1) 用戶信息輸入界面以下圖所示:

(1)用戶點擊提交按鈕時,用戶輸入信息顯示控制檯界面;

(2)用戶點擊重置按鈕後,清空用戶已輸入信息;

(3)點擊窗口關閉,程序退出。

import java.awt.EventQueue;

import javax.swing.JFrame;

public class Mian {
    public static void main(String[] args) {
        EventQueue.invokeLater(() -> {
            DemoJFrame page = new DemoJFrame();
        });
    }
}
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.Window;

public class WinCenter {
    public static void center(Window win){
        Toolkit tkit = Toolkit.getDefaultToolkit();//獲取默認工具包
        Dimension sSize = tkit.getScreenSize();//獲取屏幕的大小
        Dimension wSize = win.getSize();
        if(wSize.height > sSize.height){
            wSize.height = sSize.height;
        }
        if(wSize.width > sSize.width){
            wSize.width = sSize.width;
        }
        win.setLocation((sSize.width - wSize.width)/ 2, (sSize.height - wSize.height)/ 2);//將組件移到新的位置
    }
}
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.Window;

public class WinCenter {
    public static void center(Window win){
        Toolkit tkit = Toolkit.getDefaultToolkit();//獲取默認工具包
        Dimension sSize = tkit.getScreenSize();//獲取屏幕的大小
        Dimension wSize = win.getSize();
        if(wSize.height > sSize.height){
            wSize.height = sSize.height;
        }
        if(wSize.width > sSize.width){
            wSize.width = sSize.width;
        }
        win.setLocation((sSize.width - wSize.width)/ 2, (sSize.height - wSize.height)/ 2);//將組件移到新的位置
    }

實驗結果

 

 

練習2:採用GUI界面設計如下程序:

編制一個程序,將身份證號.txt 中的信息讀入到內存中;

按姓名字典序輸出人員信息;

查詢最大年齡的人員信息;

查詢最小年齡人員信息;

輸入你的年齡,查詢身份證號.txt中年齡與你最近人的姓名、身份證號、年齡、性別和出生地;

查詢人員中是否有你的同鄉。

輸入身份證信息,查詢所提供身份證號的人員信息,要求輸入一個身份證數字時,查詢界面就顯示知足查詢條件的查詢結果,且隨着輸入的數字的增多,查詢匹配的範圍逐漸縮小。

package ID;
import java.awt.*;
import javax.swing.*;

public class ButtonTest {
    public static void main(String[] args) {
        EventQueue.invokeLater(() -> {
            JFrame frame = new Test();
            frame.setTitle("身份證");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
        });
    }
}

 
package ID;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import java.util.Collections;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class Test extends JFrame {
    private static ArrayList<Citizen> citizenlist;
    private static ArrayList<Citizen> list;
    private JPanel panel;
    private JPanel buttonPanel;
    private static final int DEFAULT_WITH = 600;
    private static final int DEFAULT_HEIGHT = 300;

    public Test(){
        citizenlist = new ArrayList<>();
        Scanner scanner = new Scanner(System.in);
        File file = new File("E:/java/身份證號.txt");
        try {
            FileInputStream fis = new FileInputStream(file);
            BufferedReader in = new BufferedReader(new InputStreamReader(fis));
            String temp = null;
            while ((temp = in.readLine()) != null) {

                Scanner linescanner = new Scanner(temp);

                linescanner.useDelimiter(" ");
                String name = linescanner.next();
                String id = linescanner.next();
                String sex = linescanner.next();
                String age = linescanner.next();
                String birthplace = linescanner.nextLine();
                Citizen citizen = new Citizen();
                citizen.setName(name);
                citizen.setId(id);
                citizen.setSex(sex);
                int ag = Integer.parseInt(age);
                citizen.setage(ag);
                citizen.setBirthplace(birthplace);
                citizenlist.add(citizen);

            }
        } catch (FileNotFoundException e) {
            System.out.println("信息文件找不到");
            e.printStackTrace();
        } catch (IOException e) {
            System.out.println("信息文件讀取錯誤");
            e.printStackTrace();
        }
        panel = new JPanel();
        panel.setLayout(new BorderLayout());
        JTextArea jt = new JTextArea();
        panel.add(jt);
        add(panel, BorderLayout.NORTH);
        buttonPanel = new JPanel();
        buttonPanel.setLayout(new GridLayout(1, 7));
        JButton jButton = new JButton("按姓名字典序輸出人員信息");
        JButton jButton1 = new JButton("查詢年齡最大和年齡最小的人員");
        JLabel lab = new JLabel("查詢是否有你的老鄉");
        JTextField jt1 = new JTextField();
        JLabel lab1 = new JLabel("查找年齡與你相近的人:");
        JTextField jt2 = new JTextField();
        JLabel lab2 = new JLabel("輸入你的身份證號碼:");
        JTextField jt3 = new JTextField();
        JButton jButton2 = new JButton("退出");
        jButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                Collections.sort(citizenlist);
                jt.setText(citizenlist.toString());
            }
        });
        jButton1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                int max = 0, min = 100;
                int j, k1 = 0, k2 = 0;
                for (int i = 1; i < citizenlist.size(); i++) {
                    j = citizenlist.get(i).getage();
                    if (j > max) {
                        max = j;
                        k1 = i;
                    }
                    if (j < min) {
                        min = j;
                        k2 = i;
                    }

                }
                jt.setText("年齡最大:" + citizenlist.get(k1) + "年齡最小:" + citizenlist.get(k2));
            }
        });
        jButton2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                dispose();
                System.exit(0);
            }
        });
        jt1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                String find = jt1.getText();
                String text="";
                String place = find.substring(0, 3);
                for (int i = 0; i < citizenlist.size(); i++) {
                    if (citizenlist.get(i).getBirthplace().substring(1, 4).equals(place)) {
                        text+="\n"+citizenlist.get(i);
                        jt.setText("老鄉:" + text);
                    }
                }
            }
        });
        jt2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                String yourage = jt2.getText();
                int a = Integer.parseInt(yourage);
                int near = agenear(a);
                int value = a - citizenlist.get(near).getage();
                jt.setText("年齡相近:" + citizenlist.get(near));
            }
        });
        jt3.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                list = new ArrayList<>();
                Collections.sort(citizenlist);
                String key = jt3.getText();
                for (int i = 1; i < citizenlist.size(); i++) {
                    if (citizenlist.get(i).getId().contains(key)) {                        
                        list.add(citizenlist.get(i));                        
                        jt.setText("emmm!你多是:\n" + list);
                    }                    
                }
            }
        });
        buttonPanel.add(jButton);
        buttonPanel.add(jButton1);
        buttonPanel.add(lab);
        buttonPanel.add(jt1);
        buttonPanel.add(lab1);
        buttonPanel.add(jt2);
        buttonPanel.add(lab2);
        buttonPanel.add(jt3);
        buttonPanel.add(jButton2);
        add(buttonPanel, BorderLayout.SOUTH);
        setSize(DEFAULT_WITH, DEFAULT_HEIGHT);
    }

    public static int agenear(int age) {
        int min = 53, value = 0, k = 0;
        for (int i = 0; i < citizenlist.size(); i++) {
            value = citizenlist.get(i).getage() - age;
            if (value < 0)
                value = -value;
            if (value < min) {
                min = value;
                k = i;
            }
        }
        return k;
    }

}

 
package ID;
public class Citizen implements Comparable<Citizen> {

    private String name;
    private String id;
    private String sex;
    private int age;
    private String birthplace;
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public int getage() {
        return age;
    }

    public void setage(int age) {
        this.age = age;
    }

    public String getBirthplace() {
        return birthplace;
    }

    public void setBirthplace(String birthplace) {
        this.birthplace = birthplace;
    }

    public int compareTo(Citizen other) {
        return this.name.compareTo(other.getName());
    }

    public String toString() {
        return name + "\t" + sex + "\t" + age + "\t" + id + "\t" + birthplace + "\n";
    }
}

 

練習3:採用GUI界面設計如下程序

編寫一個計算器類,能夠完成加、減、乘、除的操做

利用計算機類,設計一個小學生100之內數的四則運算練習程序,由計算機隨機產生10道加減乘除練習題,學生輸入答案,由程序檢查答案是否正確,每道題正確計10分,錯誤不計分,10道題測試結束後給出測試總分;

將程序中測試練習題及學生答題結果輸出到文件,文件名爲test.txt。

package project4;

public class Main {

    public static void main(String[] args) {
        MyExGUI lg = new MyExGUI();
        // new MyExGUI();

    }

}
package project4;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.ArrayList;
import java.util.Random;

import javax.swing.JFrame;

public class chart extends JFrame {
    // 繪製柱形統計圖
    ArrayList<Integer> ran = new ArrayList<Integer>();

    public chart(ArrayList<Integer> scores) {
        super();
        getContentPane().setForeground(Color.CYAN);
        setForeground(Color.CYAN);
        setBackground(Color.CYAN);
        for (int i = 0; i < scores.size(); i++) {
            ran.add(scores.get(i));
            System.out.println(scores.get(i));
        }

        setTitle("繪製柱形圖");
        setSize(600, 400);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    @Override
    public void paint(Graphics g) {
        int Width = getWidth();
        int Height = getHeight();
        int leftMargin = 20;// 柱形圖左邊界
        int topMargin = 50;// 柱形圖上邊界
        Graphics2D g2 = (Graphics2D) g;
        g2.setColor(Color.WHITE);// 繪製白色背景
        g2.fillRect(0, 0, Width, Height - 100);// 繪製矩形圖
        g2.setColor(Color.black);
        for (int i = 0; i <= 10; i++) {
            // 繪製灰色橫線和百分比
            g2.drawString((100 - 10 * i) + " ", 15, topMargin + 30 * i);
            g2.drawLine(10, topMargin + 30 * i, Width, topMargin + 30 * i);// 繪製灰色橫線
        }
        g2.setColor(Color.RED);
        for (int i = 0; i <= ran.size(); i++) {
            // 繪製柱形圖
            int step = (i + 1) * 40;// 設置每一個柱形圖的水平間隔爲40
            // 繪製矩形
            g2.fillRoundRect(leftMargin + step * 2 - 5, (100 - ran.get(i)) * 3 + 50, 40, 300 - (100 - ran.get(i)) * 3,
                    40, 10);
            // 列出測試輪數
            g2.drawString("" + (i + 1) + "", leftMargin + step * 2, 380);
        }
    }

}
package project4;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;

public class arithmetic {
    ArrayList<String> list = new ArrayList<String>();
    ArrayList<String> list_timu = new ArrayList<String>();
    ArrayList<String> list_answer = new ArrayList<String>();

    public arithmetic() {
        FileOutputStream outSTr = null;
        BufferedOutputStream Buff = null;
        int number_n = 10, count;

        ArrayList<String> list_temp = new ArrayList<String>();
        String[] operator = new String[] { "+", "-", "*", "/" };

        Random rand = new Random();
        File file1 = new File("D:\\test.txt");
        if (file1.exists()) {
            // 建立文件
            try {
                file1.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        while (number_n > 0) {
            int[] number_temp = new int[rand.nextInt(2) + 3];
            String[] str_temp = new String[number_temp.length - 1];
            for (int i = 0; i < number_temp.length; i++) {
                if (i < number_temp.length - 1) {
                    number_temp[i] = rand.nextInt(100);
                    list_temp.add(String.valueOf(number_temp[i]));
                    str_temp[i] = operator[rand.nextInt(4)];
                    list_temp.add(str_temp[i]);

                }

                else {
                    number_temp[i] = rand.nextInt(100);
                    list_temp.add(String.valueOf(number_temp[i]));
                }
            }

            count = calculate_RPN(produce_RPN(list_temp));
            if (count != -1) {
                list_timu.add(transform_string(list_temp));
                list_answer.add(String.valueOf(count));
                list_temp.add(" = " + count);
                list.add(transform_string(list_temp));
                number_n--;
                list_temp.clear();
            } else
                list_temp.clear();
            System.out.println(number_n);

        }
        try {
            outSTr = new FileOutputStream(file1);
            Buff = new BufferedOutputStream(outSTr);
            for (int i = 0; i < list.size(); i++) {
                try {
                    Buff.write(list.get(i).getBytes());
                    Buff.write("\r\n".getBytes());
                } catch (IOException e) {
                    e.printStackTrace();
                    i--;
                }
            }
            Buff.flush();
            Buff.close();

        } catch (IOException e) {
            e.printStackTrace();
        }
        // Buff.close();
        try {
            outSTr.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i));
            System.out.println();
        }
        System.out.print("計算完畢!");

    }

    public static int calculate_RPN(ArrayList<String> list_temp) {
        int i = 0, t;
        double a = 0, b = 0;
        String l_temp;
        Stack sk = new Stack(10);
        for (t = 0; t < list_temp.size(); t++) {
            l_temp = list_temp.get(i++);
            if (!isInteger(l_temp)) {
                b = sk.mypop();
                a = sk.mypop();
                switch (l_temp) {
                case "+":
                    sk.mypush(a + b);
                    break;
                case "-":
                    if (!(a < b)) {
                        sk.mypush(a - b);
                    } else
                        return -1;
                    break;
                case "*":
                    sk.mypush(a * b);
                    break;
                case "/":
                    if (b == 0 || a < b)
                        return -1;
                    sk.mypush(a / b);
                    break;
                }
                System.out.println("st.mytop: " + sk.mypeek());
            } else {
                sk.mypush((double) Integer.parseInt(l_temp));
            }

        }
        if (!sk.myisempty()) {
            a = sk.mypop();
            b = a - (int) a;
            System.out.println("a:  " + a);
            if (a > 0 && b == 0) {
                return (int) a;
            } else
                return -1;
        } else
            return -1;

    }

    public static ArrayList<String> produce_RPN(ArrayList<String> list_temp) {
        int t = 0, i = 0;
        String tmp;
        Tack mytack = new Tack(10);
        ArrayList<String> lt_temp = new ArrayList<String>();
        while (true) {
            tmp = list_temp.get(i++);
            if (isInteger(tmp)) {
                lt_temp.add(tmp);
            } else {
                if (mytack.myisempty()) {
                    mytack.mypush(tmp);
                }

                else {
                    if (isCPriority(tmp, mytack.mypeek()))
                        mytack.mypush(tmp);
                    else {
                        lt_temp.add(mytack.mypop());
                        mytack.mypush(tmp);
                    }

                }
            }
            if (i >= list_temp.size()) {
                while (!mytack.myisempty())
                    lt_temp.add(mytack.mypop());
                System.out.println(transform_string(list_temp));
                list_temp = lt_temp;
                System.out.println(list_temp);
                return list_temp;
            }
        }

    }

    public static boolean isInteger(String str) {
        for (int i = str.length(); --i >= 0;) {
            if (!Character.isDigit(str.charAt(i))) {
                return false;
            }
        }
        return true;
    }

    public static boolean isCPriority(String str, String s) {
        if ((str + s).equals("*+") || (str + s).equals("*-") || (str + s).equals("/+") || (str + s).equals("/-"))
            return true;
        else
            return false;
    }

    public static String transform_string(ArrayList<String> list_temp) {
        String s = "";
        for (int i = 0; i < list_temp.size(); i++) {
            s += list_temp.get(i);
        }
        return s;

    }

    static class Stack {
        int mytop;
        double stk[];

        public Stack(int num) {
            mytop = -1;
            stk = new double[num];
        }

        /* 出棧 */
        double mypop() {
            double peek = stk[mytop];
            mytop--;
            return peek;
        }

        /* 入棧 */
        void mypush(double x) {
            mytop++;
            stk[mytop] = x;

        }

        /* 判空 */
        Boolean myisempty() {
            if (mytop == -1)
                return true;
            else
                return false;
        }

        /* 取棧頂元素 */
        double mypeek() {
            double peek = stk[mytop];
            return peek;
        }

        /* 棧大小 */
        int mysize() {
            return mytop + 1;
        }
    }

    static class Tack {
        int mytop;
        String tk[];

        public Tack(int num) {
            mytop = -1;
            tk = new String[num];
        }

        /* 出棧 */
        String mypop() {
            String peek = tk[mytop];
            mytop--;
            return peek;
        }

        /* 入棧 */
        void mypush(String x) {
            mytop++;
            tk[mytop] = x;

        }

        /* 判空 */
        Boolean myisempty() {
            if (mytop == -1)
                return true;
            else
                return false;
        }

        /* 取棧頂元素 */
        String mypeek() {
            String peek = tk[mytop];
            return peek;
        }

        /* 棧大小 */
        int mysize() {
            return mytop + 1;
        }

    }

}
package project4;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;

import javax.swing.*;

public class MyExGUI extends JFrame {
    ArrayList<String> user_zongti = new ArrayList<String>();
    ArrayList<String> user_zonganswer = new ArrayList<String>();
    ArrayList<String> user_answer = new ArrayList<String>();
    ArrayList<String> true_answer = new ArrayList<String>();
    ArrayList<String> jta_timu = new ArrayList<String>();
    ArrayList<String> jta_zong = new ArrayList<String>();
    ArrayList<Integer> user_fenshu = new ArrayList<Integer>();
    JMenuBar jm; // 菜單條組件
    JMenu menu;// 菜單
    JMenuItem item1, item2;// 菜單項
    JMenu build; // 二級菜單
    JMenuItem file, project;
    TextArea answer_all = new TextArea();
    TextField jta = new TextField();
    TextField jta_answer = new TextField();
    JLabel num_answer = new JLabel();
    JLabel answer;
    JToolBar jtb;// 工具條
    JButton jb1, jb2, jb3, jb4, jb5, jb6, jb7, jb_next;
    int answer_count;
    int answer_fenshu;

    public MyExGUI() {
        // 建立菜單
        jm = new JMenuBar();

        menu = new JMenu("文件(F)");
        menu.setMnemonic('f'); // 助記符

        build = new JMenu("新建");

        file = new JMenuItem("文件");
        project = new JMenuItem("答題");
        item1 = new JMenuItem("保存(S)");
        item2 = new JMenuItem("退出");

        answer = new JLabel("第 1 題");

        // 添加菜單項至菜單上
        build.add(file);
        build.add(project);

        menu.add(build);
        menu.add(item1);
        menu.add(item2);
        menu.addSeparator();
        // 將菜單加入至菜單欄
        jm.add(menu);

        JPanel contentPanel = new JPanel();
        contentPanel.setLayout(null);
        JLabel daan = new JLabel("答案");
        JLabel dengyu = new JLabel("=");
        num_answer = answer;
        num_answer.setFont(new Font("宋體", Font.BOLD, 22));
        jb_next = new JButton("下一題");
        jta.setFont(new Font("宋體", Font.BOLD, 22));
        jta_answer.setFont(new Font("宋體", Font.BOLD, 22));
        jb_next.setFont(new Font("宋體", Font.BOLD, 22));
        daan.setFont(new Font("宋體", Font.BOLD, 22));
        dengyu.setFont(new Font("宋體", Font.BOLD, 22));

        contentPanel.add(num_answer);
        contentPanel.add(daan);
        contentPanel.add(dengyu);
        contentPanel.add(jta);

        contentPanel.add(jta_answer);
        contentPanel.add(answer_all);
        contentPanel.add(jb_next);

        num_answer.setBounds(90, 20, 130, 50);
        daan.setBounds(250, 20, 90, 50);
        jta.setBounds(50, 70, 150, 30);
        dengyu.setBounds(205, 70, 20, 20);
        jta_answer.setBounds(230, 70, 100, 30);
        jb_next.setBounds(350, 70, 110, 30);
        answer_all.setBounds(50, 120, 400, 300);

        this.setJMenuBar(jm); // 添加菜單欄,不能設定位置,會自動放在最上部
        this.add(contentPanel);

        this.setTitle("在線答題系統");
        this.setSize(600, 500);
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        item1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                FileOutputStream outSTr = null;
                BufferedOutputStream Buff = null;
                boolean flag = true;
                File file;
                // String test ;
                do {
                    // test = "test"+count;

                    String inputValue = JOptionPane.showInputDialog("Please input file name");
                    file = new File(inputValue + "test.txt");
                    if (!file.exists()) {
                        // 建立文件
                        try {

                            flag = file.createNewFile();

                        } catch (IOException e) {
                            e.printStackTrace();

                        }
                        flag = false;
                    } else {

                        JOptionPane.showMessageDialog(null, "該文件名已存在,請從新輸入", "ERROR", JOptionPane.ERROR_MESSAGE);
                        flag = true;
                    }
                } while (flag);
                // 寫入文件
                String u_answer;
                try {
                    outSTr = new FileOutputStream(file);
                    Buff = new BufferedOutputStream(outSTr);
                    System.out.println("選擇是後執行的代碼" + user_zongti.size() + user_answer.size());
                    for (int i = 0; i < user_zongti.size(); i++) {
                        try {
                            Buff.write(user_zongti.get(i).getBytes());
                            Buff.write("    ".getBytes());
                            u_answer = user_answer.get(i);
                            if (u_answer.equals(""))
                                u_answer = "沒有做答";

                            Buff.write(u_answer.getBytes());
                            Buff.write("\r\n".getBytes());
                        } catch (IOException e) {
                            e.printStackTrace();
                            i--;
                        }
                    }
                    Buff.flush();
                    Buff.close();

                } catch (IOException e) {
                    e.printStackTrace();
                }
                try {
                    outSTr.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                user_zongti.clear();
                user_answer.clear();
            }
        });

        project.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                arithmetic art = new arithmetic();
                true_answer = art.list_answer;
                jta_timu = art.list_timu;
                jta_zong = art.list;
                answer_count = 1;
                answer_all.setText("");
                for (int i = 0; i < art.list_timu.size(); i++) {
                    user_zongti.add(jta_zong.get(i));
                    answer_all.append(jta_timu.get(i));
                    answer_all.append("\r\n");
                }
                num_answer.setText("" + answer_count + "");
                jta.setText(jta_timu.get(answer_count - 1));
                answer_count++;

            }
        });
        jb_next.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                String temp;
                temp = jta_answer.getText();

                if (jta.getText().equals("")) {
                    JOptionPane.showMessageDialog(null, "錯誤,請導入題庫", "錯誤", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                jta_answer.setText("");
                if (answer_count <= 10) {
                    if (isInteger(temp)) {

                        user_answer.add(temp);
                        System.out.println("選擇否後執行的代碼" + temp + "user_size" + user_answer.size());
                        num_answer.setText("" + answer_count + "");
                        jta.setText(jta_timu.get(answer_count - 1));
                        answer_count++;
                    } else {
                        JOptionPane.showMessageDialog(null, "錯誤", "請輸入數字", JOptionPane.ERROR_MESSAGE);
                    }
                } else {
                    user_answer.add(temp);
                    System.out.println("選擇否後執行的代碼" + temp + "user_size" + user_answer.size());
                    answer_fenshu = 0;
                    for (int i = 0; i < user_answer.size(); i++) {
                        if (user_answer.get(i).equals(true_answer.get(i)))
                            answer_fenshu += 5;
                    }
                    user_fenshu.add(answer_fenshu);
                    Object[] options = { "", "取消" };
                    int res = JOptionPane.showOptionDialog(null, "是否查當作績", "答題完畢", JOptionPane.DEFAULT_OPTION,
                            JOptionPane.YES_NO_OPTION, null, options, options[0]);
                    if (res == JOptionPane.YES_OPTION) {
                        chart ct = new chart(user_fenshu);
                        ct.setVisible(true);

                    } else {
                        Object[] option = { "", "取消" };
                        int res1 = JOptionPane.showOptionDialog(null, "是否退出程序", "終止框", JOptionPane.DEFAULT_OPTION,
                                JOptionPane.YES_NO_OPTION, null, option, option[0]);

                        if (res1 == JOptionPane.YES_OPTION) {
                            dispose();
                            System.exit(0);

                        } else {

                        }

                    }

                }

            }
        });

        item2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                dispose();
                System.exit(0);
            }
        });

    }

    public static boolean isInteger(String str) {
        for (int i = str.length(); --i >= 0;) {
            if (!Character.isDigit(str.charAt(i))) {
                return false;
            }
        }
        return true;
    }

}

任務3:本學期課程已結束,請彙總《面向對象程序設計課程學習進度條》的數據,統計我的專業能力提高的數據。並從學習內容、學習方法、學習心得幾個方面進行課程學習總結,也但願你對課程的不足提出建議和意見。

 學習內容:

Java語言特色與開發環境配置(第1章、第2章)

Java基本程序結構(第3章)

Java面向對象程序結構(第4章、第5章、第6章)

 類、類間關係、類圖

Java JDK預約義類/接口及其API(String-第3章、 Arrays-第3章、Files-第3章62頁、LocalDate-第4章、 Object-第5章、對象包裝器-第5章、Comparator-第6章、 異常類-第7章、ArrayList-第5+8章、第9章、第10-12章、 第14章)    

Java異常處理編程模型    

Java GUI編程模型

Java併發程序設計(第14章)

 Java應用程序部署(第13章) 

學習方法:

課堂上老師講授知識、課下自主學習

理論課:課前自主學習,經過觀看視頻和看書相結合的方法,老師總結知識,解除疑惑

實驗課:經過閱讀並運行示例程序學習。和理論知識結合起來做興應當更改。課後完成老師不知道實驗做業

經過老師提供分享的資料自主學習,遇到的問題找老師或助教學長解決。

學習心得:

經過本學期的學習,掌握了java的一些基本知識,對java有了必定的深刻了解,可是在實際問題的解決當中依然有問題。老師和學長還介紹了Java在將來的學習方向和發展,往後仍是頗有必要更深刻更熟練的去學習運用Java知識,感謝老師和助教學長一學期的悉心教導,幫助我完成了java學習的任務。在這一學期的學習中我也收穫了不少。助教學長是咱們的良師益友,不少知識學長一演示咱們就有點明白了,比直接用課本講授更容易讓人接受。

相關文章
相關標籤/搜索