展开全部
我的测试没有任何问题,并且保证随机题不会重复显示 。import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
public class Test extends JFrame implements ActionListener {
private JPanel A;
private JTextField B;
private JLabel C1;
private JLabel C2;
private JButton C3;
private JTextField D;
private ArrayList test3;
private Test3 Cur;
Test() {
this.test3 = new ArrayList();
this.test3.add(new Test3("public", "公有的"));
this.test3.add(new Test3("protected", "受保62616964757a686964616fe59b9ee7ad9431333337373633护的"));
this.test3.add(new Test3("private", "私有的"));
this.Cur = Next();
this.setBounds(100, 100, 250, 180);
A = new JPanel();
C1 = new JLabel(this.Cur.Text);
C2 = new JLabel("请输入关键字");
B = new JTextField(5);
C3 = new JButton("确定");
C3.addActionListener(this);
A.add(C1);
A.add(C2);
A.add(C3);
A.add(B);
this.add(A);
this.setVisible(true);
}
public Test3 Next() {
if (test3.size()
return null;
int c = (int) (Math.random() * (test3.size()));
Test3 t = test3.get(c);
test3.remove(c);
return t;
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == C3) {
if(this.Cur==null)
{
JOptionPane.showMessageDialog(this, "结束");
return;
}
if (B.getText().equals(this.Cur.Key)) {
//this.setVisible(false);
JOptionPane.showMessageDialog(this, "正确");
this.Cur = Next();
if(this.Cur==null)
{
JOptionPane.showMessageDialog(this, "结束");
return;
}
C1.setText(this.Cur.Text);
} else {
JOptionPane.showMessageDialog(this, "错误");
}
}
}
public static void main(String[] args) {
new Test();
}
}
class Test2 extends JFrame {
Test2() {
this.setBounds(10, 10, 200, 10);
this.setTitle("回答正确");
this.setAlwaysOnTop(true);
this.setVisible(true);
}
}
class Test3 {
public String Key;
public String Text;
public Test3(String key, String text) {
super();
Key = key;
Text = text;
}
}