www.pudn.com > charsettools_1.0.2.zip > UIUtilDialog.java


/* 

Program UIUtilDialog.java *

Author Keiven Ju *

Created 2003-12-23 6:29:25 *

Copyright 1995-1998,2000-2003 by AKuP International, Inc.,

*

Nanjing:

* Unit C, 26F Jianjiang Culture Building, No. 89 Zhongshannan Rd. Nanjing 210005 China

*

26F, Jianjiang Building No.89,Zhongshan South Rd, Nanjing *

Taipei :

*

5F, NO.6, Alley 36, Lane 26, Rueiguang Rd, Neihu District, Taipei City 114, Taiwan *

* All rights reserved.

*

* This software is the confidential and proprietary information

* of AKuP International, Inc. ("Confidential Information"). You

* shall not disclose such Confidential Information and shall use

* it only in accordance with the terms of the license agreement

* you entered into with AKuP.

*

* E-mail keiven.ju@akup.com for more information. */ package com.akup.charset.ui; import java.awt.Component; import java.awt.Frame; import javax.swing.JFileChooser; import javax.swing.JOptionPane; /** * program UIUtilDialog * @author Keiven Ju * @since 1.0.0 * @version 1.0.0 2003-12-23 6:29:25 */ public class UIUtilDialog extends Frame { /** * selectDIRECTORIES, * @param isSave * @param frame * @return String * @since 1.0.0 2003-12-24 */ public static String selectDIRECTORIES(boolean isSave, Component frame) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int option; if (isSave) { option = fileChooser.showSaveDialog(frame); } else { option = fileChooser.showOpenDialog(frame); } if (option == JFileChooser.APPROVE_OPTION) { return fileChooser.getSelectedFile().getAbsolutePath(); } return ""; } /** * selectFile, * @param isSave * @param fileType * @param frame * @return String * @since 1.0.0 2003-12-24 */ public static String selectFile(boolean isSave, String fileType, Component frame) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); if (fileType != "") { ExtensionFileFilter filter = new ExtensionFileFilter("Select Files(" + fileType + ")", fileType); fileChooser.addChoosableFileFilter(filter); } int option; if (isSave) { option = fileChooser.showSaveDialog(frame); } else { option = fileChooser.showOpenDialog(frame); } if (option == JFileChooser.APPROVE_OPTION) { return fileChooser.getSelectedFile().getAbsolutePath(); } return ""; } //return value public static final int YES_OPTION = JOptionPane.YES_OPTION; public static final int NO_OPTION = JOptionPane.NO_OPTION; public static final int CANCEL_OPTION = JOptionPane.CANCEL_OPTION; public static final int OK_OPTION = JOptionPane.OK_OPTION; public static final int CLOSED_OPTION = JOptionPane.CLOSED_OPTION; /**\u666e\u901aMessageBox info\u5904\u7406*/ public void messageBox(String msg) { JOptionPane.showMessageDialog(this, msg, "\u4fe1\u606f\uff1a", JOptionPane.INFORMATION_MESSAGE); this.dispose(); } /**\u666e\u901aMessageBox Error \u5904\u7406*/ public void messageBoxError(String msg) { JOptionPane.showMessageDialog(this, msg, "\u9519\u8bef\uff1a", JOptionPane.ERROR_MESSAGE); this.dispose(); } /**\u666e\u901aMessageBox OK \u5904\u7406*/ public int messageBoxOKCANCEL(String msg) { Object[] options = { "OK", "CANCEL" }; int r = JOptionPane.showOptionDialog(this, msg, "\u8bf7\u786e\u8ba4", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]); this.dispose(); return r; } /**\u666e\u901aMessageBox Yes/No \u5904\u7406*/ public int messageBoxYesNo(String msg) { int r = JOptionPane.showConfirmDialog(this, msg, "\u8be2\u95ee ", JOptionPane.YES_NO_OPTION); this.dispose(); return r; } /**\u666e\u901ainputBox \u5904\u7406*/ public String inputBox(String msg) { String r = JOptionPane.showInputDialog(this, msg, "\u8bf7\u8f93\u5165\uff1a", JOptionPane.QUESTION_MESSAGE); this.dispose(); return r; } /**\u666e\u901ainputBox \u521d\u59cb\u503c \u5904\u7406*/ public String inputBox(String msg, String initValue) { String r = JOptionPane.showInputDialog(this, msg, initValue); this.dispose(); return r; } /** * \u4e00\u5b9a\u8981\u52a0\u4e0adispose\u5426\u5219\u9000\u51fa\u4e0d\u4e86 * Overriding dispose * @see java.awt.Window#dispose() * @since 1.0.0 2003-9-18 */ public void dispose() { super.dispose(); } public static void main(String[] args) { UIUtilDialog dlg = new UIUtilDialog(); Object str = "\u4e0d\u9700\u8981\u521d\u59cb\u5316"; if (dlg.messageBoxYesNo("\u9700\u8981\u521d\u59cb\u5316\u5417\uff1f") == UIUtilDialog.YES_OPTION) { str = dlg.inputBox("\u521d\u59cb\u5316\u503c\uff1a", "1235"); } dlg.messageBoxOKCANCEL((String) str); //dlg.dispose(); System.out.println("finished\uff1a" + str); } }