标签:
代码:
1 package unit13; 2 3 import java.awt.Color; 4 import java.awt.event.ActionEvent; 5 import java.awt.event.ActionListener; 6 7 import javax.swing.JFrame; 8 import javax.swing.JLabel; 9 import javax.swing.JPasswordField; 10 import javax.swing.JScrollPane; 11 import javax.swing.JTextArea; 12 import javax.swing.JTextField; 13 14 public class app4 extends JFrame implements ActionListener { 15 private JLabel [] jArray={ 16 new JLabel ("用户名:"), 17 new JLabel ("密码:") 18 }; 19 20 private JTextField jName=new JTextField(); 21 private JPasswordField jPassword=new JPasswordField(); 22 23 private JTextArea jText=new JTextArea("我现在不可编辑",10,80); 24 private JScrollPane jsp=new JScrollPane(jText); 25 26 public app4(){ 27 this.setLayout(null); 28 jArray[0].setBounds(20,10,50,25); 29 jArray[1].setBounds(20,30,50,15); 30 31 jName.setBounds(70,10,170,25); 32 jPassword.setBounds(70,35,170,25); 33 jsp.setBounds(20,70,220,100); 34 jText.setEnabled(false); 35 this.add(jArray[0]); 36 this.add(jArray[1]); 37 this.add(jName); 38 this.add(jPassword); 39 this.add(jsp); 40 jText.setDisabledTextColor(Color.red); 41 jName.addActionListener(this); 42 jPassword.addActionListener(this); 43 44 this.setBounds(200,200,500,300); 45 } 46 47 48 49 50 51 52 public static void main(String[] args) { 53 // TODO 自动生成的方法存根 54 55 app4 frm=new app4(); 56 frm.setVisible(true); 57 } 58 59 @Override 60 public void actionPerformed(ActionEvent e) { 61 // TODO 自动生成的方法存根 62 if(jName.getText().equals("abc")&&String.valueOf(jPassword.getPassword()).equals("123")) 63 { 64 jText.setEnabled(true); 65 jText.setText("恭喜你!!\n现在可以编辑了"); 66 jText.setLineWrap(true); 67 } 68 69 70 } 71 72 }
标签:
原文地址:http://www.cnblogs.com/gugibv/p/4555510.html