當前位置:編程學習大全網 - 源碼下載 - JAVA GUI設計.文本框需要點擊壹下或者用鼠標改變船體大小才能顯示.

JAVA GUI設計.文本框需要點擊壹下或者用鼠標改變船體大小才能顯示.

把妳的 ct.setVisible(true); 這行放到 p.add(userpas); 之後,就行了。 如:

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JPasswordField;

import javax.swing.JTextField;

/**

* 登錄窗體

*

* @author 娃娃

*

*/

public class denglu {

JFrame ct;

JPanel p;

JButton denglu, tuichu;

JLabel usernamel, userpasl;

JTextField username;

JPasswordField userpas;

public denglu() {

// TODO Auto-generated constructor stub

ct = new JFrame("登 錄");

ct.setSize(300, 200);

ct.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

p = new JPanel();

p.setLayout(null);

ct.add(p);

denglu = new JButton("登 錄");

denglu.setBounds(50, 120, 70, 30);

denglu.addActionListener(new denglulistener());

p.add(denglu);

tuichu = new JButton("退 出");

tuichu.setBounds(170, 120, 70, 30);

tuichu.addActionListener(new tuichulistener());

p.add(tuichu);

usernamel = new JLabel("用戶名:");

usernamel.setBounds(30, 25, 50, 25);

p.add(usernamel);

userpasl = new JLabel("密 碼:");

userpasl.setBounds(30, 60, 50, 25);

p.add(userpasl);

username = new JTextField();

username.setBounds(90, 25, 150, 25);

p.add(username);

userpas = new JPasswordField();

userpas.setBounds(90, 60, 150, 25);

userpas.setEchoChar('*');

p.add(userpas);

ct.setVisible(true);

}

public static void main(String [] args) {

new denglu();

}

class denglulistener implements ActionListener {

public void actionPerformed(ActionEvent e) {

sjk.cxsql cxsql=new sjk.cxsql();

long tem =cxsql.acdl(username.getText(), new

String(userpas.getPassword()));

if (tem>0) {

zhuye zhuye=new zhuye();

zhuye.userid=tem;

zhuye.show();

ct.dispose();

}

}

}

class tuichulistener implements ActionListener {

@Override

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

System.exit(0);

}

}

}

  • 上一篇:delphi7實現模擬鍵盤按鍵,比如按下v鍵,數字0,回車等
  • 下一篇:怎樣知道自己的前世的身份,誰知道怎樣測試自己的前世啊?
  • copyright 2024編程學習大全網