?? wmltextvalidator.java
字號:
package wapide;/** * Used to validate text to see if it conforms to wml standards. * Currently, items checked for include the following: * " : quotation marks. * ' : apostrophes. * < : less than sign * > : greater than sign * = : not supported by all attributes */ /** * Copyright: Copyright (c) 2003 * @author Mark Busman * @version 1.0 * * For License and contact information see WAPIDE.java */import javax.swing.*;import java.awt.*;import java.lang.*;import java.util.*;public class WMLTextValidator { /** * Constructor - creates a new WMLTextValidator Object. */ public WMLTextValidator() { } /** * Constructor - creates a new WMLTextValidator Object and checks * the text for restricted phrases and characters. Will display a * pop-up message if a restricted character or phrase is found. * @param String text - the text to search in. * @param Component component - the component being checked, can be null. */ public WMLTextValidator(String text, Component c) { boolean found = false; String[] check = {"<", ">", "\"", "'", "="}; for (int x = 0; x < 5; x++) { if ((!found) && (text.indexOf(check[x]) > -1)) found = true; } if (found) { displayWarning(c); } } /** * Checks to see if the text contains any characters that are considered * restricted by WML rules, such as quotation marks("). * @param String text - the text to search in. */ public boolean checkText(String text) { boolean found = false; try { String[] check = {"<", ">", "\"", "'", "="}; for (int x = 0; x < 5; x++) { if ((!found) && (text.indexOf(check[x]) > -1)) found = true; } } catch (NullPointerException nullerr) {} return found; } /** * Checks to see if the text contains any characters that are considered * restricted by WML rules, such as quotation marks("). * @param String text - the text to search in. * @param String[] items - custom items to check. */ public boolean checkText(String text, String[] items) { boolean found = false; try { String[] check = items; for (int x = 0; x < 5; x++) { if ((!found) && (text.indexOf(check[x]) > -1)) found = true; } } catch (NullPointerException nullerr) {} return found; } /** * Displays a dialog with a default warning message. * The message reads as follows: * "One or more field(s) have one or more reserved character(s), * be sure the following characters are not used: * <, >, ", ', and = (not supported by all attributes) * See the WAP Developer's Manual for further information." * @param Component component - the Component requesting the display of the dialog, can be null. */ public void displayWarning(Component c) { String title = "Warning: Illegal use of reserved characters"; int messageType = JOptionPane.WARNING_MESSAGE; int optionType = JOptionPane.DEFAULT_OPTION; String message = "One or more fields have one or more reserved character(s),\n"; message = message + "be sure the following characters are not used:\n"; message = message + " <, >, \", ', = (not supported by all attributes)"; message = message + "\n\nSee the WAP Developer's Manual for further information."; JOptionPane pane = new JOptionPane(message, messageType, optionType); JDialog dlg = pane.createDialog(c, title); dlg.show(); } /** * Displays a warning dialog with a custom message. * @param Component component - the Component requesting the display of the dialog, can be null. * @param String message - the warning message to display in the dialog. */ public void displayWarning(Component c, String message) { String title = "Warning: Illegal use of reserved characters"; int messageType = JOptionPane.WARNING_MESSAGE; int optionType = JOptionPane.DEFAULT_OPTION; JOptionPane pane = new JOptionPane(message, messageType, optionType); JDialog dlg = pane.createDialog(c, title); dlg.show(); } //public static void main(String[] args) { // WMLTextValidator WMLTextValidator1 = new WMLTextValidator("test of try", null); //}}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -