private boolean checkForSave() { // build warning message String message; if (file == null) { message = "File has been modified. Save changes?"; } else { message = "File \"" + file.getName() + "\" has been modified. Save changes?"; } // show confirm dialog int r = JOptionPane.showConfirmDialog( this, new JLabel(message), "Warning!", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); if (r == JOptionPane.YES_OPTION) { // Save File if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { // write the file physWriteTextFile(fileChooser.getSelectedFile(), textView.getText()); } else { // user cancelled save after all return false; } } return r != JOptionPane.CANCEL_OPTION; }
/** * Pop-up a Dialog if the source and backup fields are the same. Returns true if the source and * backup remain the same. */ private boolean testSourceVsBackup() { if (dirTF.getText().equals(backupTF.getText())) { final String caption = ResourceHandler.getMessage("caption.warning"); MessageFormat formatter = new MessageFormat(ResourceHandler.getMessage("warning_dialog.info")); final String info = formatter.format(new Object[] {backupTF.getText()}); int n = JOptionPane.showConfirmDialog(this, info, caption, JOptionPane.WARNING_MESSAGE); if (n == JOptionPane.YES_OPTION) { backupTF.setText(backupTF.getText() + "_BAK"); return false; } else if (n == JOptionPane.NO_OPTION) return true; } return false; }
public void exit() { // user is attempting to exit the interpreter. // make sure this is what they want to do // and check if changes need to be saved. int r = JOptionPane.showConfirmDialog( this, new JLabel("Exit Interpreter?"), "Confirm Exit", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (r == JOptionPane.YES_OPTION) { // user still wants to go ahead. // if file not saved then prompt to check // whether it should be. if (!dirty || checkForSave()) { System.exit(0); } } }
void openButton_actionPerformed(ActionEvent e) { String name = nameTextField.getText().trim(); if (mode == ProfileChooser.MODE_OPEN) { // open if (name.equals("")) { JOptionPane.showMessageDialog( this, SanBootView.res.getString("ProfileChooser.errMsg.notSelect")); return; } UniProfile prof = isSameProfile(name); if (prof == null) { JOptionPane.showMessageDialog( this, SanBootView.res.getString("ProfileChooser.errMsg.notExist") + ": " + name); return; } values = new Object[1]; values[0] = prof; } else { // save as 或 save if (name.equals("")) { JOptionPane.showMessageDialog( this, SanBootView.res.getString("ProfileChooser.errMsg.notName")); return; } String tmpName = name; Pattern pattern = Pattern.compile(".+\\.prf"); Matcher matcher = pattern.matcher(tmpName); if (!matcher.find()) { tmpName += ".prf"; } UniProfile pf = isSameProfile(tmpName); if (pf != null) { // 存 在 相 同 的 名 字 的profile ( pf ) if (view.initor.mdb.getSchNumOnProfName(pf.getProfileName()) > 0) { JOptionPane.showMessageDialog( this, SanBootView.res.getString("EditProfileDialog.error.hasSch")); return; } if (JOptionPane.showConfirmDialog( // 提示信息更换 (Dialog) bakable, SanBootView.res.getString("ProfileChooser.confirmmsg1"), SanBootView.res.getString("common.confirm"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) { return; } else { values = new Object[2]; values[0] = pf; values[1] = saveAsProfile; } } else { // 不 存 在 相 同 的 名 字 String pname = ResourceCenter.PROFILE_DIR + name + ".prf"; if (pname.indexOf("\"") >= 0 || pname.indexOf("'") >= 0 || pname.indexOf(' ') >= 0 || pname.indexOf('\t') >= 0) { JOptionPane.showMessageDialog( this, SanBootView.res.getString("ProfileChooser.errmsg.badname")); return; } if (pname.getBytes().length >= 1000) { JOptionPane.showMessageDialog( this, SanBootView.res.getString("ProfileChooser.errmsg.tooLargePname")); return; } values = new Object[1]; saveAsProfile.setProfileName(pname); values[0] = saveAsProfile; } } dispose(); }
@Override public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals("下棋")) { audience.setEnabled(false); fighter.setEnabled(false); begin.setEnabled(true); // JOptionPane.showMessageDialog(null, "下棋"); System.out.println("下棋"); try { System.out.println("客户端发送下棋指令"); out66.writeObject("对手"); out66.flush(); out66.writeObject(new char[0][0]); out66.flush(); out66.writeObject(new boolean[0][0]); out66.flush(); } catch (IOException e1) { e1.printStackTrace(); } } if (e.getActionCommand().equals("观看")) { submit.setEnabled(false); regret.setEnabled(false); audience.setEnabled(false); fighter.setEnabled(false); // JOptionPane.showMessageDialog(null, "观看"); System.out.println("观看"); try { out66.writeObject("观众"); out66.flush(); out66.writeObject(stateList.get(stateList.size() - 1)); out66.flush(); out66.writeObject(takenList.get(takenList.size() - 1)); out66.flush(); } catch (IOException e1) { e1.printStackTrace(); } } /*if (e.getActionCommand().equals("人机对弈")) { audience.setEnabled(false); fighter.setEnabled(false); AIPlayer.setEnabled(false); begin.setEnabled(true); JOptionPane.showMessageDialog(null, "人机对弈"); }*/ if (e.getActionCommand().equals("发送")) { // JOptionPane.showMessageDialog(null, "发送"); System.out.println("发送"); String str = myRole + ": " + " " + jt1.getText() + "\n"; try { out99.writeObject(" " + str); out99.flush(); out99.writeObject(new char[8][8]); out99.flush(); out99.writeObject(new boolean[8][8]); out99.flush(); } catch (IOException e1) { e1.printStackTrace(); } jt2.append(str); jt1.setText(""); } if (e.getActionCommand().equals("取消")) { // JOptionPane.showMessageDialog(null, "取消"); System.out.println("取消"); jt1.setText(""); } if (e.getActionCommand().equals("悔棋")) { // JOptionPane.showMessageDialog(null, "悔棋"); System.out.println("悔棋"); try { out66.writeObject("请求悔棋"); out66.flush(); out66.writeObject(new char[8][8]); out66.flush(); out66.writeObject(new boolean[8][8]); out66.flush(); } catch (IOException e1) { e1.printStackTrace(); } // RegretChess(); // ShowChessNumber(); } if (e.getActionCommand().equals("退出")) { int quit = JOptionPane.showConfirmDialog(null, "您确定要强制退出吗?", "请确认您的选择", JOptionPane.YES_NO_OPTION); if (quit == JOptionPane.YES_OPTION) { JOptionPane.showMessageDialog(null, "已强制退出"); System.exit(0); } else return; } if (e.getActionCommand().equals("开始")) { begin.setEnabled(false); System.out.println("客户端发送开始指令"); // JOptionPane.showMessageDialog(null, "开始"); try { out66.writeObject("请求开始"); out66.flush(); out66.writeObject(stateList.get(stateList.size() - 1)); out66.flush(); out66.writeObject(takenList.get(takenList.size() - 1)); out66.flush(); } catch (IOException e1) { e1.printStackTrace(); } Begin(); if (kind == "黑") { for (int i = 0; i < 8; i++) for (int j = 0; j < 8; j++) if (cell[i][j].taken == false) { CheckPlace(cell[i][j]); if (canPut) { cell[i][j].ChangeBackground(); canPut = false; } } } } if (e.getActionCommand().equals("存盘")) { // JOptionPane.showMessageDialog(null, "存盘"); System.out.println("存盘"); try { System.out.println(); out.writeObject(stateList); out.flush(); out.close(); } catch (IOException e1) { e1.printStackTrace(); } } }
public void saveUnsaved() throws SaveAbortedException { if (!saved) { int option = 0; if (loadedFile == null) option = JOptionPane.showConfirmDialog( this, new JLabel("Save changes to UNTITLED?"), "Warning", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); else option = JOptionPane.showConfirmDialog( this, new JLabel("Save changes to " + loadedFile.getName() + "?"), "Warning", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); if (option == JOptionPane.YES_OPTION) { if (loadedFile == null) // SAVE NEW FILE { if (nameTF.getText().equals("")) { JOptionPane.showMessageDialog( this, new JLabel("Please type in the Scale Name"), "Warning", JOptionPane.WARNING_MESSAGE); throw new SaveAbortedException(); } fileChooser.setFileFilter(filter); int option2 = fileChooser.showSaveDialog(this); if (option2 == JFileChooser.APPROVE_OPTION) { File target = fileChooser.getSelectedFile(); try { PrintStream stream = new PrintStream(new FileOutputStream(target), true); save(stream); stream.close(); } catch (Exception ex) { JOptionPane.showMessageDialog( this, new JLabel("Error: " + ex.getMessage()), "Error", JOptionPane.ERROR_MESSAGE); } } else throw new SaveAbortedException(); ; } else // save LOADED FILE { try { PrintStream stream = new PrintStream(new FileOutputStream(loadedFile), true); save(stream); stream.close(); } catch (Exception ex) { JOptionPane.showMessageDialog( this, new JLabel("Error: " + ex.getMessage()), "Error", JOptionPane.ERROR_MESSAGE); } } } else if (option == JOptionPane.CANCEL_OPTION) throw new SaveAbortedException(); ; } }