⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 veiwpanel.java

📁 能测试前后两次相同词语的选择是否一样
💻 JAVA
字号:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
import java.sql.*;
import java.util.Vector.*;
import java.awt.Label.*;

public class VeiwPanel
{
	public static void main(String args[])
	{
		UI vp = new UI();
		vp.inital();
	}
}

class UI  extends Thread implements  ActionListener 
{
	private JFrame  frame;
	private Dialog log1;

	private Connection con;
	private Statement stmt;
	private Dialog log2;
	private Dialog log3;
	
	private Dialog log4;
	private boolean first;
	
	private ResultSet rs;
//	private Vector words;
	
	private static Integer count;
	
	public void inital()
	{
		frame = new JFrame("词语记忆器"); 

		first = true;
	//	this.connectDB();
	//	this.readDB();
		count = 0;
		this.showIntroduce();
		this.firstTest();
		this.secondTest();
	//	this.showCount();
		
		
		
		
		frame.addWindowListener(new WindowAdapter()
		{
			public void windowClosing(WindowEvent e)
			{
				System.exit(0);
			}
		});
		frame.setSize(400,300);
		frame.setVisible(true);
	}
	
	public  void showIntroduce()
	{
		if (log1 != null)
		{
			log1.dispose();
		}
		log1 =new Dialog(frame);
		
		log1.setLayout(new BorderLayout());
		Label title = new Label("内容简介");
		title.setFont(new Font("Impact",Font.PLAIN,20));
		
		Label contain =new Label("\t\t这是一个关于反应速度的测验,请尽可能快而准确的做出反应。在每次测验中,屏幕上首先呈现'READY'单词 ,然后屏幕上将呈现一个词语,1秒后词语消失,接下来屏幕上显示一句话 :" +
		  "这个词是形容你的吗?是按yes,否按no。从单词呈现到被测反应时间间隔作为反应时记录,测试将在5秒后开始");
		log1.add(title,"North");
		log1.add(contain,"Center");
		
		Button button1 = new Button("OK");
		log1.add(button1,"South");
		button1.addActionListener(this);

	
	}
	
	public void actionPerformed(ActionEvent et)
	{
		log1.dispose();
	}
	
	public void connectDB()
	{
		try{
			
			Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
			con=java.sql.DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;User=sa;Password=1111;DatabaseName=word"     );
			stmt=con.createStatement();			

		}catch(Exception e)
		{
			e.printStackTrace();
			System.out.println(".....")	;
		}
	}
	
	
	public Vector getReadDB()
	{
	 	Vector<Word1> words = new Vector<Word1>(10,10);
	 //	words.capacityIncrement();
		Word1 wd;
		connectDB();
		try{
			
			if(first)
				rs = stmt.executeQuery("select *  from table1");
			else
				rs = stmt.executeQuery("select *  from table2");
			while(rs.next())
			{
				wd = new Word1(
					rs.getInt(1),
					rs.getString(2).trim(),
					rs.getString(3).trim()
						
				);
				words.addElement(wd);
			}
			
		}catch(Exception e)
		{
			e.printStackTrace();
		}
		return words;
	}
	
	
	
	public void firstTest()
	{
		log2 = new Dialog(frame);
		Label title = new Label("测试内容");
		title.setFont(new Font("Impact",Font.PLAIN,20));
		
		Label lab = new Label("这个词是用来形容你的吗?");
		TextField tf = new TextField(10);
		
		Frame f1 = new Frame();
		Label l1;
		
		Button b1 = new Button("Yes");
		Button b2 = new Button("No");

		Word1 word;
	//	readDB();
		
		Vector words = getReadDB();
		int n = words.size();
		
		for(int i = 0 ; i<n ;i++)
		{
			word = (Word1)words.elementAt(n);
			tf.setText(word.getName());
		
			
				b1.addActionListener(new ActionListener()
					{ 
						public void actionPerformed(ActionEvent e)
						{
							try{
								stmt.executeUpdate("Updata tabel1 set testResult="+"yes");
								}catch(Exception et)
								{
									et.printStackTrace();
								//	System.out.println(".....")	;
								}
						}
					});
	
				b2.addActionListener(new ActionListener()
					{
						public void actionPerformed(ActionEvent e)
						{
							try{
							stmt.executeUpdate("Updata tabel2 set testResult="+"no");
							}catch(Exception et)
							{
								et.printStackTrace();
							}
						}
					});	
				if(i==n-1)		
				{
					
					l1 = new Label("第一组测试完毕");
					f1.add(l1);
					f1.setSize(200,150);
					f1.setVisible(true);
					f1.addWindowListener(new WindowAdapter()
					{
						public void windowClosing(WindowEvent e)
						{
							System.exit(0);
						}
					});
					
					
				 log2.dispose();	
				 first = false;
				}
				Thread thread =	new Thread(this);
				thread.start();
			
			}
		
		log2.add(title);
		log2.add(lab);
		log2.add(tf);
		log2.add(b1);
		log2.add(b2);		
	}
	
