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

📄 mainscreen.java

📁 Typing fingers Typing programme
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
import java.awt.*;
import javax.swing.*;
import java.beans.*;
import javax.swing.event.*;
import java.awt.event.*;
import javax.swing.plaf.metal.*;
import javax.swing.plaf.*;
import java.io.*;
/**	This is the class the program starts from.It creates the parent frame adds menus, 
*	listeners, toolbar.Contains methods to provide data to other class.*/

public class MainScreen extends JFrame{

	private UserData currentUser;
	private TempInfo tempInfo;
	private Sound sound;
	public JDesktopPane desktop;
	private static MainScreen instance;
	private CustomMenu cMenu;
	private JMenuBar menuBar;
	public static void main(String args[]){
		JDialog.setDefaultLookAndFeelDecorated(true);
		JFrame.setDefaultLookAndFeelDecorated(true);
		MetalLookAndFeel.setCurrentTheme(new StandstoneTheme());
		try {
			UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
		} catch (Exception ex) {
			System.out.println("error loading metal...");
		}
		new MainScreen();
	}

	MainScreen(){
		super("Typing Fingers");
		Window window=new Window(this);
		Dimension screen=Toolkit.getDefaultToolkit().getScreenSize();
		String path=System.getProperty("user.dir");
		ImageIcon img=new ImageIcon(path+"/images/Logo.png");
		int left=(screen.width-img.getIconWidth())/2;
		int top=(screen.height-img.getIconHeight())/2;
		window.setBounds(left,top,img.getIconWidth(),img.getIconHeight());
		window.setVisible(true);
		try{
			Thread.sleep(100);
		}catch(Exception e){}
		img.paintIcon(window,window.getGraphics(),0,0);
		try{
			Thread.sleep(2000);
		}catch(Exception e){}
		createFrame(window);
	}
	private void createFrame(Window w){
		Dimension screen=Toolkit.getDefaultToolkit().getScreenSize();
		setBounds(0,0,screen.width,screen.height);
		ImageIcon img=new ImageIcon(System.getProperty("user.dir")+"/Images/icon.gif");
		setIconImage(img.getImage());
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		getContentPane().add(desktop=new JDesktopPane());
		instance=this;
		cMenu=new CustomMenu(this);
		menuBar=cMenu.mbar;
		RegistrationDialog rDialog=new RegistrationDialog(this,w);
		setVisible(true);
		rDialog.setVisible(true);
		desktop.putClientProperty("JDesktopPane.dragMode", "outline");
		UIManager.addPropertyChangeListener(new UISwitchListener((JComponent)getRootPane()));
	}
	public static MainScreen getInstance(){
		return instance;
	}
	public void lessonEnded(){
		JInternalFrame frames[]=desktop.getAllFrames();
		InternalFrame frm[]=new InternalFrame[frames.length];
		for(int i=0;i<frames.length;i++){
			frm[i]=(InternalFrame)frames[i];
			frm[i].updateValues();
			frm[i].dispose();
		}
		if(sound!=null){
			sound.stop();
			sound=null;
		}
		new MsgBox(this,"End of lesson. Weldone!",0);
		setJMenuBar(menuBar);
		cMenu.toolbar.enableLesson(true);
		validateTree();
	}
	public void setCurrentUser(UserData u){
		currentUser=u;
		tempInfo=new TempInfo(u);
	}
	public UserData getCurrentUser(){
		return currentUser;
	}
	public void setTempInfo(TempInfo info){
		tempInfo=info;
	}
	public TempInfo getTempInfo(){
		return tempInfo;
	}
	public Sound getMusic(){
		sound=new Sound(currentUser.getBackgroundMusic());
		return sound;
	}
}
class CustomMenu{
	JMenuBar mbar;
	private JDesktopPane desktop;
	private ThemeMenu themeMenu;
	MyToolbar toolbar;
	SpeedGraphFrame speedFrame;
	private MainScreen screen;
	TypingComponent tComponent;
	String path,lesson="";
	private final JFrame f;
	CustomMenu(JFrame f){
		path=System.getProperty("user.dir");
		screen=(MainScreen)f;
		this.f=f;
		desktop=screen.desktop;
		mbar=new JMenuBar();
		mbar.setOpaque(true);
		addFileMenu();
		addLessonsMenu();
		addTestsMenu();
		addQuoteMenu();
		addThemesMenu();
		addHelpMenu();
		f.setJMenuBar(mbar);
		f.getContentPane().add(toolbar=new MyToolbar(),BorderLayout.SOUTH);
	}
	private void addFileMenu(){
		JMenu file=new JMenu("File");
		final JMenuItem open,close,exit;
		file.add(open=new JMenuItem("New/Open..."));
		open.setEnabled(false);
		file.add(close=new JMenuItem("Close"));
		open.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				RegistrationDialog rDialog=new RegistrationDialog(f,null);
				rDialog.setVisible(true);
				close.setEnabled(true);
				open.setEnabled(false);
					mbar.getMenu(1).setEnabled(true);
				toolbar.enableLesson(true);
			}
		});
		close.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent a){
				open.setEnabled(true);
				close.setEnabled(false);
					mbar.getMenu(1).setEnabled(false);
				toolbar.enableLesson(false);
				toolbar.disableStop();
			}
		});
		file.addSeparator();
		file.add(exit=new JMenuItem("Exit"));
		exit.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				System.exit(0);
			}
		});
		mbar.add(file);
	}
	private void addLessonsMenu(){
		JMenu lesson=new JMenu("Lesson");
		JMenu informative=new JMenu("Informative");
		JMenuItem regular,alphaNum,keypad,diskfile;
		JMenuItem celeron,fileCompresion,firewall,islam,lieDetector,vios,virus;
		lesson.add(regular=new JMenuItem("Regular"));
		regular.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				setLesson(getFileText("Regular.txt"));
				showLessonDialog();
			}
		});
		lesson.add(alphaNum=new JMenuItem("Alphabetic and Numeric"));
		alphaNum.setEnabled(false);
		lesson.add(keypad=new JMenuItem("Keypad"));
		keypad.setEnabled(false);
		lesson.add(diskfile=new JMenuItem("Disk File"));
		diskfile.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				String s=getFile();
				if(s!=null){
					setLesson(validateText(s));
					showLessonDialog();
				}
			}
		});
		informative.add(celeron=new JMenuItem("Celeron and Pentium"));
		celeron.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent a){
				setLesson(getFileText(a.getActionCommand()+".txt"));
				showLessonDialog();
			}
		});
		informative.add(fileCompresion=new JMenuItem("FileCompression"));
		fileCompresion.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent a){
				setLesson(getFileText(a.getActionCommand()+".txt"));
				showLessonDialog();
			}
		});
		informative.add(firewall=new JMenuItem("Firewall"));
		firewall.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent a){
				setLesson(getFileText(a.getActionCommand()+".txt"));
				showLessonDialog();
			}
		});
		informative.add(islam=new JMenuItem("Islam"));
		islam.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent a){
				setLesson(getFileText(a.getActionCommand()+".txt"));
				showLessonDialog();
			}
		});
		informative.add(lieDetector=new JMenuItem("LieDetector"));
		lieDetector.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent a){
				setLesson(getFileText(a.getActionCommand()+".txt"));
				showLessonDialog();
			}
		});
		informative.add(vios=new JMenuItem("Vios"));
		vios.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent a){
				setLesson(getFileText(a.getActionCommand()+".txt"));
				showLessonDialog();
			}
		});
		informative.add(virus=new JMenuItem("Virus"));
		virus.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent a){
				setLesson(getFileText(a.getActionCommand()+".txt"));
				showLessonDialog();
			}
		});
		lesson.add(informative);
		mbar.add(lesson);
	}
	private void addTestsMenu(){
		JMenu test=new JMenu("Tests");
		JMenuItem alphabet,allkeys,book,keypad;
		test.add(alphabet=new JMenuItem("Alphabetic"));
		test.add(allkeys=new JMenuItem("All Keys"));
		test.add(book=new JMenuItem("Book File"));
		test.add(keypad=new JMenuItem("Keypad"));
		keypad.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
			}
		});
		mbar.add(test);
		test.setEnabled(false);
	}
	private void addQuoteMenu(){
		JMenu quote=new JMenu("Quote");
		JMenuItem q;
		quote.add(q=new JMenuItem("Quote"));
		q.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent a){
				Quote qot=new Quote();
				MsgBox mBox=new MsgBox(f,qot.getQuote(),0);
			}
		});
		mbar.add(quote);
	}
	public ThemeMenu getThemeMenu(){
		return themeMenu;
	}
	private void addThemesMenu(){
		DefaultMetalTheme[] themes = { new DefaultMetalTheme(),
				new AquaTheme(),
				new ContrastTheme(),
				new GreenTheme(),
				new StandstoneTheme()};
		themeMenu=new ThemeMenu("Theme", themes);
		mbar.add(themeMenu);
	}
	private void addHelpMenu(){
		JMenu help=new JMenu("Help");
		JMenuItem about,topics;
		help.add(topics=new JMenuItem("Help Topics"));
		topics.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent a){
				String path=System.getProperty("user.dir");
				OpenFile of=new OpenFile(path+"/text/Help.txt");
				HelpDialog hd=new HelpDialog(f,of.getFile());
				hd.show();
			}
		});	
		help.add(about=new JMenuItem("About Typing Tutor"));
		about.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent a){
				HelpDialog hd=new HelpDialog(f);
				hd.show();
			}
		});	
		mbar.add(help);
	}
	public void enableMenus(boolean flag){
		int count=mbar.getMenuCount();
		for(int i=0;i<count;i++)

⌨️ 快捷键说明

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