java swing程序问题,求大神解答啊~我是初学者,实在不知道自己错在哪里??万分感激!!代码在下面:
classStudentextendsJFrameimplementsActionListener{/****/privatestaticfinallongserialV...
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);
}
这段自己写的简单的成绩查询界面,可是为什么运行后是空白的窗口??是不是缺少哪些语句?还是面板的叠加错误了??求救求救。。。 展开
/**
*
*/
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);
}
这段自己写的简单的成绩查询界面,可是为什么运行后是空白的窗口??是不是缺少哪些语句?还是面板的叠加错误了??求救求救。。。 展开
4个回答
展开全部
你的程序我帮你改好了,你看看吧。(改动的地方见注释)
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) {//加上按钮按下处理函数
//这里面填写按钮按下处理语句
}
}
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) {//加上按钮按下处理函数
//这里面填写按钮按下处理语句
}
}
展开全部
你的main方法呢、、、
还有输出语句System.out.println(?);呢、、//?处填想显示的数据
还有输出语句System.out.println(?);呢、、//?处填想显示的数据
追问
mian 方法有啊,这里只是截那段窗口的,输出的还不用,我只是在写个界面先~~可是运行出来时空白的窗口啊
追答
最主要问题是二维数组没初始化、、比如Object a[][]={{1,2,3,4},{3,4,5,1},{1,2,4,6}};
还有其余细节问题,还得你自己好好想想了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
对于父面板要先add()再设置可见
this.setVisible(true);
this.setVisible(true);
追问
照你的说法做了啊亲~可是还是不行啊。。。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
布局问题
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询