我在Java awt中用我的简单形式提交了一个特殊文本的奇怪问题。我的代码和结果如下:
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.Panel;
import java.awt.TextField;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Frame;
public class GUI extends Frame {
public static TextField user = null;
public static TextField password = null;
public static TextField base = null;
Label userLabel = null;
Label passwordLabel = null;
Label baseLabel = null;
public GUI(){
this.setSize(260, 160);
this.setTitle("Sybase connection");
this.setResizable(false);
//CLOSE OP
this.addWindowListener(new WindowAdapter(){
public void windowClosing( WindowEvent we){
System.exit(0);
}
});
//LAYOUT
this.setLayout(null);
// FORM PANEL
Panel form = new Panel();
form.setLayout(null);
form.setBackground(new Color(0, 255, 0));
form.setBounds(30,30, 200, 110);
//TEXT/LABEl
userLabel = new Label("User:");
userLabel.setBounds(5, 5, 90, 20);
form.add(userLabel);
passwordLabel = new Label("Password:");
passwordLabel.setBounds(5, 30, 90, 20);
form.add(passwordLabel);
baseLabel = new Label("Base:");
baseLabel.setBounds(5, 55, 90, 20);
form.add(baseLabel);
user = new TextField(20);
user.setBounds(100, 5, 90, 20);
form.add(user);
password = new TextField(20);
password.setBounds(100, 30, 90, 20);
form.add(password);
base = new TextField(20);
user.setBounds(100, 55, 90, 20);
form.add(base);
this.add(form);
//TEXT/LABEL
//BUTTON
//LoginButton b = new LoginButton();
//this.add(b);
//BUTTON
}
public static void main(String[] args) {
GUI frame = new GUI();
frame.setVisible(true);
}
}
结果: enter image description here
那个丑陋的绿色背景仅用于检查面板是否位于一个好位置。你可以看到,其他两个TextField都可以。你有什么想法,为什么第一个不在表格面板?