2024/9/30日工作日志

news/2024/10/1 0:27:49

完成Java课堂测试;
import javax.swing.;
import java.awt.
;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;

public class Question extends JFrame {
private JPasswordField[] password = new JPasswordField[30];
private int[] answer = new int[30];
private Random rand = new Random();
private double rightnum = 0;
private JLabel timerLabel;
private int timeLeft = 60;
private Timer timer;

public Question() {setTitle("四则运算");setSize(600, 500);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setLocationRelativeTo(null);setLayout(new GridLayout(8, 10)); // Adjust grid size to fit timerint i = 0;int[] x = new int[30];int[] y = new int[30];int[] z = new int[30];while (i < 30) {x[i] = rand.nextInt(90) + 10;y[i] = rand.nextInt(90) + 10;z[i] = rand.nextInt(4);if (z[i] == 0 && judgeSame(x, y, z, i)) { // Additionanswer[i] = x[i] + y[i];add(new JLabel(x[i] + " + " + y[i] + " ="));password[i] = new JPasswordField();password[i].setSize(50,20);add(password[i]);i++;}else if (z[i] == 1 && judgeSame(x, y, z, i)) { // Subtractionif (x[i] >= y[i]) {answer[i] = x[i] - y[i];add(new JLabel(x[i] + " - " + y[i] + " ="));password[i] = new JPasswordField();password[i].setSize(50,20);add(password[i]);i++;}}else if (z[i] == 2 && judgeSame(x, y, z, i)) { // Multiplicationif (x[i] * y[i] < 1000) {answer[i] = x[i] * y[i];add(new JLabel(x[i] + " * " + y[i] + " ="));password[i] = new JPasswordField();add(password[i]);i++;}}else if (z[i] == 3 && judgeSame(x, y, z, i)) {if (y[i] != 0 && (x[i] / y[i]) * y[i] == x[i]) {answer[i] = x[i] / y[i];add(new JLabel(x[i] + " / " + y[i] + " ="));password[i] = new JPasswordField();add(password[i]);i++;}}}JButton confirm = new JButton("查看得分");confirm.addActionListener(e -> {calculateScore();});add(confirm);timerLabel = new JLabel("剩余时间: " + timeLeft + " 秒", SwingConstants.CENTER);add(timerLabel);timer = new Timer(1000, new ActionListener() {public void actionPerformed(ActionEvent e) {timeLeft--;timerLabel.setText("剩余时间: " + timeLeft + " 秒");if (timeLeft <= 0) {timer.stop();disableInputs();calculateScore();}}});timer.start();
}private void disableInputs() {for (JPasswordField pass : password) {pass.setEnabled(false);}
}public boolean judgeSame(int[] x, int[] y, int[] z, int i) {for (int j = 0; j < i; j++) {if (x[i] == x[j] && y[i] == y[j] && z[i] == z[j]) return false;}return true;
}public boolean judgeAnswer(int answer, JPasswordField password) {String a = String.valueOf(answer);return password.getText().equals(a);
}private void calculateScore() {rightnum = 0;for (int i = 0; i < password.length; i++) {if (judgeAnswer(answer[i], password[i])) {rightnum++;}}JOptionPane.showMessageDialog(this, "你的得分是: " + rightnum + "/" + password.length);
}

}

import javax.swing.*;

public class text {
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
Question frame = new Question();
frame.setVisible(true);
});
}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.ryyt.cn/news/66691.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈,一经查实,立即删除!

相关文章

高级语言程序设计第二次个人作业

班级链接:https://edu.cnblogs.com/campus/fzu 作业要求链接:https://edu.cnblogs.com/campus/fzu/2024C/homework/13282 学号:102400130 姓名:杨子旭 章节习题在第四题的时候发现即使代码正确也无法输出正确结果,最后发现是win7系统原因,测试发现在win10的系统可以转为十…

YouTube 注释 All In One

YouTube 注释 All In OneYouTube 注释 All In One old YouTube 批注是在视频上添加文字层,链接或热点。 他们添加了链接到其他网站或视频的交互式框(您想要的任何链接)。https://zh-cn.aiseesoft.com/how-to/add-annotations-to-youtube.html将注释支持带回 YouTube™! 201…

AnimationClip优化工具 - 删除连续相同的帧

下图中Rotation.z的前4个关键帧[0, 3](即15帧, 30帧, 45帧, 60帧),值都没变; (3, 4)Rotation.z变为60(即61帧到90帧); 后3个关键帧[5, 7]一直维持在60没变。可以分析下:前4个关键帧,[1, 2]删除对动画没影响,后3个关键帧[5, 7]删除对动画也没影响。public class AnimC…

实验1 C语言输入输出和简单程序编写

一,实验目的 1. 会使用C语言程序开发环境(vs2010/devc++等),能熟练、正确使用它们编写、编译、运行、调 试C程序 2. 知道C程序结构和编码规范,能正确使用 3. 能正确、熟练使用C语言输入输出函数: scanf() , printf() , getchar() , putchar() 4. 能灵活、组合使用基本数据…

VScode Cmake-tools 部分问题记录

我的 Visual Studio Code 先前一直安装了 cpp-tools 和 cmake-tools。随后,我升级了我的 GCC 环境版本。然而,重新启动 Visual Studio Code 后,旧的 GCC 版本仍保留在工具包中。起初,我以为是 cpp-tools 插件的问题,一直无法解决这个 bug。后来卸载了相关插件后才发现是 c…

数组0.1

一维数组 数组的运用场合 当我们需要涉及的变量特别多,光想名字都要想半天 所以引入数组 Q: (1)在程序中怎样存放100个学生的成绩? (2)定义100个整型变量吗? (3)C语言中的解决方案是……? A: (1)存储学生成绩用整型数组 mark[100]; (2)存储一行文字用字符数组 …

opencascade AIS_WalkDelta、AIS_ViewInputBuffer源码学习工作

opencascade AIS_WalkDelta 前言 运行方法 1. 空构造函数。 AIS_WalkDelta() : myIsDefined(false), myIsJumping(false), myIsCrouching(false), myIsRunning(false) {} 2. 返回平移组件。 const AIS_WalkPart& operator[] (AIS_WalkTranslation thePart) ; 3. 返回平移组…

2023-9-30

标签之文本标签列表标签之有序列表列表标签之无序列表