java小程序2

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class NULLLayoutDemo extends JFrame implements ActionListener {
 private JLabel lbUser = new JLabel();
 private JLabel info = new JLabel();
 private JLabel lbPassword = new JLabel();
 private JButton btnLog = new JButton();/* 该行有错误什么问题呀 */
 private Container container = getContentPane();
 private JTextField jtextfield_1 = new JTextField(10);
 private JPasswordField jtextfield_2 = new JPasswordField(10);
 public NULLLayoutDemo() {
  super("登陆器");
  this.setSize(350, 200);
  this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 }
 public static void main(String[] args) {
  NULLLayoutDemo frame = new NULLLayoutDemo();
  frame.setLayout();
  frame.setVisible(true);
 }
 public void setLayout() {
  container.setLayout(null);
  lbUser.setText("用户名");
  container.add(lbUser);
  container.add(jtextfield_1); // 增加输入用户名的文本框
  jtextfield_1.setBounds(80, 26, 120, 26);// 设置用户名的文本框位置
  lbUser.setBounds(16, 26, 42, 16);
  lbPassword.setText("密码");
  container.add(lbPassword);
  lbPassword.setBounds(16, 56, 40, 16);
  btnLog.setText("登陆");
  jtextfield_2.setEchoChar('*');
  container.add(jtextfield_2);// 设置密码的文本框位置
  jtextfield_2.setBounds(80, 56, 120, 26);// 增加输入密码的文本框
  container.add(btnLog);
  btnLog.addActionListener(this);
  btnLog.setBounds(125, 101, 73, 25);
//  info.setBounds(0, 130, 300, 35); // 设置信息的标签
  info.setText("用户名是:我爱你 密码是:520");
  container.add(info);
  /*
   * public void ceshi(){ if() }
   */
 }
 public void actionPerformed(ActionEvent e) {
  String name = jtextfield_1.getText(); // 取得用户名文本框的信息
  String password = jtextfield_2.getText();// 取得密码文本框的信息
  // 判断是否符合条件
  if ("我爱你".equals(name) && "520".equals(password)) {
   JOptionPane.showMessageDialog(this, "恭喜你!爱情登陆成功", "通过",
     JOptionPane.INFORMATION_MESSAGE, null);
  } else {
   JOptionPane.showMessageDialog(this, "你的输入错误", "错误",
     JOptionPane.INFORMATION_MESSAGE, null);
  }
 }
}
 
 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值