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

📄 increment1frame.java

📁 java 开源游戏源码 RISK 联机对战 战棋类
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
		    go("manual");
                }
            });
        menuHelp.add(helpMan);

        JMenuItem helpAbout = new JMenuItem("About");
        helpAbout.setMnemonic('A');
        helpAbout.addActionListener(
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    openAbout();
                }
            });
        menuHelp.add(helpAbout);

        // create Clear menu item
        JMenu menuClear = new JMenu("Clear");
        menuClear.setMnemonic('C');

        JMenuItem ClearConsole = new JMenuItem("Clear Console");
        ClearConsole.setMnemonic('s');
        ClearConsole.addActionListener(
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    Testing.append("Console cleared\n");
		    Console.setText("");
                }
            });
        menuClear.add(ClearConsole);

        JMenuItem ClearTestLog = new JMenuItem("Clear TestLog");
        ClearTestLog.setMnemonic('T');
        ClearTestLog.addActionListener(
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    Testing.append("TestLog cleared\n");
		    Testing.setText("");
                }
            });
        menuClear.add(ClearTestLog);

        JMenuItem ClearHistory = new JMenuItem("Clear History");
        ClearHistory.setMnemonic('H');
        ClearHistory.addActionListener(
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
		    history.clear();
		    pointer = -1;
                    Testing.append("History cleared\n");
                }
            });
        menuClear.add(ClearHistory);

        // create Open menu item
        final JFileChooser fc = new JFileChooser();
        JMenuItem openFile = new JMenuItem("Run Script");
        openFile.setMnemonic('R');
        openFile.addActionListener(
            new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent e) {
                    int returnVal = fc.showOpenDialog(Increment1Frame.this);
                    if (returnVal == javax.swing.JFileChooser.APPROVE_OPTION) {
                        java.io.File file = fc.getSelectedFile();
                        // Write your code here what to do with selected file

			    try {
				//Submit.setEnabled(false);
				//Command.setEnabled(false);
				//statusBar.setText("Working...");

        			Testing.append("Opening file: "+ file.getPath() +"\n");
        			Testing.append("Running Script...\n");

				FileReader filein = new FileReader(file);
				BufferedReader bufferin = new BufferedReader(filein);

				String input = bufferin.readLine();
				while(input != null) {

				    go(input);
				    input = bufferin.readLine();

				}
				bufferin.close();
        			Testing.append("Script end\n");

				//Submit.setEnabled(true);
				//Command.setEnabled(true);
				//statusBar.setText("Done... Ready");
			    }
			    catch(Exception error) {
				    Testing.append("Error: "+error.getMessage() + "\n");
 			    }

                    } else {
                        // Write your code here what to do if user has canceled Open dialog
                    }
                }
            });
        menuFile.add(openFile);

        // create Save menu item
        JMenuItem saveFile = new JMenuItem("Save Console");
        saveFile.setMnemonic('S');
        saveFile.addActionListener(
            new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent e) {
                    int returnVal = fc.showSaveDialog(Increment1Frame.this);
                    if (returnVal == JFileChooser.APPROVE_OPTION) {
                        java.io.File file = fc.getSelectedFile();
                        // Write your code here what to do with selected file

			    try {
				//Submit.setEnabled(false);
				//Command.setEnabled(false);
				//statusBar.setText("Working...");

        			Testing.append("Creating file: "+ file.getPath() +"\n");
        			Testing.append("Writing to file...\n");

			        FileWriter fileout = new FileWriter(file);
			        BufferedWriter buffer = new BufferedWriter(fileout);
			        PrintWriter printer = new PrintWriter(buffer);

			        printer.write(Console.getText());

			        printer.close();
        			Testing.append("File Saved\n");

				//Submit.setEnabled(true);
				//Command.setEnabled(true);
				//statusBar.setText("Done... Ready");
			    }

			    catch(Exception error) {
				    Testing.append("Error: "+error.getMessage() + "\n");
 			    }

                    } else {
                        // Write your code here what to do if user has canceled Save dialog
                    }
                }
            });
        menuFile.add(saveFile);

        // create Print menu item
        JMenuItem print = new JMenuItem("Print");
        print.setMnemonic('P');
        print.addActionListener(
            new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent e) {
                    PrintDialog.print();
                }
            }); menuFile.add(print);

        // create Exit menu item
        JMenuItem fileExit = new JMenuItem("Exit");
        fileExit.setMnemonic('E');
        fileExit.addActionListener(
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    System.exit(0);
                }
            });
        menuFile.add(fileExit);

        menuBar.add(menuFile);
        menuBar.add(menuClear);
        menuBar.add(menuHelp);

        // sets menu bar
        setJMenuBar(menuBar);
        setBounds(new java.awt.Rectangle(0,0,905,629));
        addWindowListener(
            new java.awt.event.WindowAdapter() {
                public void windowClosing(java.awt.event.WindowEvent evt) {
                    exitForm(evt);
                }
            }
	);

        // pack();

    }

    /** Exit the Application */

    /**
     * Closes the GUI
     * @param evt Close button was pressed
     */
    private void exitForm(WindowEvent evt) {
        Testing.append("Exit\n");
        System.exit(0);
    }

    /**
     * Submits input to parser if neccessary
     * @param input The string that is checked
     */
    public void go(String input) {

        Testing.append("Submitted: \""+input+"\"\n");

	if (input.equals("exit") ) {
	    // Testing.append("Exit.\n");
            System.exit(0);
	}
	else if (input.equals("help") ) {
	    Commands();
	}
	else if (input.equals("about") ) {
	    openAbout();
	}
	else if (input.equals("clear") ) {
	    Console.setText("");
	    Testing.append("Console cleared\n");
	}
	else if (input.equals("manual") ) {

		try {
			RiskUtil.openDocs("help/index_commands.htm");
			Testing.append("Manual Opened\n");
		}
		catch(Exception e) {
			JOptionPane.showMessageDialog(this,"Unable to open manual: "+e.getMessage(),"Error", JOptionPane.ERROR_MESSAGE);
		}

	}
	else {

	    //statusBar.setText("Working...");
	    //Submit.setEnabled(false);
	    //Command.setEnabled(false);

	    risk.parser(input);
	}

	// Console.setCaretPosition(Console.getDocument().getLength());

    }

    /**
     * This reads in a file for the commands
     * @throws FileNotFoundException The file cannot be found
     * @throws IOException
     */
    public void Commands() {

	String commands="";

	try {
	    FileReader filein = new FileReader("commands.txt");
	    BufferedReader bufferin = new BufferedReader(filein);
	    String input = bufferin.readLine();
	    while(input != null) {
		if (commands.equals("")) { commands = input; }
		else { commands = commands + "\n" + input; }
		input = bufferin.readLine();
	    }
	    bufferin.close();
            Testing.append("Commands Box opened\n");
	    JOptionPane.showMessageDialog(this, commands, "Commands:", JOptionPane.PLAIN_MESSAGE);
	}
	catch (FileNotFoundException e) {
	    Testing.append("Unable to find file commands.txt\n");
	}
	catch (IOException e) {
	    Testing.append("Unable to read file commands.txt\n");
	}

    }

    /**
     * This opens the about dialog box
     */
    public void openAbout() {

	RiskUtil.openAbout(Increment1Frame.this,product, version);

	Testing.append("About Box opened\n");

    }

