📄 testword.java
字号:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.util.*;
public class TestWord extends Thread
{
static JFrame f;
static MyPanel p;
static JButton b1,b2,b3;
static JLabel l1,l2;
static JTextField tf;
static JTextField pf;
static String [] testWord;
static String [] testMeaning;
static int m=0,n=0,u=0;
static TestThread tt;
public TestWord(String [] testWord,String [] testMeaning)
{
this.testWord = testWord;
this.testMeaning = testMeaning;
init();
}
static void change(String [] testWord,String [] testMeaning)
{
testWord = testWord;
testMeaning = testMeaning;
}
void init()
{
f = new JFrame("测试");
b2 = new JButton("退出");
b1 = new JButton("确认");
b3 = new JButton("开始");
l1 = new JLabel("英文单词");
l2 = new JLabel("汉语词汇");
tf = new JTextField(20);
pf = new JTextField(20);
p = new MyPanel("image\\blue.jpg");
p.setLayout(new FlowLayout());
f.setContentPane(p);
p.add(l1);
p.add(tf);
p.add(b1);
p.add(l2);
p.add(pf);
p.add(b2);
p.add(b3);
f.setSize(400,150);
b1.setOpaque(false);
b2.setOpaque(false);
b3.setOpaque(false);
l1.setOpaque(false);
l2.setOpaque(false);
b1.setForeground(Color.yellow);
b2.setForeground(Color.yellow);
b3.setForeground(Color.yellow);
l1.setForeground(Color.yellow);
l2.setForeground(Color.yellow);
f.show();
b1.addActionListener(new compare());
b3.addActionListener(new start());
b2.addActionListener(new exit());
System.out.println(ReadDat.wordCount);
System.out.println(m);
System.out.println(n);
}
class compare implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
tt.resume();
}
}
class start implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
tt = new TestThread();
tt.start();
}
}
class exit implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
f.show(false);
// System.exit(0);
}
}
}
/////////////////////////////////////////////////
class TestThread extends Thread
{
public void run()
{
int [] j = new int[ReadDat.wordCount];
Random random = new Random();
int l = 0,x;
for(int m=0;m<ReadDat.wordCount;m++)
{
x = random.nextInt(ReadDat.wordCount);
l = 0;
for(int n=0;n<m;n++)
{
if(x==j[n])l++;
}
if(l==0)j[m]=x;
else m--;
}
for(int i=0;i<ReadDat.wordCount;i++)
{
TestWord.pf.setText(TestWord.testMeaning[j[i]]);
this.suspend();
String getString = new String();
getString = TestWord.tf.getText();
if(TestWord.testWord[j[i]].equals(getString))
{
TestWord.pf.setText("正确");
TestWord.tf.setText("");
TestWord.m++;
}
else
{
TestWord.pf.setText("错误");
TestWord.tf.setText("");
TestWord.n++;
}
try
{
this.sleep(1000);
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
if((TestWord.m+TestWord.n)==ReadDat.wordCount)
{
int o = (int)(((float)TestWord.m/(float)(ReadDat.wordCount))*100);
String ll = java.lang.Float.toString((float)o);
TestWord.pf.setText(ll);
TestWord.tf.setText("你的得分");
TestWord.m = 0;
TestWord.n = 0;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -