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

📄 dbpractice.java

📁 小键盘指法练习 我是初学者
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
				String textstr=timetext.getText();
				//int sec=Integer.parseInt(textstr);
								
				if(textstr.length()>0)
				{
					seconds=Integer.parseInt(timetext.getText());
					timer.start();
					right=0;total=0;number=0;practicetime=0;
					startpanel.setVisible(false);
					endpanel.setVisible(false);
					helppanel.setVisible(false);
					aboutpanel.setVisible(false);
					practicepanel.setVisible(true);
					for(int i=0;i<5;i++)
					{
						Float figure=random.nextFloat();
						figure*=100;
						String str=String.valueOf(figure);
						str=str.substring(0,str.indexOf(".")+3);
						rlabel[i].setText(str);
					}
					for(int i=0;i<5;i++)
					{
						ftext[i].setText("");
						if(i>0)
						{
							ftext[i].setEditable(false);
						}
					}
					ftext[0].setEditable(true);
					ftext[0].requestFocus();
				}
				
				
			}
			else
			{
				//JButton source=(JButton)(e.getSource());
				String command=e.getActionCommand();
				if(command=="测试")
				{
					seconds=600;
					right=0;total=0;number=0;practicetime=0;
					timer.start();
					startpanel.setVisible(false);
					endpanel.setVisible(false);
					helppanel.setVisible(false);
					aboutpanel.setVisible(false);
					practicepanel.setVisible(true);
					for(int i=0;i<5;i++)
					{
						Float figure=random.nextFloat();
						figure*=100;
						String str=String.valueOf(figure);
						str=str.substring(0,str.indexOf(".")+3);
						rlabel[i].setText(str);
					}
					for(int i=0;i<5;i++)
					{
						ftext[i].setText("");
						if(i>0)
						{
							ftext[i].setEditable(false);
						}
					}
					ftext[0].setEditable(true);
					ftext[0].requestFocus();
				}
				if(command=="练习")
				{
					if((timetext.getText()).length()>0)
					{
						right=0;total=0;number=0;practicetime=0;
						seconds=Integer.parseInt(timetext.getText());
						timer.start();
						startpanel.setVisible(false);
						endpanel.setVisible(false);
						helppanel.setVisible(false);
						aboutpanel.setVisible(false);
						practicepanel.setVisible(true);
						
						for(int i=0;i<5;i++)
						{
							Float figure=random.nextFloat();
							figure*=100;
							String str=String.valueOf(figure);
							str=str.substring(0,str.indexOf(".")+3);
							rlabel[i].setText(str);
						}
					}
					for(int i=0;i<5;i++)
					{
						ftext[i].setText("");
						if(i>0)
						{
							ftext[i].setEditable(false);
						}
					}
					ftext[0].setEditable(true);
					ftext[0].requestFocus();
				}
				if(command=="帮助")
				{
					timer.stop();
					startpanel.setVisible(false);
					endpanel.setVisible(false);
					practicepanel.setVisible(false);
					aboutpanel.setVisible(false);
					helppanel.setVisible(true);
				}
				if(command=="关于")
				{
					timer.stop();
					startpanel.setVisible(false);
					endpanel.setVisible(false);
					practicepanel.setVisible(false);
					helppanel.setVisible(false);
					aboutpanel.setVisible(true);
					
				}
				if(command=="结束")
				{
					timer.stop();
					startpanel.setVisible(false);
					helppanel.setVisible(false);
					aboutpanel.setVisible(false);
					practicepanel.setVisible(false);
					endpanel.setVisible(true);
				}
				if(command=="继续")
				{
					
					endpanel.setVisible(false);
					helppanel.setVisible(false);
					aboutpanel.setVisible(false);
					practicepanel.setVisible(false);
					startpanel.setVisible(true);
					timetext.setText("");
					//startpanel.setFocusable(true);
					timetext.requestFocus(true);
				}
				if(command=="退出")
				{
					System.exit(0);
				}
			}
		}
	}
	private class TEvent implements ActionListener
	{
		public void actionPerformed(ActionEvent ee)
		{
			//long temptime=System.currentTimeMillis();
			Date date=new Date();
			String datestr=date.toString();
			datestr=datestr.substring(11,19);
			overtime=--seconds;
			//practicetime+=1;
			if(overtime<0)
			{
				timer.stop();
				startpanel.setVisible(false);
				practicepanel.setVisible(false);
				aboutpanel.setVisible(false);
				helppanel.setVisible(false);
				endpanel.setVisible(true);
				
			}
			else
			{
				++practicetime;
				overlabel.setText("剩余时间:"+String.valueOf(overtime)+"秒");
				practicelabel.setText("使用时间:"+String.valueOf(practicetime)+"秒");
				endplabel.setText("使用时间:"+String.valueOf(practicetime)+"秒");
				timelabel.setText("系统时间:"+datestr);
				if(practicetime>0)
				{
					int speed=number*60/practicetime;
					speedlabel.setText("速度:"+String.valueOf(speed)+"字/分钟");
					endslabel.setText("速度:"+String.valueOf(speed)+"字/分钟");
					if(speed<80)
					{
						infolabel.setText("太差劲了,赶快练习吧!");
					}
					else if(speed>=80&&speed<120)
					{
						infolabel.setText("水平一般,还需继续努力!");
					}
					else if(speed>=120&&speed<160)
					{
						infolabel.setText("很好,指法不错!");
					}
					else if(speed>=160)
					{
						infolabel.setText("非常好,指法一流!");
					}
					
					
				}
				if(total>0)
				{
					float rate=right*100/total;
					String ratestr=String.valueOf(rate);
					//ratestr=ratestr.substring(0,4);
					ratelabel.setText("准确率:"+ratestr+"%");
					endrlabel.setText("准确率:"+ratestr+"%");
				}
				
				numlabel.setText("击键次数:"+String.valueOf(number));
				endnlabel.setText("击键次数:"+String.valueOf(number));
			}
			
		}
	}
	private class IEvent implements ActionListener
	{
		public void actionPerformed(ActionEvent eee)
		{
			IEvent input=new IEvent();
			for(int i=0;i<4;i++)
			if(eee.getSource()==ftext[i])
			{
				String ftstr=ftext[i].getText();
				if(ftstr.length()>0)
				{
					
					if(ftstr.equals(rlabel[i].getText()))
					{
						++right;
						++total;
						number+=ftstr.length();
					}
					else
					{
						++total;
					}
					ftext[i].setEditable(false);
					ftext[i].setText("");
					rlabel[i].setText("");
					//ftext[i+1].setText(rlabel[i].getText());
					ftext[i+1].setEditable(true);
					ftext[i+1].requestFocus();
				}
				
			}
			if(eee.getSource()==ftext[4])
			{
				if((ftext[4].getText()).length()>0)
				{
					if((ftext[4].getText()).equals(rlabel[4].getText()))
					{
						++right;
						++total;
						number+=(ftext[4].getText()).length();
					}
					else
					{
						++total;
					}
					ftext[4].setEditable(false);
					ftext[4].setText("");
					ftext[0].setEditable(true);
					ftext[0].requestFocus();
					for(int i=0;i<5;i++)
					{
						Float figure=random.nextFloat();
						figure*=100;
						String str=String.valueOf(figure);
						str=str.substring(0,str.indexOf(".")+3);
						rlabel[i].setText(str);
					}
				}
				
				//judgement=true;
				
		
			}
		}
	}
	private class DigitDocument extends PlainDocument
	{
		public void insertString(int offset,String s,AttributeSet a)
		{
			char c=s.charAt(0);
			if(c<='9'&&c>='0')
			{
				try
				{
					super.insertString(offset,s,a);
				}
				catch(BadLocationException eb)
				{
				}
				
			}
		}
	}
	public static void createAndShowGUI()
	{
		JFrame.setDefaultLookAndFeelDecorated(true);
		JFrame frame=new JFrame("指法练习");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		//JMenuBar menubar=new JMenuBar();JMenu menu=new JMenu("123");menubar.add(menu);
		//frame.setJMenuBar(menubar);
		DBPractice demo=new DBPractice();
		frame.setContentPane(demo.createContentPane());
		
		frame.setSize(500,400);
		frame.setResizable(false);
		frame.setVisible(true);
		frame.setLocationRelativeTo(null);
		//container=createContentPane();
		
		
	}
	public static void main(String args[])
	{
		javax.swing.SwingUtilities.invokeLater(new Runnable(){
			public void run()
			{
				createAndShowGUI();
			}
		});
	}
}

⌨️ 快捷键说明

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