课程设计报告实验内容:综合课程设计相关课程: Java程序设计学期: 2009-2010学年第2学期学时学分: 48学时 3学分专业班级: xxxxxxxx学号: xxxxxxxxxxx 姓名: xxxxxxx 指导老师: xxx 提交日期: xxxx年 xx月xx日题目JAVA课程设计一、实验目的通过课程设计,主要要达到两个目的,一是检验和巩固专业知识、二是提高综合素质和能力。
信科0821班学生的课程设计主要是Java语言程序设计的实现。
通过该课程设计,可以将学生课堂上掌握的理论知识与处理数据的业务相结合,以检验我们同学们掌握知识的宽度、深度及对知识的综合运用能力。
二、实验环境硬件环境CPU:AMD5000+ 双核主板:华硕M2N-X 显示器:1024x768/256色操作系统:Windows XP;JDK:jdk-6u18-windows-i586;运行环境以及调试软件:JCreator Pro三、实验内容内容一:设计一个计算器,利用它可以进行简单的四则运算(加、减、乘、除、开方)等,但仅限于十进制下,此外还可以进行(八进制,十进制,十六进制)之间的相互转换。
内容二:设计一个记事本,菜单中要求有文件,编辑,和帮助。
文件中有新建、打开、保存和退出;编辑中有剪切、复制和粘贴;帮助中显示开发人和版本信息。
内容三:编写tic-tac-toe游戏程序。
即 3*3的9个方格子,每人下一次看谁先连成一行3个四、算法分析、设计与描述1.算法分析和设计内容(1)算法分析:首先,设计对输入数字的进行转换,不进行转换操作则默认为十进制,然后进行符号转换操作以及正弦函数等,接着可以进行加减乘除等运算,添加“C”、“CE”按钮进行退格和清空操作,清空操作显示“0”,最后在帮助中显示开发人信息。
功能及界面设计:功能1:按下数字键在液晶平上会显示数字,这时计算器最基本的功能。
功能2:输入数字后,点击进制转换,可转换成二、八进制;按“exp”“log”键,则进行e次幂运算和自然对数运算;按“tan”“cos”“sin”则进行三角函数运算。
功能3:按“+”“-”“*”“/”分别进行四则运算功能4:在任何时候按下“+/-”键,计算器文本框上的数字置反号。
功能5:第一次按下“运算”键,再按下数字键,将重新输入第二个数字。
再次按下“运算”键,将算出前两个数字运算的结果,然后按下数字,将又重新输入新的数字。
功能6:按下“C”键向前退格,按下“C E”键,数据被全部清除功能7:按下“帮助”键查看制作人信息功能8:按下“选项”键,点“退出”键退出计算器面板设计算法描述选项进制转换帮助(输出区域)sqrt +/- exp C CE 7 8 9 log / 4 5 6 tan * 1 2 3 cos - 0 . = sin +内容(2)算法分析:此程序应当符合大众化,因为记事本是一个常用程序,因此我们常用计算机系统带的记事本进行设计本程序,其功能有以下几个方面:(1)“菜单”中有“文件”,“编辑”,“帮助”三个主菜单。
(2)“文件”中有“新建”,“打开”,“保存”,“退出”四个子菜单:分别用于新建文件,打开文件,保存文件,退出记事本。
(3)“编辑”中有“剪切”,“复制”,“粘贴”三个子菜单:用于剪切文字,复制文字,粘贴文字。
(4)“帮助”菜单中有“关于”用来显示作者信息计算结果显示接受用户输入是否再次计算退出是否处理异常默认十进制 十六进制八进制开始选择你要计算运行的进制10、8、16进制转换刷新记事本面板设计:文件编辑帮助(文本区)内容(3)算法分析:1初始化游戏,2检查棋子是否布满游戏格局,格局被布满则进行赢者判断,没布满则“X”下棋,3再次检查游戏格局是否被棋子布满,没布满则轮到“O”下棋,且跳到步骤2,若布满格局则进行赢者判断算法描叙:五、程序设计1.程序设计的基本思路 内容(1):计算结果显示区设计private JTextField displayField 保存+,-,*,/,=命令private String lastCommand 保存计算结果private double result 判断是否为数字的开始 private boolean start设置布局、为按钮注册事件监听器 public Calculator()是否占满游戏格局初始化游戏平局是否有玩家赢是否占满游戏输出赢家“O ”下棋“X ”下棋YYNNNY是否有玩家赢NY调用成员方法添加菜单this.addmyMenu()按钮的单击事件处理方法public void actionPerformed(ActionEvent e)退格键的实现方法if(input.equals("C")) {if(str.length()>0)displayField.setText(str.substring(0,str.length()-1)); // 清零键的实现方法input.equals("CE")displayField.setText("0");start=true;内容(2):使用的包如下:import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.*;为按钮添加行为监听器: ActionListener为按钮添加键盘适配器:KeyListener菜单设计:JMenuBar mbar;JMenu mnuFile, mnuEdit, mnuHelp;JMenuItem fileNew, fileOpen, fileSave, fileExit;JMenuItem editCut, editCopy, editPaste, editSelectAll, editDel;JMenuItem helpAbout;JToolBar tlbr;ImageIcon iconNew, iconOpen, iconSave;ImageIcon iconCut, iconCopy, iconPaste;JButton bttnNew, bttnOpen, bttnSave;JButton bttnCut, bttnCopy, bttnPaste;打开异常处理:catch(Exception ex){JOptionPane.showMessageDialog(this,ex.getMessage(),"打开失败",JOptionPane.ERROR_MESSAGE);}退出异常处理:if(txtChanged){int res;res = JOptionPane.showConfirmDialog(this,"保存更改?","退出",JOptionPane.YES_NO_CANCEL_OPTION);if(res == JOptionPane.YES_OPTION){saveFile();}else if(res == JOptionPane.CANCEL_OPTION){return;}内容(3)创建并且初始化盘区单位private char whoseTurn = 'X';创建并且初始化状态标签private Cell[][] cells = new Cell[3][3];private JLabel jlblStatus = new JLabel("X's turn to play");确认玩家顺序public TicTacToe() {JPanel p = new JPanel(new GridLayout(3, 3, 0, 0));for (int i = 0; i < 3; i++)for (int j = 0; j < 3; j++)p.add(cells[i][j] = new Cell());判断盘区单位全部是否被棋子占领public boolean isFull() {for (int i = 0; i < 3; i++)for (int j = 0; j < 3; j++)if (cells[i][j].getToken() == ' ')return false;return true;}判断有指定的象征的玩家胜利public boolean isWon(char token) {for (int i = 0; i < 3; i++)if ((cells[i][0].getToken() == token)&& (cells[i][1].getToken() == token)&& (cells[i][2].getToken() == token)) { return true;}for (int j = 0; j < 3; j++)if ((cells[0][j].getToken() == token)&& (cells[1][j].getToken() == token)&& (cells[2][j].getToken() == token)) { return true;}if ((cells[0][0].getToken() == token)&& (cells[1][1].getToken() == token)&& (cells[2][2].getToken() == token)) { return true;}if ((cells[0][2].getToken() == token)&& (cells[1][1].getToken() == token)&& (cells[2][0].getToken() == token)) { return true;}return false;}2.程序代码内容(1):import java.awt.*;import java.awt.event.*;import javax.swing.*;public class Calculator extends Frame implements ActionListener, WindowListener{private Container container;private GridBagLayout layout;private GridBagConstraints constraints;private JTextField displayField; //计算结果显示区private String lastCommand; //保存+,-,*,/,=命令0private double result; //保存计算结果private boolean start; //判断是否为数字的开始private JMenuBar menubar;private JMenuItem m_exit,m2_ejz,m2_bjz;private Dialog dialog;private Label label_dialog;private JButton button_sqrt,button_plusminus,button_CE,button_cancel,button_1,button_2 ,button_3,button_4,button_5,button_6,button_7,button_8,button_9,button_ 0,button_plus,button_minus,button_multiply,button_divide,button_poin t,button_equal,button_log,button_tan,button_cos,button_sin,button_ex p;public Calculator() //构造方法设置布局、为按钮注册事件监听器{super("Calculator");this.setLocation(240,200);this.setSize(350,300);this.setResizable(true);this.setLayout(new GridLayout(7,1));this.addmyMenu(); //调用成员方法添加菜单displayField=new JTextField(30);this.add(displayField);displayField.setEditable(true);start=true;result=0;lastCommand = "=";JPanel panel0=new JPanel();panel0.setLayout(new GridLayout(1,4,4,4));JPanel panel1=new JPanel();panel1.setLayout(new GridLayout(1,5,4,4));this.add(panel1);button_sqrt=new JButton("sqrt");button_plusminus=new JButton("+/-");button_exp=new JButton("exp");button_CE=new JButton("C");button_cancel=new JButton("CE");JPanel panel2=new JPanel();panel2.setLayout(new GridLayout(1,5,4,4));this.add(panel2);button_7=new JButton("7");button_8=new JButton("8");button_9=new JButton("9");button_log=new JButton("log");button_divide=new JButton("/");JPanel panel3=new JPanel();panel3.setLayout(new GridLayout(1,5,4,4));this.add(panel3);button_4=new JButton("4");button_5=new JButton("5");button_6=new JButton("6");button_tan=new JButton("tan");button_multiply=new JButton("*");JPanel panel4=new JPanel();panel4.setLayout(new GridLayout(1,5,4,4));this.add(panel4);button_1=new JButton("1");button_2=new JButton("2");button_3=new JButton("3");button_cos=new JButton("cos");button_minus=new JButton("-");JPanel panel5=new JPanel();panel5.setLayout(new GridLayout(1,5,4,4));this.add(panel5);button_0=new JButton("0");button_point=new JButton(".");button_equal=new JButton("=");button_sin=new JButton("sin");button_plus=new JButton("+");panel1.add(button_sqrt);panel1.add(button_plusminus);panel1.add(button_exp);panel1.add(button_CE);panel1.add(button_cancel);panel2.add(button_7);panel2.add(button_8);panel2.add(button_9);panel2.add(button_log);panel2.add(button_divide);panel3.add(button_4);panel3.add(button_5);panel3.add(button_6);panel3.add(button_tan);panel3.add(button_multiply);panel4.add(button_1);panel4.add(button_2);panel4.add(button_3);panel4.add(button_cos);panel4.add(button_minus);panel5.add(button_0);panel5.add(button_point);panel5.add(button_equal);panel5.add(button_sin);panel5.add(button_plus);button_sqrt.addActionListener(this);button_plusminus.addActionListener(this);button_exp.addActionListener(this);button_CE.addActionListener(this);button_cancel.addActionListener(this);button_7.addActionListener(this);button_8.addActionListener(this);button_9.addActionListener(this);button_log.addActionListener(this);button_divide.addActionListener(this);button_4.addActionListener(this);button_5.addActionListener(this);button_6.addActionListener(this);button_tan.addActionListener(this);button_multiply.addActionListener(this);button_1.addActionListener(this);button_2.addActionListener(this);button_3.addActionListener(this);button_cos.addActionListener(this);button_minus.addActionListener(this);button_0.addActionListener(this);button_point.addActionListener(this);button_equal.addActionListener(this);button_sin.addActionListener(this);button_plus.addActionListener(this);this.addWindowListener(new WinClose()); //注册窗口监听器this.setVisible(true);}private void addmyMenu() //菜单的添加{JMenuBar menubar=new JMenuBar();this.add(menubar);JMenu m1=new JMenu("选项");JMenu m2=new JMenu("进制转换");JMenuItem m1_exit=new JMenuItem("退出");m1_exit.addActionListener(this);JMenuItem m2_ejz=new JMenuItem("二进制");m2_ejz.addActionListener(this);JMenuItem m2_bjz=new JMenuItem("八进制");m2_bjz.addActionListener(this);JMenu m3 = new JMenu(" 帮助");JMenuItem m3_Help = new JMenuItem("作者");m3_Help.addActionListener(this);dialog = new Dialog(this,"关于",true); //模式窗口 dialog.setSize(240,80);label_dialog = new Label("",Label.CENTER); //标签的字符串为空,居中对齐dialog.add(label_dialog);dialog.addWindowListener(this); //为对话框注册窗口事件监听器m1.add(m1_exit);menubar.add(m1);m2.add(m2_ejz);m2.add(m2_bjz);menubar.add(m2);m3.add(m3_Help);menubar.add(m3); }public void actionPerformed(ActionEvent e) //按钮的单击事件处理方法{if(e.getSource().equals(button_1)||e.getSource().equals(button_2)||e.getSource().equals(button_3)||e.getSource().equals(button_4)||e.getSource().equals(button_5)|| e.getSource().equals(button_6)||e.getSource().equals(button_7)|| e.getSource().equals(button_8)||e.getSource().equals(button_9) ||e.getSource().equals(button_0)||e.getSource().equals(button_point)||e.getSource().equals(button_pl usminus)||e.getSource().equals(button_cancel)||e.getSource().equals(button_C E)){ //非运算符的处理方法String input=e.getActionCommand();if (start){displayField.setText("");start=false;if(input.equals("+/-"))displayField.setText(displayField.getText()+"-");}if(!input.equals("+/-")){String str=displayField.getText();if(input.equals("C")) //退格键的实现方法{if(str.length()>0)displayField.setText(str.substring(0,str.length()-1));}else if(input.equals("CE")) //清零键的实现方法{displayField.setText("0");start=true;}elsedisplayField.setText(displayField.getText()+input);}}else if (e.getActionCommand()=="二进制") //二进制的转换{int n=Integer.parseInt(displayField.getText());displayField.setText(Integer.toBinaryString(n));}else if (e.getActionCommand()=="八进制") //八进制的转换{int n=Integer.parseInt(displayField.getText());displayField.setText(Integer.toOctalString(n));}else if (e.getActionCommand()=="退出") //选项中退出的处理方法{System.exit(0);}else if (e.getActionCommand()=="作者") //按下'帮助'菜单栏中用法的处理方法{label_dialog.setText("熊瑛琪制作 \n学号:080320618");dialog.setLocation(400,250);dialog.setVisible(true);}else //各运算符的识别{String command=e.getActionCommand();if(start){lastCommand=command;}else{calculate(Double.parseDouble(displayField.getText()));lastCommand=command;start=true;}}}public void calculate(double x) //各运算符的具体运算方法{double d=0;if (lastCommand.equals("+"))result+= x;else if (lastCommand.equals("-"))result-=x;else if (lastCommand.equals("*"))result*=x;else if (lastCommand.equals("/"))result/=x;else if (lastCommand.equals("="))result=x;else if (lastCommand.equals("sqrt")){d=Math.sqrt(x);result=d;}else if (lastCommand.equals("exp")){d=Math.exp(x);result=d;}else if (lastCommand.equals("log")){d=Math.log(x);result=d;}else if (lastCommand.equals("tan")){d=Math.tan(x);result=d;}else if (lastCommand.equals("cos")){d=Math.cos(x);result=d;}else if (lastCommand.equals("sin")){d=Math.sin(x);result=d;displayField.setText(""+ result);}public void windowClosing(WindowEvent e){if(e.getSource()==dialog)dialog.setVisible(false); //隐藏对话框elseSystem.exit(0);}public void windowOpened(WindowEvent e) { }public void windowActivated(WindowEvent e) { }public void windowDeactivated(WindowEvent e) { }public void windowClosed(WindowEvent e) { }public void windowIconified(WindowEvent e) { }public void windowDeiconified(WindowEvent e) { }public static void main(String args[]){Calculator calculator=new Calculator();}}class WinClose implements WindowListener{public void windowClosing(WindowEvent e) //单击窗口关闭按钮时触发并执行实现窗口监听器接口{System.exit(0); //结束程序运行}public void windowOpened(WindowEvent e){}public void windowActivated(WindowEvent e){}public void windowDeactivated(WindowEvent e){}public void windowClosed(WindowEvent e){}public void windowIconified(WindowEvent e){}public void windowDeiconified(WindowEvent e){}}内容(2):import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.*;class MyPad extends JFrame implements ActionListener, KeyListener {boolean txtChanged = false;String fname = "";JMenuBar mbar;JMenu mnuFile, mnuEdit, mnuHelp;JMenuItem fileNew, fileOpen, fileSave, fileExit;JMenuItem editCut, editCopy, editPaste, editSelectAll, editDel; JMenuItem helpAbout;JToolBar tlbr;ImageIcon iconNew, iconOpen, iconSave;ImageIcon iconCut, iconCopy, iconPaste;JButton bttnNew, bttnOpen, bttnSave;JButton bttnCut, bttnCopy, bttnPaste;JTextArea txtPad;Container c;MyPad(){initComponents();setTitle("MyPad");setSize(400,300);setVisible(true);setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); addWindowListener(new WinHandler());}void initComponents(){c = getContentPane();c.setLayout(new BorderLayout());initMenu();txtPad = new JTextArea();Font f = new Font("Comic Sans MS", Font.PLAIN, 20);txtPad.setFont(f);txtPad.addKeyListener(this);JScrollPane jscroll = new JScrollPane(txtPad);c.add(jscroll, BorderLayout.CENTER);}void initMenu(){mbar = new JMenuBar();mnuFile = new JMenu("文件");mnuEdit = new JMenu("编辑");mnuHelp= new JMenu("帮助");fileNew = new JMenuItem("新建");fileOpen= new JMenuItem("打开");fileSave= new JMenuItem("保存");fileExit = new JMenuItem("退出");editCut = new JMenuItem("剪切");editCopy= new JMenuItem("复制");editPaste = new JMenuItem("黏贴");editSelectAll = new JMenuItem("全选");editDel= new JMenuItem("删除");helpAbout= new JMenuItem("关于");mnuFile.add(fileNew);mnuFile.add(fileOpen);mnuFile.add(fileSave);mnuFile.add(fileExit);mnuEdit.add(editCut);mnuEdit.add(editCopy);mnuEdit.add(editPaste);mnuEdit.addSeparator();mnuEdit.add(editSelectAll);mnuEdit.add(editDel);mnuHelp.add(helpAbout);mbar.add(mnuFile);mbar.add(mnuEdit);mbar.add(mnuHelp);setJMenuBar(mbar);fileNew.addActionListener(this);fileOpen.addActionListener(this);fileSave.addActionListener(this);fileExit.addActionListener(this);editCut.addActionListener(this);editCopy.addActionListener(this);editPaste.addActionListener(this);editSelectAll.addActionListener(this);editDel.addActionListener(this);helpAbout.addActionListener(this);}public void actionPerformed(ActionEvent e){Object src = e.getSource();if(src.equals(bttnNew) || src.equals(fileNew)){newFile();}else if(src.equals(bttnOpen) || src.equals(fileOpen)) {openFile();}else if(src.equals(bttnSave) || src.equals(fileSave)) {saveFile();}else if(src.equals(fileExit)){exitFile();}else if(src.equals(bttnCut) || src.equals(editCut)) {txtPad.cut();}else if(src.equals(bttnCopy) || src.equals(editCopy)) {txtPad.copy();}else if(src.equals(bttnPaste) || src.equals(editPaste)) {txtPad.paste();}else if(src.equals(editSelectAll)){txtPad.selectAll();}else if(src.equals(editDel)){txtPad.replaceSelection("");}else if(src.equals(helpAbout)){aboutHelp();}}void newFile(){if(txtChanged){int res;res = JOptionPane.showConfirmDialog(this,"保存修改?","新建文件",JOptionPane.YES_NO_CANCEL_OPTION);if(res == JOptionPane.YES_OPTION){saveFile();}else if(res == JOptionPane.CANCEL_OPTION){return;}}fname = "";txtChanged = false;txtPad.setText("");}void saveFile(){if(fname.equals("")){JFileChooser jfc = new JFileChooser();int res;res = jfc.showSaveDialog(this);if(res == jfc.APPROVE_OPTION){fname = jfc.getSelectedFile().getAbsolutePath(); }else{return;}}try{FileWriter fw = new FileWriter(fname);fw.write(txtPad.getText());fw.flush();fw.close();txtChanged = false;}catch(Exception ex){JOptionPane.showMessageDialog(this,ex.getMessage(),"保存失败",JOptionPane.ERROR_MESSAGE);}}void openFile(){int res;JFileChooser jfc = new JFileChooser("c:/");res = jfc.showOpenDialog(this);if(res == jfc.APPROVE_OPTION){fname = jfc.getSelectedFile().getAbsolutePath();try{FileReader fr = new FileReader(fname); BufferedReader br = new BufferedReader(fr);txtPad.setText("");String s;while( (s = br.readLine()) != null ){txtPad.append(s);txtPad.append("\n");}br.close();fr.close();}catch(Exception ex){JOptionPane.showMessageDialog(this,ex.getMessage(),"打开失败",JOptionPane.ERROR_MESSAGE);}}}void exitFile(){if(txtChanged){int res;res = JOptionPane.showConfirmDialog(this,"保存更改?","退出",JOptionPane.YES_NO_CANCEL_OPTION);if(res == JOptionPane.YES_OPTION){saveFile();}else if(res == JOptionPane.CANCEL_OPTION) {return;}}dispose();}void aboutHelp(){new HelpDlg(this);}public void keyPressed(KeyEvent e){}public void keyReleased(KeyEvent e){}public void keyTyped(KeyEvent e){txtChanged = true;}class WinHandler extends WindowAdapter {public void windowClosing(WindowEvent e) {exitFile();}}public static void main(String args[]) {MyPad mp = new MyPad();}}class HelpDlg extends JDialog{public HelpDlg(MyPad m){JOptionPane.showOptionDialog(null,"程序名称:\n MyPad \n" +"程序设计:\n 熊瑛琪 \n","制作人",JOptionPane.DEFAULT_OPTION,RMATION_MESSAGE,null, null, null);setDefaultCloseOperation(DISPOSE_ON_CLOSE);}}内容(3):import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.border.LineBorder;public class TicTacToe extends JApplet {// 表明哪个玩家的顺序,最初它是X玩家private char whoseTurn = 'X';// 创建并且初始化盘区单位private Cell[][] cells = new Cell[3][3];// 创建并且初始化状态标签private JLabel jlblStatus = new JLabel("X's turn to play");public TicTacToe() {// 利用p来确认玩家顺序JPanel p = new JPanel(new GridLayout(3, 3, 0, 0));for (int i = 0; i < 3; i++)for (int j = 0; j < 3; j++)p.add(cells[i][j] = new Cell());// 设置在单位盘区和状态标签的边界线p.setBorder(new LineBorder(Color.red, 1));jlblStatus.setBorder(new LineBorder(Color.yellow, 1));// 安置盘区和标签的附属程序add(p, BorderLayout.CENTER);add(jlblStatus, BorderLayout.SOUTH);}/** 确定盘区单位全部是否被占领 **/public boolean isFull() {for (int i = 0; i < 3; i++)for (int j = 0; j < 3; j++)if (cells[i][j].getToken() == ' ')return false;return true;}/** 判断有指定的象征的玩家胜利 **/public boolean isWon(char token) {for (int i = 0; i < 3; i++)if ((cells[i][0].getToken() == token)&& (cells[i][1].getToken() == token)&& (cells[i][2].getToken() == token)) {return true;}for (int j = 0; j < 3; j++)if ((cells[0][j].getToken() == token)&& (cells[1][j].getToken() == token)&& (cells[2][j].getToken() == token)) {return true;}if ((cells[0][0].getToken() == token)&& (cells[1][1].getToken() == token)&& (cells[2][2].getToken() == token)) {return true;}if ((cells[0][2].getToken() == token)&& (cells[1][1].getToken() == token)&& (cells[2][0].getToken() == token)) {return true;}return false;}// 单位区的类public class Cell extends JPanel {// 单位区域象征private char token = ' ';public Cell() {setBorder(new LineBorder(Color.black, 1)); // 设置单位区的颜色addMouseListener(new MouseListener()); // 注册计数器}/** 单位区的返回 **/public char getToken() {return token;}/** 设置一个新的象征 */public void setToken(char c) {token = c;repaint();}/** 设置单位区域 */protected void paintComponent(Graphics g) {super.paintComponent(g);if (token == 'X') {g.drawLine(10, 10, getWidth() - 10, getHeight() - 10);g.drawLine(getWidth() - 10, 10, 10, getHeight() - 10);}else if (token == 'O') {g.drawOval(10, 10, getWidth() - 20, getHeight() - 20);}}private class MouseListener extends MouseAdapter {/** 处理鼠标事件 */public void mouseClicked(MouseEvent e) {// 如果单位区域非满则比赛继续if (token == ' ' && whoseTurn != ' ') {setToken(whoseTurn); // 设置象征// 检查游戏进程if (isWon(whoseTurn)) {jlblStatus.setText(whoseTurn + " won! The game is over"); whoseTurn = ' '; // 游戏结束}else if (isFull()) {jlblStatus.setText("Draw! The game is over");whoseTurn = ' '; // 游戏结束}else {whoseTurn = (whoseTurn == 'X') ? 'O': 'X'; // 改变顺序 jlblStatus.setText(whoseTurn + "'s turn"); // 显示顺序 }}}}}/** 使附属程序运行应用程序的方法 **/public static void main(String[] args) {// 创建框架JFrame frame = new JFrame("TicTacToe");// 创造附属程序的实例TicTacToe applet = new TicTacToe();// 增加附属程序事例到框架frame.add(applet, BorderLayout.CENTER);// 框架大小frame.setSize(400, 400);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setVisible(true);}}六、程序运行、调试和结果分析1.程序运行中出现的问题及调试手段(包括异常处理)内容(1):在对程序进行测试时发现“sin”函数出现异常点击“sin”然后输入“90”出现以下情况经过对程序代码的检查发现在下面方法中public void calculate(double x) //各运算符的具体运算方法{double d=0;if (lastCommand.equals("+"))result+= x;else if (lastCommand.equals("-"))result-=x;else if (lastCommand.equals("*"))result*=x;else if (lastCommand.equals("/"))result/=x;else if (lastCommand.equals("="))result=x;else if (lastCommand.equals("sqrt")) {d=Math.sqrt(x);result=d;}else if (lastCommand.equals("exp")){d=Math.exp(x);result=d;}else if (lastCommand.equals("log")){d=Math.log(x);result=d;}else if (lastCommand.equals("tan")){d=Math.tan(x);result=d;}else if (lastCommand.equals("cos")){d=Math.cos(x);result=d;}displayField.setText(""+ result);}发现遗漏以下代码else if (lastCommand.equals("sin")){d=Math.sin(x);result=d;}修改后再次进行测试输入“1.5707963”(约为0.5*pi)再键入“sin”得以下结果可见程序修改成功内容(2):在测试中发现程序无法实现“编辑”菜单中的“全选”项,经检查后发现问题出现在1.public void actionPerformed(ActionEvent e)2.{3.Object src = e.getSource();4.if(src.equals(bttnNew) || src.equals(fileNew))5.{6.newFile();7.}8.else if(src.equals(bttnOpen) || src.equals(fileOpen))9.{10.openFile();11.}12.else if(src.equals(bttnSave) || src.equals(fileSave))13.{14.saveFile();15.}16.else if(src.equals(fileExit))17.{18.exitFile();19.}20.else if(src.equals(bttnCut) || src.equals(editCut))21.{22.txtPad.cut();23.}24.else if(src.equals(bttnCopy) || src.equals(editCopy))25.{26.txtPad.copy();27.}28.else if(src.equals(bttnPaste) || src.equals(editPaste))29.{30.txtPad.paste();31.}32.else if(src.equals(editDel))33.{txtPad.replaceSelection("");34.}35.else if(src.equals(helpAbout))36.{37.aboutHelp();38.}39.}在第31行代码后一行缺少else if(src.equals(editSelectAll)){txtPad.selectAll();}进行修改后再测试发现修改成功内容(3):在程序编译时出现如下情况--------------------配置: <默认>--------------------C:\Documents and Settings\qi\桌面\新建文件夹\TicTacToe.java:39: 需要 ';'return true^1 错误处理已完成。