rss· 投稿· 设为首页· 加入收藏· 繁體版
当前位置: 火魔网 » 程序开发 » Java基础

简易的聊天用户登录框Java代码

package com.umt.gui;

import java.awt.Font;
import java.awt.TextField;
import java.awt.font.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JFrame;
import javax.swing.ImageIcon;

public class LoginGui extends JFrame  {
 private JTextField username;
 private JTextField pwd;
 
 public LoginGui(String title){
  super(title);
  init();
  this.setVisible(true);
 }
 
 public void init(){
  this.setBounds(300, 200, 300, 200); 
  this.setLayout(null);
  
  //Lable1
  JLabel label1=new JLabel("用户登录");
  label1.setIcon(new ImageIcon("res/login.jpg"));
  label1.setBounds(0, 0, 300, 60);
  label1.setFont(new Font(null,Font.BOLD|Font.ITALIC,24));
  this.add(label1);
  
  //label2
  JLabel label2=new JLabel("用户名");
  label2.setBounds(20, 70, 100, 26);
  this.add(label2);
  
  //TextField
  username=new JTextField();
  username.setBounds(100, 70, 150, 20);
  this.add(username);
  
  //label3
  JLabel label3=new JLabel("密  码");
  label3.setBounds(20, 100, 100, 26);
  this.add(label3);
  
  //TextField
  pwd=new JTextField();
  pwd.setBounds(100, 100, 150, 20);
  this.add(pwd);
  
  //Button
  JButton button1=new JButton("登 录");
  button1.setBounds(90, 130, 60, 26);
  this.add(button1);
  
  JButton button2=new JButton("重置");
  button2.setBounds(190, 130, 60, 26);
  this.add(button2);
  
  button2.addActionListener(new ActionListener(){
   public void actionPerformed(ActionEvent e){
    //System.out.println("我被点了");
    System.out.println(username.getText());
    username.setText("");
    pwd.setText("");
   }
  });
  
 }
 
 public static void main(String arg[]){
  LoginGui login=new LoginGui("腾讯QQ");
 
 }
}

顶一下
(0)
踩一下
(0)