我的这个JPanel上为什么不显示JLabel上的内容?
importjavax.swing.*;importjava.awt.*;publicclassLoginextendsJFrame{/***@paramargs*/JL...
import javax.swing.*;
import java.awt.*;
public class Login extends JFrame{
/**
* @param args
*/
JLabel title,username,password;
JTextField usernameBox,passwordBox;
JPanel p;
public Login()
{
this.setSize(400, 300);
this.setTitle("用户登录页面");
setMiddScree();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
p=new JPanel();
this.getContentPane().add(p);
title=new JLabel();
title.setFont(new Font("宋体",Font.BOLD,18));
title.setForeground(Color.blue);
title.setSize(200, 40);
title.setBounds(20, 20, 300, 40);
p.add(title);
//usernameBox=new JTextField();
}
void setMiddScree()//设置屏幕大小
{
Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize=this.getSize();
if(frameSize.height>screenSize.height)
{
frameSize.height=screenSize.height;
}
if(frameSize.width>screenSize.width)
{
frameSize.width=screenSize.width;
}
this.setLocation((screenSize.width-frameSize.width)/2,(screenSize.height-frameSize.height)/2);
this.setVisible(true);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Login login=new Login();
}
} 展开
import java.awt.*;
public class Login extends JFrame{
/**
* @param args
*/
JLabel title,username,password;
JTextField usernameBox,passwordBox;
JPanel p;
public Login()
{
this.setSize(400, 300);
this.setTitle("用户登录页面");
setMiddScree();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
p=new JPanel();
this.getContentPane().add(p);
title=new JLabel();
title.setFont(new Font("宋体",Font.BOLD,18));
title.setForeground(Color.blue);
title.setSize(200, 40);
title.setBounds(20, 20, 300, 40);
p.add(title);
//usernameBox=new JTextField();
}
void setMiddScree()//设置屏幕大小
{
Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize=this.getSize();
if(frameSize.height>screenSize.height)
{
frameSize.height=screenSize.height;
}
if(frameSize.width>screenSize.width)
{
frameSize.width=screenSize.width;
}
this.setLocation((screenSize.width-frameSize.width)/2,(screenSize.height-frameSize.height)/2);
this.setVisible(true);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Login login=new Login();
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询