	public void secondTest()
	{
		log3 = new Dialog(frame);
		Label title = new Label("测试内容");
		title.setFont(new Font("Impact",Font.PLAIN,20));
		Label lab = new Label("这个词是用来形容你的吗?");
		TextField tf = new TextField(10);
		
		Frame f1 = new Frame();;
		Label l1;
		
		Button b1 = new Button("Yes");
		Button b2 = new Button("No");
		Word1 word;
		
		Vector words = getReadDB();
		int n = words.size();
		//Iterator it = (Iterator)words;
		for(int i=0;i<n;i++)
		{
			
			word = (Word1)words.elementAt(n);
			tf.setText(word.getName());
				b1.addActionListener(new ActionListener()
					{
						public void actionPerformed(ActionEvent e)
						{
							try{
								stmt.executeUpdate("Updata tabel2 set testResult ="+" yes");
							}catch(Exception et)
							{
								et.printStackTrace();
							}
						}
					});
	
				b2.addActionListener(new ActionListener()
					{
						public void actionPerformed(ActionEvent e)
						{
							try{
								stmt.executeUpdate("Updata tabel2 set testResult ="+" no");
							}catch(Exception et)
							{
								et.printStackTrace();
							}
						}
					});	
				
				try{
					rs = stmt.executeQuery("select "+word.getName()+"  from tabel1");
				}catch(Exception et)
				{
					et.printStackTrace();
				}
				
				try{
					if (rs.getString(1).trim()!=null)	
					{
					//	String s = stmt.executeQuery("select testResult from tabel1 where name="+word.getName());
						String s;
						
							s = stmt.executeQuery("select testResult from tabel1 where name="+word.getName()).getString(1).trim();
						
						
						if (s.equals(word.getName()))
						{
							count++;
						}
					}
					}catch(Exception et)
					{
						et.printStackTrace();
					}
			
				if(i==n-1)		
				{
					
					l1 = new Label("第二组测试完毕");
					f1.add(l1);
					f1.setSize(200,150);
					f1.setVisible(true);
					f1.addWindowListener(new WindowAdapter()
					{
						public void windowClosing(WindowEvent e)
						{
							System.exit(0);
						}
					});
					log3.dispose();
					showCount();
				}
				
				Thread thread =	new Thread(this);
				thread.start();
					
		}
		log3.add(title);
		log3.add(lab);
		log3.add(tf);
		log3.add(b1);
		log3.add(b2);
		
	}
	

	
	public void run()
	{
		try{
			
			Thread.sleep(1000);
			
		}catch(Exception e)
		{
			e.printStackTrace();
		}
	}
	
	
	public void showCount()
	{
		log4 = new Dialog(frame);
		Label title = new Label("您的分数为");
		title.setFont(new Font("Impact",Font.PLAIN,20));
		Label lab = new Label(count.toString());
		log4.add(title);
		log4.add(lab);
	}
	

}



class Word1
{
	private  int  id;
	private  String  name;
	private  String  testResult;
	
	public  Word1 (int id,String name,String s)
	{
		this.id=id;
		this.name=name;
		testResult = s;
	}
	
	public String getName()
	{
		return name;
	}
	
	public void setTestResult(String s)
	{
		testResult = s;
	}
 	
 	public String getTestResult()
 	{
 		return testResult;
 	}
 	
}


















⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -