Java图形界面(3)

 1 package t1;
 2 import javax.swing.*;
 3 public class Test5 extends JFrame {
 4     JTextField jtf=new JTextField("该文本框不可编辑",30);
 5     static JPasswordField jpf=new JPasswordField("太空人3号",30);
 6     public Test5(String str) {
 7         super(str);
 8         jtf.setBounds(20,40,140,20);
 9         jtf.setEditable(false);
10         add(jtf);
11     }
12     public static void main(String[] args) {
13 
14         Test5 frm=new Test5("文本编辑窗口");
15         JTextArea jta=new JTextArea("您好",10,30);
16         JScrollPane jsp=new JScrollPane(jta);
17         frm.setLocation(200, 150);
18         frm.setSize(240, 220);
19         frm.setLayout(null);
20         jsp.setBounds(20, 70, 160, 100);
21         jpf.setBounds(20, 10, 140, 20);
22         jpf.setEchoChar('*');
23         frm.add(jpf);
24         frm.add(jsp);
25         char[] password=jpf.getPassword();
26         String str=new String(password);
27         System.out.println("今天口令是: "+password+"  转换成文本后是: "+str);
28         frm.setVisible(true);
29         frm.setResizable(false);
30         frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
31         
32     }
33 
34 }
原文地址:https://www.cnblogs.com/ljydbk/p/14804064.html