java swing程序问题,求大神解答啊~我是初学者,实在不知道自己错在哪里??万分感激!!代码在下面:

class Student extends JFrame implements ActionListener{ /** * */ private static final long serialVersionUID = -5234234228112405240L; JTable stuTable; Object a[][]; Object name[]={"学号","姓名","科目","分数"}; JLabel stuLabel0,stuLabel1,stuLabel2,stuLabel3; JButton stuButton0,stuButton1; JPanel stuPan0,stuPan1; JTextField stuField0,stuField1,stuField2;Student(){this.setBounds(200,100,600,600); this.setVisible(true); this.setLayout(null); validate(); stuPan0=new JPanel(null); stuPan0.setBounds(new Rectangle(0, 0, 583, 300)); stuPan1=new JPanel(null); stuPan1.setBounds(new Rectangle(0, 300, 583, 262)); stuTable=new JTable(a,name); stuTable.setBounds(new Rectangle(15, 60, 550, 220)); stuLabel0=new JLabel("课程总分数:"); stuLabel0.setBounds(new Rectangle(175, 75, 100, 30)); stuLabel1=new JLabel("课程平均分:"); stuLabel1.setBounds(new Rectangle(175, 135, 100, 30)); stuLabel2=new JLabel("班级 排名:"); stuLabel2.setBounds(new Rectangle(175, 195, 100, 30)); stuButton0=new JButton("各科成绩"); stuButton1=new JButton("成绩统计"); stuField0=new JTextField(null); stuField0.setBounds(new Rectangle(300, 75, 100, 30)); stuField1=new JTextField(null); stuField1.setBounds(new Rectangle(300, 135, 100, 30)); stuField2=new JTextField(null); stuField2.setBounds(new Rectangle(300, 195, 98, 31)); stuPan0.add(stuButton0); stuPan0.add(stuTable); stuPan1.add(stuButton1); stuPan1.add(stuLabel0); stuPan1.add(stuLabel1); stuPan1.add(stuLabel2); stuPan1.add(stuField0); stuPan1.add(stuField1); stuPan1.add(stuField2); this.add(stuPan0); this.add(stuPan1); validate(); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);}这段自己写的简单的成绩查询界面,可是为什么运行后是空白的窗口??是不是缺少哪些语句?还是面板的叠加错误了??求救求救。。。
2026年09月27日 16:07
有4个网友回答
网友(1):

你的程序我帮你改好了,你看看吧。(改动的地方见注释)
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;
class Student extends JFrame implements ActionListener{
private static final long serialVersionUID = -5234234228112405240L;
JTable stuTable;
Object a[][]={{"10001","张三","物理","85"},{"10002","李四","化学","93"}};//这里为a[][]初始化
Object name[]={"学号","姓名","科目","分数"};
JLabel stuLabel0,stuLabel1,stuLabel2,stuLabel3;
JButton stuButton0,stuButton1;
JPanel stuPan0,stuPan1;
JTextField stuField0,stuField1,stuField2;
JScrollPane scrollPane;//这里加一句

Student(){
this.setLayout(null);
validate();
stuPan0=new JPanel(null);
stuPan0.setBounds(new Rectangle(0, 0, 583, 300));
stuPan1=new JPanel(null);
stuPan1.setBounds(new Rectangle(0, 300, 583, 262));
stuTable=new JTable(a,name);
//stuTable.setBounds();
scrollPane=new JScrollPane(stuTable);//为JTable加上滚动条
scrollPane.setBounds(new Rectangle(15, 60, 550, 220));//这里为JTable设定了位置
stuLabel0=new JLabel("课程总分数:");
stuLabel0.setBounds(new Rectangle(175, 35, 100, 30));//这里纵向位置调整了一下
stuLabel1=new JLabel("课程平均分:");
stuLabel1.setBounds(new Rectangle(175, 95, 100, 30));//这里纵向位置调整了一下
stuLabel2=new JLabel("班级 排名:");
stuLabel2.setBounds(new Rectangle(175, 155, 100, 30));//这里纵向位置调整了一下
stuButton0=new JButton("各科成绩");
stuButton0.setBounds(new Rectangle(175, 200,100, 30));//这里为JButton设定了位置
stuButton1=new JButton("成绩统计");
stuButton1.setBounds(new Rectangle(300, 200, 100, 30));//这里为JButton设定了位置
stuField0=new JTextField(null);
stuField0.setBounds(new Rectangle(300, 35, 100, 30));//这里纵向位置调整了一下
stuField1=new JTextField(null);
stuField1.setBounds(new Rectangle(300, 95, 100, 30));//这里纵向位置调整了一下
stuField2=new JTextField(null);
stuField2.setBounds(new Rectangle(300, 155, 98, 31));//这里纵向位置调整了一下
stuPan1.add(stuButton0);//这里把stuButton0加入到stuPan1中
stuPan0.add(scrollPane);//这里把JTable加入到 stuPan0中
stuPan1.add(stuButton1);
stuPan1.add(stuLabel0);
stuPan1.add(stuLabel1);
stuPan1.add(stuLabel2);
stuPan1.add(stuField0);
stuPan1.add(stuField1);
stuPan1.add(stuField2);
this.add(stuPan0);
this.add(stuPan1);
stuButton0.addActionListener(this);//这里加上按钮监听器
stuButton1.addActionListener(this);//这里加上按钮监听器
validate();
setBounds(200,100,600,600);//这一句从上面移下来
setVisible(true);//这一句从上面移下来
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}
public static void main(String [] args){ //加上主函数
new Student();
}
public void actionPerformed(ActionEvent arg0) {//加上按钮按下处理函数
//这里面填写按钮按下处理语句
}
}

网友(2):

你的main方法呢、、、
还有输出语句System.out.println(?);呢、、//?处填想显示的数据

网友(3):

对于父面板要先add()再设置可见
this.setVisible(true);

网友(4):

布局问题