0%

AAAAA

a

second blog.

b

  • sa
  • ad

daadfa

成龙

ASDF

asd

tables Are Cool
asdf asd asdf

package com.test;

adf


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package register;  

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

import java.awt.Font;
import javax.swing.JPasswordField;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.Toolkit;

public class Register {

private JFrame frame;
private JTextField textField;
private JPasswordField passwordField;

/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Register window = new Register();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

/**
* Create the application.
*/
public Register() {
initialize();
}

/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame("Register");
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);

JButton button = new JButton("\u6CE8\u518C");
button.setBounds(188, 203, 93, 23);
frame.getContentPane().add(button);
button.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
click();
}
});

JLabel label = new JLabel("\u7528\u6237\u540D");
label.setFont(new Font("宋体", Font.PLAIN, 14));
label.setBounds(115, 56, 72, 20);
frame.getContentPane().add(label);

JLabel label_1 = new JLabel("\u5BC6\u7801");
label_1.setFont(new Font("宋体", Font.PLAIN, 14));
label_1.setBounds(115, 106, 72, 20);
frame.getContentPane().add(label_1);

textField = new JTextField();
textField.setBounds(196, 53, 128, 26);
frame.getContentPane().add(textField);
textField.setColumns(10);

passwordField = new JPasswordField();
passwordField.setBounds(196, 106, 128, 26);
frame.getContentPane().add(passwordField);
}
private void click() {
try {
String password=String.valueOf(passwordField.getPassword());
Password pw=new Password(password);
pw.ExceptionCatch();
}catch(NumberRangeException e) {
JOptionPane.showMessageDialog(null,"密码个数不符合规定");
}catch (NotAllNumExpection e) {
JOptionPane.showMessageDialog(null,"密码应该只有数字");
}
}

}
class Password{
private String password;
public Password(String str) {
password=str;
}
public void setPasseord(String str) {
password=str;
}
public String getPassword() {
return password;
}
public void ExceptionCatch() throws NumberRangeException,NotAllNumExpection{
if(password.length()<3||password.length()>6) {

throw new NumberRangeException();
}


if(!password.matches("[0-9]{1,}")) //正则表达式判断是否是纯数字字符串
{

throw new NotAllNumExpection();
}

}

private boolean isNumeric(String tmp) {
return false;
}
}

class NumberRangeException extends Exception{
NumberRangeException()
{
System.out.print("NumberRangeException:4~6");
}

}
class NotAllNumExpection extends Exception{
NotAllNumExpection()
{
System.out.print("NotAllNumExpection:password is expected number");
}

}