这是一份有关扫雷的游戏程序源代码说明,源代码分为七个文件,一个主函数,附带六个功能函数,以下分别对六个文件的具体功能进行说明:
使用了SweepMine中的Frame()函数,生成了一个扫雷框架实例
设置了主窗口的大小以及进行了扫雷实例窗口和实际窗口大小比较适应、位置调整
设置了主窗口的默认关闭方式
添加了一个窗口监听器,在里面添加了对按钮的监听以及窗口对应的提示
在其中添加了对record函数的调用,完成对记录的读写
设置面板属性,大小位置、是否可见等属性,并设置了默认的关闭模式
创建了一个Jpanel实例,并且对其的位置、大小等进行设置,然后向面板中添加了三个按钮以及一个文本框
分别设置了三个按钮的功能,分别调用了newgame()函数,restart函数,退出时调用了record的功能函数,对数据进行记录
class Message extends JDialog implements ActionListener, MouseListener,Runnable
public Message(String s)
public void run()
public void sort(String[] str)
public void countWin(String s)
public void noRecord()
public void show(String s)
public void actionPerformed(ActionEvent e)
public void mousePressed(MouseEvent e)
public void mouseClicked(MouseEvent arg0)
public void mouseEntered(MouseEvent arg0)
public void mouseExited(MouseEvent arg0)
public void mouseReleased(MouseEvent arg0)
// Constuct Method
// Add component to pane
//restruct the run method
// read the information of record
// Add component to pane
***Difficult Part**
// range the time of sweeping mines
// Calculate the percent of winning the game
// Judge Record is empty
// Judge Record is not empty
// Check && Confirm
// Reset the statistical information
**************
// The function about Mouse' pressing the RadionButton
// Basis
// Intermediate
// Advance
// Mouse Method restruction Default
构造方法:
FileWriter fw = new FileWriter(String fileName);//创建字符输出流类对象和已存在的文件相关联。文件不存在的话,并创建。
BufferWriter
将文本写入字符输出流,缓冲各个字符,从而提供单个字符、数组和字符串的高效写入。
write
写入数据
close
关掉数据流
异常捕获:
catch (IOException e) {
e.printStackTrace();
class Record
public Record()
public void writeNumber(int level, int i)
public void writeTime(int level, int i)
public void writeLevel(int i)
public void writeLevel4(int row, int column, int mine)
public String readNumber(int level)
public String readLevel()
public String readTime(int level)
public void clear()
public String getTime()
//set a number of the game
// Set the time of Sweeping mine
// record the Difficulty level of Sweeping mine
// set the number of squares and mines when user defines level by itself
// get the number of the game
// read the time of sweeping mine
// Read the level of sweeping mine
// Reading the number of squares
// read mines when user defines level by itself
// Clear every record
// formate the win time
- This is a level setting panel,include the number of the block and mines
- // set 4 radiobuttons add to the button group ,add to the pane
- // set 9 Label ,3 text windows, 2 Button:"confirm' and "cancel",add to the pane
- supplement:we add the user-defined mode to add the fun of game
- supplement: we add the shortcut key function to make the panel more similar likes the game
class Setting extends JDialog implements ActionListener, KeyListener,Runnable
public Setting(SweepMine mine, int level, String s)
public void addPart()
public void actionPerformed(ActionEvent e)
public void run()
public void keyPressed(KeyEvent e)
public void keyReleased(KeyEvent arg0)
public void keyTyped(KeyEvent e)
// Setting the panel font and location
// setting the radiobutton and add to the group and panel
// set the location and actionlistener
// setting the label font\location and add to the panel
//add three textfield to set the hight\width\mine number
//add two button to make the setting coming into force
// Setting the usable the custom bar
// Setting the number of text
// select the level of difficulties
// Cancel Button
// Basis
// Intermediate
// Advance
// User-defined
// monitoring the shortcut key input and make key's function is working