模拟答题
来源:互联网 发布:《深入浅出数据分析》 编辑:程序博客网 时间:2024/04/29 18:30
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Teacher{
public static void main(String[] args){
ComputerFrame cf = new ComputerFrame();
cf.setVisible(true);
cf.setBounds(100, 100, 660, 130);
cf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
class ComputerFrame extends JFrame {
JButton j1 = new JButton("获取题目");
JButton j2 = new JButton("确认答案");
JTextField t1 = new JTextField(15);
JTextField t2 = new JTextField(15);
JTextField t3 = new JTextField(15);
JLabel l1 = new JLabel("+");
JLabel l2 = new JLabel("=");
JLabel l3 = new JLabel("你还没有回答那");
JPanel p1 = new JPanel(new FlowLayout());
JPanel p2 = new JPanel(new FlowLayout());
public ComputerFrame(){
p2.add(j1);
p2.add(t1);
p2.add(l1);
p2.add(t2);
p2.add(l2);
p2.add(t3);
p1.add(j2);
p1.add(l3);
p2.add(p1);
add(p2,BorderLayout.CENTER);
p2.setBackground(Color.red);
p1.setBackground(Color.green);
j1.addActionListener(new ButtonListener());
j2.addActionListener(new ButtonListener());
}
class ButtonListener implements ActionListener {
int Result = 0;
double d = Math.random() * 30;
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
if(((JButton)arg0.getSource()) == j1) {
t1.setText(String.valueOf(d));
t2.setText(String.valueOf(d));
if((Math.random() * 20) > 100){
l1.setText("-");
}
else if((Math.random() * 20) <= 0){
l1.setText("*");
}
}
if(((JButton)arg0.getSource()) == j2){
if(t3.getText() == String.valueOf(Result)){
l3.setText("回答正确!");
}
else {
l3.setText("回答错误!");
}
}
}
}
}
- 模拟答题
- [NOIP模拟题]答题比赛
- 答题
- 第十一章 类的无参方法 简答题5 模拟竞猜活动
- 答题了
- 在线答题
- 人工答题
- 答题技巧
- 答题-jquery
- 子集---答题
- 答题比赛
- 答题比赛
- 电视答题
- 答题吧官网
- 简答题
- 中招了,答题...
- 天龙八部科举答题器
- POJ答题小结
- 4X99神将X国逆向工程实战
- 国产芯片大全
- ASP.NET调用javascript脚本的常见方法小结
- Google的全球级的分布式数据库Spanner
- ubutun apache源码完整安装过程
- 模拟答题
- Extjs Store 的用法详解
- 信 息 过 滤 技 术
- 无法ping could not establish link
- pl/sql分隔符,运算符,文本书写规范,标识符规范,编码规范
- 手机EVOD参数影响电话呼入
- S 1.2 transform C程序
- windows下进程间通信方式介绍
- 逆转一个整数的二进制表示问题