java事件处理
完成一个按钮的事件处理程序,实现功能自拟,例如:改变窗口的背景颜色,改变按钮的位置等等
package demo; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; public class MyFrame implements ActionListener { JPanel p; JFrame f; JButton b; JLabel l1,l2; JTextField t1,t2; JPasswordField s; JTextArea a; public MyFrame () { f = new JFrame(); p = new JPanel(); b = new JButton("登录"); b.addActionListener(this); l1 = new JLabel("手机号码"); t1 = new JTextField(10); l2 = new JLabel("密码"); s = new JPasswordField(10); a = new JTextArea(); f.add(p); p.add(l1); p.add(t1); p.add(l2); p.add(s); p.add(b); p.add(a); f.setSize(500, 400); f.setLocation(450, 300); f.setVisible(true); } public static void main(String []args) { new MyFrame(); } @Override public void actionPerformed(ActionEvent arg0) { // TODO 自动生成的方法存根 p.setBackground(new Color(217,129,229)); a.setText("巴啦啦能量"); } }
开始不知道怎么隐藏密码,现在又不会怎么把'.'变成'*'.(ಥ﹏ಥ)