添加java_java怎么添加数据并且加入到界面中?

展开全部

我的测试没有任何问题,并且保证随机题不会重复显示 。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;

}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值