MainKaisa.java
1 import javax.swing.JFrame;
2
3 public class MainKaisa {
4
5 /**
6 * @param nonles
7 */
8 public static void main(String[] args) {
9 //瀹炰緥鍖栦竴涓獥浣?/span>
10 KaisaFrame kaisaFrame = new KaisaFrame();
11 kaisaFrame.setVisible(true);
12 kaisaFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
13
14 }
15
16 }
Kaisa.java
1 mport java.awt.event.ActionEvent;
2 import java.awt.event.ActionListener;
3 import javax.swing.*;
4
5 public class KaisaFrame extends JFrame {
6
7 JLabel jlDackText = new JLabel();
8 JButton btnBrightText = new JButton();
9 JPasswordField jpf = new JPasswordField();
10 JTextField jtf2 = new JTextField();
11 char[] buf;
12
13
14 public KaisaFrame() {
15 this.setSize(300,200); //璁劇疆紿椾綋澶у皬
16 this.setTitle("鍑拻鍔犲瘑娉?/span>");
17 this.setResizable(false);
18
19 jbInit();
20 }
21
22 private void isLetter() {
23 //鍒ゆ柇杈撳叆鐨勫唴瀹規槸鍚︿負瀛楁瘝
24 buf = jpf.getPassword();
25 for(char c:buf) {
26 if(Character.isLetter(c) == false) {
27 JOptionPane.showMessageDialog(this, "涓嶈兘涓洪潪瀛楃", "Error", JOptionPane.ERROR_MESSAGE);
28 jpf.setText("");
29 jtf2.setText("");
30 return;
31 } else {
32 makeBrightText();
33 }
34 }
35 }
36
37 private void makeBrightText() {
38 // 浜х敓鏄庢枃
39 char[] arr = new char[buf.length];
40 int index=0,temp;
41 for(char c:buf) {
42 temp = c+3; //瀛楁瘝鍚庣Щ涓変綅
43 if( (temp>90 && temp<97) || temp>122 ) {
44 //鑻SCII鐮佸湪姝ゅ尯闂村垯鍑忓幓26(浣垮瓧絎YZ,xyz寰幆鍒癤AB,xab)
45 temp = temp - 26;
46 arr[index++] = (char)temp;
47 } else {
48 arr[index++] = (char)temp;
49 }
50 }
51
52 String str = new String(arr);
53 jtf2.setText(str);
54
55 }
56
57 private void jbInit() {
58 // 璁劇疆紿椾綋鍐呭
59 this.setLayout(null);
60 jlDackText.setText("杈撳叆瀵嗘枃錛?/span>");
61 jlDackText.setBounds(30, 20, 80, 30);
62 btnBrightText.setText("鐢熸垚鏄庢枃錛?/span>");
63 btnBrightText.setBounds(30, 90, 100, 30);
64 jpf.setBounds(160, 20, 80, 30);
65 jpf.setEchoChar('*');
66 jtf2.setBounds(160, 90, 80, 30);
67 jtf2.setEditable(false);
68
69 this.add(jlDackText);
70 this.add(jpf);
71 this.add(btnBrightText);
72 this.add(jtf2);
73
74 btnBrightText.addActionListener(new ActionListener(){
75
76 @Override
77 public void actionPerformed(ActionEvent e) {
78 isLetter(); //鍒ゆ柇杈撳叆鐨勫唴瀹規槸鍚︿負瀛楁瘝
79 }
80
81 });
82 }
83
84 }
85
鐜板疄鍥捐В錛?nbsp;
寰鏂囨湰妗嗕腑杈撳叆瀵嗘枃錛堝彧闄愬瓧絎︼級錛岀偣鍑繪寜閽紝鍗崇敓鎴愮浉搴斿瘑鏂囥?

鑻ヨ緭鍏ヤ負闈炲瓧絎︼紝鍒欏脊鍑洪敊璇~

綆鍗曠殑涓涓▼搴忥紝璇存槑閮戒笉鐢ㄤ簡銆傘傘?br />

]]>