使用Java的Frame類編寫的QQ登入介面

來源:互聯網
上載者:User

標籤:錯誤   public   efault   res   listen   使用   介面   resizable   print   

  1 public static void main(String[] args) {  2           3         Frame f = new Frame();  4           5         //關閉表單  6         f.addWindowListener(new WindowAdapter() {  7             @Override  8             public void windowClosing(WindowEvent e) {  9                 System.exit(0); 10             } 11         }); 12          13         f.setTitle("QQ登入");//添加標題 14         f.setSize(420, 230);//設定表單的尺寸 15         f.setLocation(455, 207);//設定表單出現座標 16         f.setLayout(null);//清除表單預設布局 17         f.setIconImage(Toolkit.getDefaultToolkit().getImage("F:\\qq.png"));//設定表徵圖 18         f.setResizable(false);//禁止表單改變尺寸 19          20      21          22         //帳號標籤 23         Label user = new Label("帳號:"); 24         user.setLocation(75, 50); 25         user.setSize(50, 25); 26         user.setFont(new Font("微軟雅黑",Font.BOLD,16)); 27         f.add(user); 28          29         //密碼標籤 30         Label password = new Label("密碼:"); 31         password.setLocation(75, 100); 32         password.setSize(50, 25); 33         password.setFont(new Font("微軟雅黑",Font.BOLD,16)); 34         f.add(password); 35          36         //輸入帳號的文字框 37         TextField t1 = new TextField(); 38         //鍵盤輸入監聽 39         t1.addKeyListener(new KeyAdapter() { 40             @Override 41             public void keyTyped(KeyEvent e) { 42                 int key = e.getKeyChar(); 43                 if(key>=KeyEvent.VK_0 && key<=KeyEvent.VK_9){ 44                      45                 }else{ 46                     e.consume(); 47                 } 48             } 49         }); 50         t1.setSize(220,25); 51         t1.setLocation(130, 50); 52         t1.setFont(new Font("微軟雅黑",Font.PLAIN,16)); 53         f.add(t1); 54          55         //輸入密碼的文字框 56         TextField t2 = new TextField(); 57         t2.setEchoChar(‘*‘); 58         t2.setSize(220,25); 59         t2.setLocation(130, 100); 60         t2.setFont(new Font("微軟雅黑",Font.PLAIN,16)); 61         f.add(t2); 62          63         //登入按鈕 64         Button login = new Button("登入"); 65         //按鈕觸發事件 66         login.addActionListener(new ActionListener() { 67              68             @Override 69             public void actionPerformed(ActionEvent arg0) { 70                 String zh = t1.getText(); 71                 String ma = t2.getText(); 72                 if(zh.equals("34598700") && ma.equals("meinv123")){ 73                     System.out.println("登入成功"); 74                 }else{ 75                     JOptionPane.showMessageDialog(f, "帳號或密碼輸入錯誤"); 76                     t1.setText(""); 77                     t2.setText(""); 78                 } 79             } 80         }); 81         login.setLocation(100, 160);//按鈕在表單中的座標 82         login.setSize(75, 30);//設計按鈕的尺寸 83         f.add(login);//把按鈕元素添加到表單中 84          85         //註冊按鈕 86         Button reg = new Button("註冊"); 87         //觸發事件 88         reg.addActionListener(new ActionListener() { 89              90             @Override 91             public void actionPerformed(ActionEvent e) { 92                 new Reg(); 93             } 94         }); 95         reg.setLocation(250, 160);//按鈕在表單中的座標 96         reg.setSize(75, 30);//設計按鈕的尺寸 97         f.add(reg);//把按鈕元素添加到表單中 98          99         f.setVisible(true);//設定表單的可見度100 101     }

 

使用Java的Frame類編寫的QQ登入介面

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.