📄 wordframe.java
字号:
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.LinkedList;
import javax.swing.*;
public class WordFrame extends JFrame implements ActionListener
{
JMenuBar bar;
JToolBar toolBar;
JLabel scoreLabel;
JButton changeMusic,exit,bookBar;
File file1=new File("Data/英汉互译排行榜.txt"),
file2=new File("Data/近义词训练排行榜.txt"),
file3=new File("Data/反义词训练排行榜.txt");
JMenu fileMenu,helpMenu,musicMenu,sentenceMenu,scoreMenu,英汉互译,
近义词训练;
JMenuItem 反义词训练,结束,关于作者,关于游戏,书签,英汉互译排行榜,
近义词训练排行榜,反义词训练排行榜,保存,英汉互译四级词汇,
英汉互译六级词汇,英汉互译考研词汇,英汉互译雅思词汇,
英汉互译托福词汇,近义词训练四级词汇,近义词训练六级词汇,
近义词训练考研词汇,近义词训练雅思词汇,
近义词训练托福词汇;
JCheckBoxMenuItem 背景音乐,提示音;
Block block[];
ReadWords readWords;
RandomSetWord random;
ShowRecord showRecord;
JPanel pCenter,pNorth;
LinkedList ccc=new LinkedList();
String a[];
int rows=5;
LinkedList list=new LinkedList();
LinkedList rightOrder=new LinkedList();
LinkedList 成绩表=new LinkedList();
ImageIcon icon;
HelpAboutMe meDialog;
HelpAboutGame gameDialog;
BookBar bookSheet;
Music music;
int flag;
int step=1;
Conform conform;
JProgressBar progressBar;
javax.swing.Timer 计时器=null;
int time=0;
Record record;
int num;
File gradeFile=new File("Data/英汉互译排行榜.txt");
public WordFrame(String s)
{
super(s);
progressBar=new JProgressBar(0,120);
progressBar.setStringPainted(false);
计时器=new Timer(1000,this);
bar=new JMenuBar();
fileMenu=new JMenu("文件(G)");
helpMenu=new JMenu("帮助(H)");
musicMenu=new JMenu("音乐(M)");
sentenceMenu=new JMenu("书签(S)");
scoreMenu=new JMenu("英雄榜(C)");
英汉互译=new JMenu("英汉互译");
近义词训练=new JMenu("近义词训练");
反义词训练=new JMenuItem("反义词训练");
英汉互译排行榜=new JMenuItem("英汉互译排行榜");
近义词训练排行榜=new JMenuItem("近义词训练排行榜");
反义词训练排行榜=new JMenuItem("反义词训练排行榜");
保存=new JMenuItem("保存分数");
结束=new JMenuItem("结束");
关于作者=new JMenuItem("关于作者");
关于游戏=new JMenuItem("关于游戏");
书签=new JMenuItem("书签");
英汉互译四级词汇=new JMenuItem("四级词汇");
英汉互译六级词汇=new JMenuItem("六级词汇");
英汉互译考研词汇=new JMenuItem("考研词汇");
英汉互译雅思词汇=new JMenuItem("雅思词汇");
英汉互译托福词汇=new JMenuItem("托福词汇");
近义词训练四级词汇=new JMenuItem("四级词汇");
近义词训练六级词汇=new JMenuItem("六级词汇");
近义词训练考研词汇=new JMenuItem("考研词汇");
近义词训练雅思词汇=new JMenuItem("雅思词汇");
近义词训练托福词汇=new JMenuItem("托福词汇");
背景音乐=new JCheckBoxMenuItem("背景音乐");
提示音=new JCheckBoxMenuItem("提示音");
fileMenu.setMnemonic('G');
helpMenu.setMnemonic('H');
musicMenu.setMnemonic('M');
sentenceMenu.setMnemonic('S');
scoreMenu.setMnemonic('C');
fileMenu.add(英汉互译);
fileMenu.addSeparator();
fileMenu.add(近义词训练);
fileMenu.addSeparator();
fileMenu.add(反义词训练);
fileMenu.addSeparator();
fileMenu.add(结束);
fileMenu.addSeparator();
helpMenu.add(关于作者);
helpMenu.addSeparator();
helpMenu.add(关于游戏);
musicMenu.add(背景音乐);
musicMenu.addSeparator();
musicMenu.add(提示音);
sentenceMenu.add(书签);
scoreMenu.add(英汉互译排行榜);
scoreMenu.addSeparator();
scoreMenu.add(近义词训练排行榜);
scoreMenu.addSeparator();
scoreMenu.add(反义词训练排行榜);
scoreMenu.addSeparator();
scoreMenu.add(保存);
英汉互译.add(英汉互译四级词汇);
英汉互译.add(英汉互译六级词汇);
英汉互译.add(英汉互译考研词汇);
英汉互译.add(英汉互译雅思词汇);
英汉互译.add(英汉互译托福词汇);
近义词训练.add(近义词训练四级词汇);
近义词训练.add(近义词训练六级词汇);
近义词训练.add(近义词训练考研词汇);
近义词训练.add(近义词训练雅思词汇);
近义词训练.add(近义词训练托福词汇);
bar.add(fileMenu);
bar.add(musicMenu);
bar.add(helpMenu);
bar.add(scoreMenu);
bar.add(sentenceMenu);
setJMenuBar(bar);
toolBar=new JToolBar();
scoreLabel=new JLabel("0");
scoreLabel.setHorizontalAlignment(SwingConstants.CENTER);
changeMusic=new JButton("更换背景音乐");
exit=new JButton("提示");
bookBar=new JButton("下一关");
toolBar.add(changeMusic);
toolBar.add(exit);
toolBar.add(bookBar);
pNorth=new JPanel();
pNorth.setLayout(new GridLayout(1,3));
pNorth.add(toolBar);
pNorth.add(progressBar);
pNorth.add(scoreLabel);
英汉互译.addActionListener(this);
近义词训练.addActionListener(this);
反义词训练.addActionListener(this);
exit.addActionListener(this);
结束.addActionListener(this);
关于作者.addActionListener(this);
关于游戏.addActionListener(this);
背景音乐.addActionListener(this);
changeMusic.addActionListener(this);
bookBar.addActionListener(this);
书签.addActionListener(this);
保存.addActionListener(this);
英汉互译排行榜.addActionListener(this);
近义词训练排行榜.addActionListener(this);
反义词训练排行榜.addActionListener(this);
英汉互译四级词汇.addActionListener(this);
英汉互译六级词汇.addActionListener(this);
英汉互译考研词汇.addActionListener(this);
英汉互译雅思词汇.addActionListener(this);
英汉互译托福词汇.addActionListener(this);
近义词训练四级词汇.addActionListener(this);
近义词训练六级词汇.addActionListener(this);
近义词训练考研词汇.addActionListener(this);
近义词训练雅思词汇.addActionListener(this);
近义词训练托福词汇.addActionListener(this);
if(!file1.exists())
{
try{
FileOutputStream out=new FileOutputStream("Data/英汉互译排行榜.txt");
ObjectOutputStream object_out=new ObjectOutputStream(out);
object_out.writeObject(成绩表);
object_out.close();
out.close();
}
catch(IOException e)
{
}
}
if(!file2.exists())
{
try{
FileOutputStream out=new FileOutputStream("Data/近义词训练排行榜.txt");
ObjectOutputStream object_out=new ObjectOutputStream(out);
object_out.writeObject(成绩表);
object_out.close();
out.close();
}
catch(IOException e)
{
}
}
if(!file3.exists())
{
try{
FileOutputStream out=new FileOutputStream("Data/反义词训练排行榜.txt");
ObjectOutputStream object_out=new ObjectOutputStream(out);
object_out.writeObject(成绩表);
object_out.close();
out.close();
}
catch(IOException e)
{
}
}
//icon=new ImageIcon("Images/2.gif");
int index=(int)(Math.random()*7+1);
switch(index)
{
case 1:
icon=new ImageIcon("Images/1.gif");
break;
case 2:
icon=new ImageIcon("Images/2.gif");
break;
case 3:
icon=new ImageIcon("Images/3.gif");
break;
case 4:
icon=new ImageIcon("Images/4.gif");
break;
case 5:
icon=new ImageIcon("Images/5.gif");
break;
case 6:
icon=new ImageIcon("Images/6.gif");
break;
case 7:
icon=new ImageIcon("Images/7.gif");
break;
}
readWords=new ReadWords();
a=readWords.getWords();
random=new RandomSetWord();
pCenter=new JPanel();
pCenter.setLayout(new GridLayout(a.length/rows,rows));
a=random.randomSetwords(a);
block=new Block[a.length];
for(int k=0;k<block.length;k++)
{
block[k]=new Block();
block[k].setMyViewer(new JButton());
JButton bbb=(JButton)block[k].getMyViewer();
bbb.addActionListener(this);
bbb.setIcon(icon);
pCenter.add(bbb);
}
add(pNorth,BorderLayout.NORTH);
add(pCenter,BorderLayout.CENTER);
setBounds(12,23,700,500);
setVisible(true);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
pCenter.validate();
this.validate();
}
public void fraction()
{
scoreLabel.setText(String.valueOf(Integer.parseInt(scoreLabel.getText())+100));
}
public void selectMode(File f)
{
num=5;
over();
flag=30;
a=null;
scoreLabel.setText("0");
rightOrder.clear();
pCenter.removeAll();
readWords.closeRead();
readWords=new ReadWords();
readWords.setLinkFile(f);
a=readWords.getWords();
for(int i=0;i<a.length;i++)
{
rightOrder.add(a[i]);
}
random=new RandomSetWord();
a=random.randomSetwords(a);
block=new Block[a.length];
for(int k=0;k<block.length;k++)
{
block[k]=new Block();
block[k].setMyViewer(new JButton());
JButton bbb=(JButton)block[k].getMyViewer();
ccc.add(bbb);
bbb.addActionListener(this);
bbb.setText(a[k]);
pCenter.add(bbb);
}
begin();
//add(pCenter,BorderLayout.CENTER);
this.validate();
}
public void nextStep()
{
num=5;
flag=30;
a=null;
over();
rightOrder.clear();
pCenter.removeAll();
a=readWords.getWords();
for(int i=0;i<a.length;i++)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -