编写一个小程序,java

来源:百度知道 编辑:UC知道 时间:2024/07/07 14:20:58
编写一个小程序,用文本框接受用户的用户名和密码,如果用户名和密码是javalearner和happy,则输出“javahappy”,

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Mima extends JFrame implements ActionListener
{
JPanel jp=new JPanel();
JTextField text=new JTextField();
JPasswordField pass=new JPasswordField();
JLabel l1=new JLabel("请输入用户名:");
JLabel l2=new JLabel("请输入密码:");
JLabel l3=new JLabel("");
public Mima()
{
jp.setLayout(null);
l1.setBounds(10,10,120,20);
text.setBounds(120,10,120,20);
l2.setBounds(10,30,120,20);
pass.setBounds(120,30,120,20);
pass.addActionListener(this);
l3.setBounds(10,60,120,20);
pass.setEchoChar('*');
jp.add(l1);
jp.add(text);
jp.add(l2);
jp.add(pass);
jp.add(l3);

this.add(jp);
this.setBounds(100,100,260,120);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public voi