【求救!】JAVA中我的简单的GUI为什么显示不出来!
importjavax.swing.*;publicclassMainFrameextendsJFrame{privateJTextFieldtf_IPAddress=n...
import javax.swing.*;
public class MainFrame extends JFrame
{
private JTextField tf_IPAddress = new JTextField(10);
private JTextField tf_Port = new JTextField(5);
private JTextField tf_Username = new JTextField(10);
private JTextField tf_password = new JTextField(10);
private JLabel IPAddress = new JLabel("主机名或URL");
private JLabel Username = new JLabel("登录ID");
private JLabel password = new JLabel("密码");
private JLabel Port = new JLabel("端口");
private JButton Login = new JButton("确认登录");
public MainFrame()
{
this.setLayout(null);
this.setTitle("登录界面");
IPAddress.setBounds(500, 100, 150, 50);
Port.setBounds(500, 160, 150, 50);
Username.setBounds(500, 220, 150, 50);
password.setBounds(500, 280, 150, 50);
tf_IPAddress.setBounds(680, 100, 150, 50);
tf_Port.setBounds(680, 160, 50, 50);
tf_Username.setBounds(680, 220, 150, 50);
tf_password.setBounds(680, 280, 150, 50);
this.add(IPAddress);
this.add(Port);
this.add(Username);
this.add(password);
this.add(tf_IPAddress);
this.add(tf_Port);
this.add(tf_Username);
this.add(tf_password);
this.setBounds(450, 50, 500, 500);
this.setVisible(true);
}
public static void main(String[] args)
{
new MainFrame();
}
}
谢谢帮我看下~ 展开
public class MainFrame extends JFrame
{
private JTextField tf_IPAddress = new JTextField(10);
private JTextField tf_Port = new JTextField(5);
private JTextField tf_Username = new JTextField(10);
private JTextField tf_password = new JTextField(10);
private JLabel IPAddress = new JLabel("主机名或URL");
private JLabel Username = new JLabel("登录ID");
private JLabel password = new JLabel("密码");
private JLabel Port = new JLabel("端口");
private JButton Login = new JButton("确认登录");
public MainFrame()
{
this.setLayout(null);
this.setTitle("登录界面");
IPAddress.setBounds(500, 100, 150, 50);
Port.setBounds(500, 160, 150, 50);
Username.setBounds(500, 220, 150, 50);
password.setBounds(500, 280, 150, 50);
tf_IPAddress.setBounds(680, 100, 150, 50);
tf_Port.setBounds(680, 160, 50, 50);
tf_Username.setBounds(680, 220, 150, 50);
tf_password.setBounds(680, 280, 150, 50);
this.add(IPAddress);
this.add(Port);
this.add(Username);
this.add(password);
this.add(tf_IPAddress);
this.add(tf_Port);
this.add(tf_Username);
this.add(tf_password);
this.setBounds(450, 50, 500, 500);
this.setVisible(true);
}
public static void main(String[] args)
{
new MainFrame();
}
}
谢谢帮我看下~ 展开
2个回答
展开全部
窗体大小是500x500,文本框和按钮的坐标是大于500显示的
下面的代码改成这样
IPAddress.setBounds(0, 100, 150, 50);
Port.setBounds(0, 160, 150, 50);
Username.setBounds(0, 220, 150, 50);
password.setBounds(0, 280, 150, 50);
tf_IPAddress.setBounds(180, 100, 150, 50);
tf_Port.setBounds(180, 160, 50, 50);
tf_Username.setBounds(180, 220, 150, 50);
tf_password.setBounds(180, 280, 150, 50);
追问
啊我哦明白了
是不是 this.setBounds(450, 50, 500, 500); 里的x 和y 是 屏幕的坐标
而IPAddress.setBounds(0, 100, 150, 50); 里的x 和Y是基于 主窗口的坐标?
追答
是的
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询