📄 mainscreen.java
字号:
mbar.getMenu(i).setEnabled(flag);
mbar.getMenu(2).setEnabled(false);
MyToolbar toolbar=new MyToolbar();
toolbar.button[2].setEnabled(!flag);
}
public void setLesson(String l){
lesson=l;
}
public String getLesson(){
return lesson;
}
private void showLessonDialog(){
LessonDialog dialog=new LessonDialog(f);
if(!dialog.showDialog()) return ;
int x=dialog.getLessonDuration()*60;
MainScreen screen=(MainScreen)f;
String s=screen.getCurrentUser().getTypingStyle();
f.setCursor(new Cursor(Cursor.WAIT_CURSOR));
if(s.equals("Moving Text")){
MovingText movingText=new MovingText(getLesson(),
showSpeedGraph(x),(KeyboardFrame)showKeyboardFrame());
showTypingFrame(movingText.getFrame());
}
else if(s.equals("Classic")){
LetterChase letterChase=new LetterChase(getLesson(),
showSpeedGraph(x),(KeyboardFrame)showKeyboardFrame());
showTypingFrame(letterChase.getFrame());
}
else{
CharIndicatorMain indicator=new CharIndicatorMain(getLesson(),
showSpeedGraph(x),(KeyboardFrame)showKeyboardFrame());
showTypingFrame(indicator.getFrame());
}
f.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
f.setJMenuBar(null);
toolbar.enableLesson(false);
}
private TypingFrame showTypingFrame(TypingFrame frame){
desktop.add(frame);
Dimension d=Utilities.getTypingFrameSize();
frame.setBounds(5,5,d.width,d.height);
frame.setVisible(true);
speedFrame.setVisible(true);
return frame;
}
private SpeedGraphFrame showSpeedGraph(int seconds){
speedFrame=new SpeedGraphFrame(seconds);
Dimension screen=Utilities.getScreenSize();
desktop.add(speedFrame);
Dimension d=Utilities.getTypingFrameSize();
speedFrame.setBounds(d.width+10,5,Utilities.SPEED_GRAPH_WIDTH,Utilities.SPEED_GRAPH_HEIGHT);
return speedFrame;
}
private InternalFrame showKeyboardFrame(){
KeyboardFrame keyboardFrame=new KeyboardFrame();
desktop.add(keyboardFrame);
Dimension d=Utilities.getTypingFrameSize();
keyboardFrame.setBounds(5,d.height+10,Utilities.KEYBOARD_WIDTH,Utilities.KEYBOARD_HEIGHT);
keyboardFrame.setVisible(true);
return keyboardFrame;
}
private String getFileText(String file){
OpenFile of=new OpenFile(path+"/Text/"+file);
String text=of.getFile();
if(file.equals("Regular.txt")){
MainScreen screen=(MainScreen)f;
UserData user=screen.getCurrentUser();
long words=user.getWords();
if(words>=text.length()) return text;
return text.substring((int)words,text.length());
}
return text;
}
public String getFile(){
FileDialog o=new FileDialog(f,"Typing Fingers",FileDialog.LOAD);
o.show();
String s=o.getDirectory()+o.getFile();
System.out.println(s);
if(s!=null){
OpenFile f=new OpenFile(s);
s=f.getFile();
}
return s;
}
class MyToolbar extends JToolBar implements ActionListener{
Button button[];
String cap[]={"Lesson","Quote","Stop","Info"};
MyToolbar(){
button=new Button[cap.length];
for(int i=0;i<cap.length;i++){
add(button[i]=new Button(cap[i]));
button[i].addActionListener(this);
}
setFloatable(false);
button[2].setEnabled(false);
}
public void actionPerformed(ActionEvent a){
String s=a.getActionCommand();
if(s.equals("Lesson")){
setLesson(getFileText("Regular.txt"));
showLessonDialog();
}
else if(s.equals("Quote")){
Quote q=new Quote();
MsgBox mBox=new MsgBox(f,q.getQuote(),0);
}
else if(s.equals("Info")){
HelpDialog hd=new HelpDialog(f);
hd.show();
}
else if(s.equals("Stop")){
MainScreen.getInstance().lessonEnded();
enableLesson(true);
}
}
public void enableLesson(boolean value){
button[0].setEnabled(value);
button[2].setEnabled(!value);
}
public void disableStop(){
button[2].setEnabled(false);
}
}
public String validateText(String text){
String valid="`~!@#$%^& *()_+[{]}\\|;:'\",<.>/?";
int l=text.length();
String validated="";
char ch;
for(int i=0;i<l;i++){
ch=text.charAt(i);
if((ch>=65&&ch<=90)||(ch>=97&&ch<=122)||(ch>=48&&ch<=57))
validated=validated+ch;
else if(valid.indexOf(ch)!=-1)
validated=validated+ch;
}
return validated;
}
}
class ThemeMenu extends JMenu implements ActionListener{
DefaultMetalTheme themes[];
JRadioButtonMenuItem item[];
public ThemeMenu(String name, DefaultMetalTheme[] themeArray) {
super(name);
themes = themeArray;
item=new JRadioButtonMenuItem[themes.length];
ButtonGroup group = new ButtonGroup();
for (int i = 0; i < themes.length; i++) {
item[i] = new JRadioButtonMenuItem( themes[i].getName() );
group.add(item[i]);
add( item [i]);
item[i].setActionCommand(i+"");
item[i].addActionListener(this);
}
}
public void actionPerformed(ActionEvent e) {
String numStr = e.getActionCommand();
MetalTheme selectedTheme = themes[ Integer.parseInt(numStr) ];
MetalLookAndFeel.setCurrentTheme(selectedTheme);
try {
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
} catch (Exception ex) {
System.out.println("error loading metal...");
}
}
public void selectTheme(String theme){
System.out.println("Theme passed="+theme);
for(int i=0;i<themes.length;i++){
System.out.println(item[i].getText()+" compared with="+theme);
if(item[i].getText().equals(theme)){
item[i].setSelected(true);
break;
}
}
}
}
/** This class receives events whenever a theme is changed.
*/
class UISwitchListener implements PropertyChangeListener {
JComponent componentToSwitch;
public UISwitchListener(JComponent c) {
componentToSwitch = c;
}
public void propertyChange(PropertyChangeEvent e) {
String name = e.getPropertyName();
if (name.equals("lookAndFeel")) {
SwingUtilities.updateComponentTreeUI(componentToSwitch);
componentToSwitch.invalidate();
componentToSwitch.validate();
componentToSwitch.repaint();
}
}
}
/** This class defines colors for the Aqua Theme */
class AquaTheme extends DefaultMetalTheme implements Serializable{
public String getName() { return "Aqua Theme"; }
private final ColorUIResource primary1 = new ColorUIResource(102, 153, 153);
private final ColorUIResource primary2 = new ColorUIResource(128, 192, 192);
private final ColorUIResource primary3 = new ColorUIResource(159, 235, 235);
protected ColorUIResource getPrimary1() { return primary1; }
protected ColorUIResource getPrimary2() { return primary2; }
protected ColorUIResource getPrimary3() { return primary3; }
}
/** This class defines colors for the Contrast Theme */
class ContrastTheme extends DefaultMetalTheme implements Serializable{
public String getName() { return "Contrast"; }
private final ColorUIResource primary1 = new ColorUIResource(0, 0, 0);
private final ColorUIResource primary2 = new ColorUIResource(204, 204, 204);
private final ColorUIResource primary3 = new ColorUIResource(255, 255, 255);
private final ColorUIResource primaryHighlight = new ColorUIResource(102,102,102);
private final ColorUIResource secondary2 = new ColorUIResource(204, 204, 204);
private final ColorUIResource secondary3 = new ColorUIResource(255, 255, 255);
private final ColorUIResource controlHighlight = new ColorUIResource(102,102,102);
protected ColorUIResource getPrimary1() { return primary1; }
protected ColorUIResource getPrimary2() { return primary2; }
protected ColorUIResource getPrimary3() { return primary3; }
public ColorUIResource getPrimaryControlHighlight() { return primaryHighlight;}
protected ColorUIResource getSecondary2() { return secondary2; }
protected ColorUIResource getSecondary3() { return secondary3; }
public ColorUIResource getControlHighlight() { return super.getSecondary3(); }
public ColorUIResource getFocusColor() { return getBlack(); }
public ColorUIResource getTextHighlightColor() { return getBlack(); }
public ColorUIResource getHighlightedTextColor() { return getWhite(); }
public ColorUIResource getMenuSelectedBackground() { return getBlack(); }
public ColorUIResource getMenuSelectedForeground() { return getWhite(); }
public ColorUIResource getAcceleratorForeground() { return getBlack(); }
public ColorUIResource getAcceleratorSelectedForeground() { return getWhite(); }
}
/** This class defines colors for the Default Theme.It is the default theme when a new user
logs on.
*/
class DefaultTheme extends DefaultMetalTheme implements Serializable{
//Highlight Color
//public ColorUIResource getPrimary1(){return new ColorUIResource(25,50,228);}
public ColorUIResource getPrimary2(){return new ColorUIResource(0,135,230);}
//public ColorUIResource getPrimary3(){return new ColorUIResource(28,20,128);}
//public ColorUIResource getSecondary2(){return new ColorUIResource(64,200,128);}
public ColorUIResource getControl(){return new ColorUIResource(120,135,230);}
}
/** This class defines colors for the Green Theme */
class GreenTheme extends DefaultMetalTheme implements Serializable{
public String getName() { return "Emerald"; }
// greenish colors
private final ColorUIResource primary1 = new ColorUIResource(51, 102, 51);
private final ColorUIResource primary2 = new ColorUIResource(102, 153, 102);
private final ColorUIResource primary3 = new ColorUIResource(153, 204, 153);
protected ColorUIResource getPrimary1() { return primary1; }
protected ColorUIResource getPrimary2() { return primary2; }
protected ColorUIResource getPrimary3() { return primary3; }
}
/** This class defines colors for the standstone theme.
*/
class StandstoneTheme extends DefaultMetalTheme implements Serializable{
public String getName() { return "Sandstone"; }
private final ColorUIResource primary1 = new ColorUIResource( 87, 87, 47);
private final ColorUIResource primary2 = new ColorUIResource(159, 151, 111);
private final ColorUIResource primary3 = new ColorUIResource(199, 183, 143);
private final ColorUIResource secondary1 = new ColorUIResource( 111, 111, 111);
private final ColorUIResource secondary2 = new ColorUIResource(159, 159, 159);
private final ColorUIResource secondary3 = new ColorUIResource(231, 215, 183);
protected ColorUIResource getPrimary1() { return primary1; }
protected ColorUIResource getPrimary2() { return primary2; }
protected ColorUIResource getPrimary3() { return primary3; }
protected ColorUIResource getSecondary1() { return secondary1; }
protected ColorUIResource getSecondary2() { return secondary2; }
protected ColorUIResource getSecondary3() { return secondary3; }
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -