我写了一个涉及JSwing界面的代码 但是不知道为何其中一个JPanel容器不能显示出来 用的是null布局
不过把它改成FlowLayout布局就可以显示出来 问题出在哪里呢?
下面附上代码:import java.awt.*;
import java.awt.event.*;
import javax.swing.*;class student extends JFrame {
public JFrame frame;
public JPanel p1,p2;
public JLabel idL=new JLabel("学号:");
public JLabel nameL=new JLabel("姓名:");
public JLabel sexL=new JLabel("性别:");
public JTextField idT=new JTextField();
public JTextField nameT=new JTextField();
public JTextField sexT=new JTextField();
public JButton query=new JButton("查询");
public JButton add=new JButton("添加");
public JButton delete=new JButton("删除");
public JButton modify=new JButton("修改");
public void student123(){
frame=new JFrame("STUDENT子表查询");
p1=new JPanel();
p2=new JPanel();
p1.setLayout(new FlowLayout());
p2.setLayout(null);
p1.add(query);
p1.add(add);
p1.add(delete);
p1.add(modify);
idL.setLocation(35,40);
idL.setSize(40,20);
idT.setLocation(90,40);
idT.setSize(200,20);
nameL.setLocation(35,70);
nameL.setSize(40,20);
nameT.setLocation(90,70);
nameT.setSize(200,20);
sexL.setLocation(35,100);
sexL.setSize(40,20);
sexT.setLocation(90,100);
sexT.setSize(40,20);
p2.add(idL);
p2.add(idT);
p2.add(nameL);
p2.add(nameT);
p2.add(sexL);
p2.add(sexT);
frame.getContentPane().setLayout(new FlowLayout());
frame.setSize(400,400);
frame.setLocation(10,210);
frame.getContentPane().add(p1);
frame.getContentPane().add(p2);
frame.setVisible(true);
}
public static void main(String args[]){
student frame=new student();
frame.student123();
}
}
本来是做个简单数据库查询的 代码比较长 为了方便各位大大看 我自己把界面部分截了下来
不过把它改成FlowLayout布局就可以显示出来 问题出在哪里呢?
下面附上代码:import java.awt.*;
import java.awt.event.*;
import javax.swing.*;class student extends JFrame {
public JFrame frame;
public JPanel p1,p2;
public JLabel idL=new JLabel("学号:");
public JLabel nameL=new JLabel("姓名:");
public JLabel sexL=new JLabel("性别:");
public JTextField idT=new JTextField();
public JTextField nameT=new JTextField();
public JTextField sexT=new JTextField();
public JButton query=new JButton("查询");
public JButton add=new JButton("添加");
public JButton delete=new JButton("删除");
public JButton modify=new JButton("修改");
public void student123(){
frame=new JFrame("STUDENT子表查询");
p1=new JPanel();
p2=new JPanel();
p1.setLayout(new FlowLayout());
p2.setLayout(null);
p1.add(query);
p1.add(add);
p1.add(delete);
p1.add(modify);
idL.setLocation(35,40);
idL.setSize(40,20);
idT.setLocation(90,40);
idT.setSize(200,20);
nameL.setLocation(35,70);
nameL.setSize(40,20);
nameT.setLocation(90,70);
nameT.setSize(200,20);
sexL.setLocation(35,100);
sexL.setSize(40,20);
sexT.setLocation(90,100);
sexT.setSize(40,20);
p2.add(idL);
p2.add(idT);
p2.add(nameL);
p2.add(nameT);
p2.add(sexL);
p2.add(sexT);
frame.getContentPane().setLayout(new FlowLayout());
frame.setSize(400,400);
frame.setLocation(10,210);
frame.getContentPane().add(p1);
frame.getContentPane().add(p2);
frame.setVisible(true);
}
public static void main(String args[]){
student frame=new student();
frame.student123();
}
}
本来是做个简单数据库查询的 代码比较长 为了方便各位大大看 我自己把界面部分截了下来
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货