textfielddemo.java

来自「java课件 java课件 java课件 java课件」· Java 代码 · 共 35 行

JAVA
35
字号
//<applet code="TextFieldDemo.class" height="120" width="240">
//</applet>
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TextFieldDemo extends JApplet{
  JLabel label,label1,label2;
  JTextField  jtf;
  JPasswordField  jpf;
  Container cp;
  public void init(){
  	label=new JLabel("Please input name and password:");
  	label.setForeground(Color.BLUE);
  	label1=new JLabel("User Name:");
  	label2=new JLabel("Password:");
  	jtf=new JTextField(10);
    jpf=new JPasswordField(10);
    cp=getContentPane();
    cp.setLayout(new FlowLayout());
    cp.add(label);
    cp.add(label1); cp.add(jtf);
    cp.add(label2); cp.add(jpf);
    jtf.setFocusable(true);
    jpf.addActionListener(new TL());
  }
  public class TL implements ActionListener{
    public void actionPerformed(ActionEvent e){
      String name=jtf.getText();
      char[]pass=jpf.getPassword();
      String password=new String(pass);
      label.setText("name:"+name+",password:"+password);
     }
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?