當前位置:編程學習大全網 - 編程語言 - java編程 JFrame swt使用問題

java編程 JFrame swt使用問題

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class Test_Login extends javax.swing.JFrame {

private JPanel jPanel1;

private JButton bntLogin;

private JButton bntCannel;

private JPasswordField pwd;

private JTextField username;

private JLabel jLabel2;

private JLabel jLabel1;

public static void main(String[] args) {

Test_Login inst = new Test_Login();

inst.setLocationRelativeTo(null);

inst.setVisible(true);

}

public Test_Login() {

super();

initGUI();

}

private void initGUI() {

try {

setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

{

jPanel1 = new JPanel();

getContentPane().add(jPanel1, BorderLayout.CENTER);

jPanel1.setLayout(null);

{

jLabel1 = new JLabel();

jPanel1.add(jLabel1);

jLabel1.setText("用戶名");

jLabel1.setBounds(45, 30, 75, 25);

}

{

jLabel2 = new JLabel();

jPanel1.add(jLabel2);

jLabel2.setText("密碼");

jLabel2.setBounds(45, 75, 55, 15);

}

{

username = new JTextField();

jPanel1.add(username);

username.setBounds(100, 30, 140, 25);

}

{

pwd = new JPasswordField();

jPanel1.add(pwd);

pwd.setBounds(100, 70, 140, 25);

}

{

bntLogin = new JButton();

jPanel1.add(bntLogin);

bntLogin.setText("登陸");

bntLogin.setBounds(40, 120, 60, 30);

bntLogin.addMouseListener(new MouseAdapter() {

public void mouseClicked(MouseEvent e) {

if (username.getText().equals("lisong")

&& pwd.getText().equals("lisong")) {

JOptionPane.showMessageDialog(Test_Login.this,

"登錄成功");

} else {

JOptionPane.showMessageDialog(Test_Login.this,

"登錄失敗");

}

}

});

bntCannel = new JButton();

jPanel1.add(bntCannel);

bntCannel.setText("取消");

bntCannel.setBounds(180, 120, 60, 30);

bntCannel.addMouseListener(new MouseAdapter() {

public void mouseClicked(MouseEvent e) {

System.exit(0);

}

});

}

}

pack();

setSize(300, 215);

} catch (Exception e) {

e.printStackTrace();

}

}

}

  • 上一篇:宮燈怎麽拼裝
  • 下一篇:求AKB48 BINGO!的羅馬拼音,THANKS
  • copyright 2024編程學習大全網