class Increment1RiskAdapter extends RiskAdapter {

    /**
     * Checks if redrawing or repainting is needed 
     * @param output
     * @param redrawNeeded If frame needs to be redrawn
     * @param repaintNeeded If frame needs to be repainted 
     */
    public void sendMessage(String output, boolean redrawNeeded, boolean repaintNeeded) {

	Testing.append("Returned: \""+output+"\"\n");
	Console.append(output + System.getProperty("line.separator") );

	Console.setCaretPosition(Console.getDocument().getLength());

    }

    /**
     * checks if the the frame needs input 
     * @param s determines what needs input
     */
    public void needInput(int s) {

	Submit.setEnabled(true);
	Command.setEnabled(true);
	Command.requestFocus();
	statusBar.setText("Done... Ready");

    }

    /**
     * Blocks Input
     */
    public void noInput() {

	statusBar.setText("Working...");
	Submit.setEnabled(false);
	Command.setEnabled(false);

        Testing.append("Input Blocked\n");

    }

}

    /**
     * This runs the program
     * @param argv
     */
    public static void main(String[] argv) {

	Increment1Frame gui = new Increment1Frame( new Risk(null,"sersom.map","risk.cards") );

        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension frameSize = gui.getSize();
        frameSize.height = ((frameSize.height > screenSize.height) ? screenSize.height : frameSize.height);
        frameSize.width = ((frameSize.width > screenSize.width) ? screenSize.width : frameSize.width);
        gui.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
        gui.setVisible(true);

    }

}

⌨️ 快捷键说明

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