swing简单模仿QQ登陆界面

效果图

<ignore_js_op>

 

代码如下

  1. package Game;
  2. import  javax.swing.*;
  3. import java.awt.*;
  4. import java.awt.event.*;
  5. class Qq{
  6.     public  void showLoginFrame(){
  7.         final JFrame loginFrame=new JFrame();
  8.         //设置大小,位置,标题
  9.         loginFrame.setSize(300,200);
  10.         loginFrame.setTitle("QQ2014");
  11.         loginFrame.setLocationRelativeTo(null);
  12.         //创建流式分布对象
  13.         FlowLayout layout=new FlowLayout();
  14.         loginFrame.setLayout(layout);
  15.          
  16.         //创建账户名,密码和输入框
  17.         JLabel user=new JLabel("账号:");
  18.         JLabel password=new JLabel("密码:");
  19.         final JTextField named=new JTextField(20);
  20.         final JPasswordField password2=new JPasswordField(20);
  21.         //创建登陆,重置按钮
  22.         JButton reset=new JButton("重置");
  23.         JButton login=new JButton("登陆");
  24.          
  25.         //设置窗体可见
  26.         loginFrame.setVisible(true);
  27.          
  28.         //创建事件监听对象
  29.         ActionListener listener1=new ActionListener(){
  30.             public void actionPerformed(ActionEvent e){
  31.                 String name=named.getText();
  32.                 String password=password2.getText();
  33.                 if("zhaoxin".equals(name)&&"123".equals(password))
  34.                 {
  35.                     showIndexFrame();
  36.                     loginFrame.setDefaultCloseOperation(3);
  37.                     loginFrame.setVisible(false);
  38.                 }
  39.                 else{
  40.                     System.out.println("密码错误,重新输入!");
  41.                 }
  42.                  
  43.                  
  44.             }
  45.              .......

详细说明:http://java.662p.com/thread-3728-1-1.html

posted on 2014-11-18 09:42  wangniuzen  阅读(1748)  评论(0编辑  收藏  举报

导航