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

📄 registrationdialog.java

📁 Typing fingers Typing programme
💻 JAVA
字号:
import java.awt.*;
import java.io.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.plaf.*;
import javax.swing.plaf.metal.*;
import java.util.Calendar;
import java.util.Date;

/**	This class shows a registration dialog.The dialog has two options ie allow the users to
*	register or they can select their name from the list if they have already signed in.
*/

class RegistrationDialog extends JDialog{
	LabeledField lf;
	CustomList list;
	private Window win;
	JButton button;
	{
		JDialog.setDefaultLookAndFeelDecorated(true);
		try{	
			MetalLookAndFeel.setCurrentTheme(new StandstoneTheme());
			UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
		}catch(Exception e){System.out.println(e);}
	}
	RegistrationDialog(final Frame f,Window win){
		super(f,"Welcome",true);
		this.win=win;
		Container content=getContentPane();
		content.setLayout(new BorderLayout());
		JPanel p1=new JPanel(new GridLayout(2,0));
		String path=System.getProperty("user.dir");
		p1.add(new ImagePanel(new ImageIcon(path+"/Images/RegistrationInfo.png")));
		p1.add(lf=new LabeledField("Name:(New to the typing tutor)",20,Utilities.ALPHABETIC));
		lf.getTextField().addKeyListener(new KeyAdapter(){
			public void keyTyped(KeyEvent k){
				list.deselect(list.getSelectedIndex());
			}
		});
		String names[]=getNames();
		p1.add(list=new CustomList("Select your name (signed in previously)"));
		list.getList().addItemListener(new ItemListener(){
			public void itemStateChanged(ItemEvent iL){	
				lf.getTextField().setText("");
			}
		});
		for(int i=0;i<names.length;i++)
			list.add(names[i]);
		JPanel p=new JPanel();
		p.add(button=new JButton("Ok"));		
		button.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				String item=list.getSelectedItem();
				if(lf.getText().trim().length()>0){
					UserData user=new UserData(lf.getText());
					user.setRegistrationDate(Calendar.getInstance().getTime());

					MainScreen m=(MainScreen)f;
					m.setCurrentUser(user);
					setVisible(false);
				}
				else if(item!=null){
					UserData user=UserDataIO.readObject(item);
					MainScreen m=(MainScreen)f;
					m.setCurrentUser(user);
					Date date=Calendar.getInstance().getTime();
					if(user.getRegistrationDate().after(date)){
						user.setRegistrationDate(date);
						user.setTypingPeriod(0);
						String s="Your registration date is adjusted";
						setVisible(false);
						new MsgBox(f,s,0);
					}
					else{
						double period=user.getTypingPeriod()/1000;
						String s="You have typed a total of "+(int)period+
							 " seconds$Your typing speed is "+
							  (int)user.getSpeed()+"$with an accuracy"+
							 "of "+(int)user.getAccuracy()+"%."; 						
						setVisible(false);
						new MsgBox(f,s,1);
					}
				}
			}
		});
		content.add(p1,BorderLayout.NORTH);
		content.add(list);
		content.add(p,BorderLayout.SOUTH);
		Dimension screen=Utilities.getScreenSize();
		int w=screen.width;
		int h=screen.height;
		setBounds((w-h/2)/2,(h-w/2)/2,h/2,w/2);
	}
	public String[] getNames(){
		File file=new File(System.getProperty("user.dir"));
		String names[]=file.list(new FilenameFilter(){
			public boolean accept(File f,String s){
				if(s.endsWith(".rizi"))
					return true;
				else
					return false;
			}
		});
		for(int i=0;i<names.length;i++){
			if(names[i].endsWith(".rizi")){
				names[i]=names[i].substring(0,names[i].lastIndexOf(".rizi"));
			}
		}
		return names;
	}
	public void paint(Graphics g){
		super.paint(g);
		try{
			Thread.sleep(1000);
		}catch(Exception e){}
		if(win!=null)
			win.dispose();
	}
}
class CustomList extends JPanel{
	List list;	
	DialogLabel label;
	CustomList(String title){
		setLayout(new BorderLayout());
		add(label=new DialogLabel(title),BorderLayout.NORTH);
		add(list=new List());
	}
	public void add(String s){
		list.add(s);
	}
	public String getSelectedItem(){
		return list.getSelectedItem();
	}
	public void deselect(int index){
		list.deselect(index);
	}
	public int getSelectedIndex(){
		return list.getSelectedIndex();
	}
	public List getList(){
		return list;
	}
}

⌨️ 快捷键说明

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