单行编辑框、口令输入框、多行编辑框的用法!

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class JPassword
{
 JFrame f = new JFrame("单行编辑框、口令输入框、多行编辑框的用法!");
 private JTextField user = new JTextField(20);
 private JPasswordField pwd = new JPasswordField(10);
 private JTextArea ta = new JTextArea(5,10);
 Font ft = new Font("Serif",Font.BOLD,28);
 JPanel jp = new JPanel(new GridLayout(2,2,10,10));
 public static void main(String[] args)
 {
  JPassword that = new JPassword();
  that.go();
 }
 void go()
 {
  f.getContentPane().setLayout(new BorderLayout(0,10));
  f.getContentPane().add("North",jp);
  Label l1 = new Label("用户名:",JLabel.RIGHT);
  jp.add(l1);
  jp.add(user);
  Label l2 = new Label("口令:",JLabel.RIGHT);
  jp.add(l2);
  jp.add(pwd);
  f.getContentPane().add("Center",ta);
  ta.setFont(ft);
  user.setFont(ft);
  pwd.setFont(ft);
  l1.setFont(ft);
  l2.setFont(ft);
  user.addActionListener(new TextHandler(1));
  pwd.addActionListener(new TextHandler(2));
  f.addWindowListener(new WindowHandler());
  f.setSize(450,300);
  f.setResizable(true);
  f.setVisible(true);
 }
 class TextHandler implements ActionListener
 {
  int sel;
  TextHandler(int sel)
  {
   this.sel = sel;
  }
  public void actionPerformed(ActionEvent e)
  {
   String uname,upass;
   uname = user.getText();
   upass = new String(pwd.getPassword());
   ta.setText("你输入的用户名是"+uname+"/n"+"你输入的口令是"+upass);
  }
 }
 class WindowHandler extends WindowAdapter
 {
  public void windowClosing(WindowEvent e)
  {
   System.exit(1);
  }
 }
}
代码编译没问题,但是运行不起来,高手看了不妨运行下试试看

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值