swing簡單模仿QQ登錄界面

效果圖html

<ignore_js_op>java

 

代碼以下code

  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.htmlorm

相關文章
相關標籤/搜索