| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 708 人关注过本帖
标题:关于JAVA界面程序的问题,谁会啊
只看楼主 加入收藏
xiao8988
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2006-1-23
收藏
 问题点数:0 回复次数:5 
关于JAVA界面程序的问题,谁会啊

这是我写的一个学员管理的界面程序,有个错误我一直解决不了,希望大家帮忙

搜索更多相关主题的帖子: JAVA 界面 
2006-01-23 17:34
EA_Games
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:539
专家分:0
注 册:2005-3-13
收藏
得分:0 
不说出来谁都解决不了

2006-01-24 01:20
xiao8988
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2006-1-23
收藏
得分:0 

就是这个代码,大家帮我看看吧.(有点长...)

谢谢


import javax.swing.*;
import java.awt.*;
class FrameTest extends JFrame
{

public FrameTest()
{
super("学员信息");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
setSize(400,300);
}
}
class PanelTest
{
JPanel mp;
JPanel p1;
JPanel p2;
JPanel p3;
JPanel p4;
JPanel p5;
JPanel p6;
JPanel p7;

public PanelTest()
{
mp=new JPanel();
p1=new JPanel();
p2=new JPanel();
p3=new JPanel();
p4=new JPanel();
p5=new JPanel();
p6=new JPanel();
p7=new JPanel();
getContentPane().add(mp);
}
}
class ConTest extends PanelTest
{
JLabel lH;
JLabel lN;
JLabel lA;
JLabel lS;
JLabel lG;
JLabel lD;
JLabel lT;
JCheckBox cBox;
JTextField tN;
JTextField tA;
JRadioButton r1;
JRadioButton r2;
JList iG;
JScrollPane sc; //列表滚动条
JComboBox cDep;
JTable ta;
JScrollPane st; //表格滚动条
JButton b1;
JButton b2;
public ConTest()
{
//主要面板
lH=new JLabel("----------学员信息编辑器------------"); //标题行控件
mp.add(lH);
cBox=new JCheckBox("是否注册",false);
mp.add(cBox); //复选框

//GridBag布局 添加子面板1上的姓名标签和文本框
GridBagLayout lay1=new GridBagLayout();
GridBagConstraints gbc1=new GridBagConstraints();
p1.setLayout(lay1);
lN=new JLabel("姓名:");
gbc1.anchor=GridBagConstraints.EAST;
lay1.setConstraints(lN,gbc1);
tN=new JTextField(15);
tN.setEnabled(false);
gbc1.anchor=GridBagConstraints.WEST;
lay1.setConstraints(tN,gbc1);
p1.add(lN);
p1.add(tN);
mp.add(p1);

//GridBag布局 添加子面板2上的年龄标签和文本框
GridBagLayout lay2=new GridBagLayout();
GridBagConstraints gbc2=new GridBagConstraints();
p2.setLayout(lay2);
lA=new JLabel(" 年龄:");
gbc2.anchor=GridBagConstraints.EAST;
lay2.setConstraints(lA,gbc2);
tA=new JTextField(3);
tA.setEnabled(false);
gbc2.anchor=GridBagConstraints.WEST;
lay2.setConstraints(tA,gbc2);
p2.add(lA);
p2.add(tA);
mp.add(p2);

//GridBag布局 添加子面板3上的性别标签和单选按钮
GridBagLayout lay3=new GridBagLayout();
GridBagConstraints gbc3=new GridBagConstraints();
p3.setLayout(lay3);
lS=new JLabel("性别:");
gbc3.anchor=GridBagConstraints.EAST;
gbc3.gridx=0;
gbc3.gridy=0;
lay3.setConstraints(lS,gbc3);
r1=new JRadioButton("男 ",true);
r1.setEnabled(false);
gbc3.anchor=GridBagConstraints.WEST;
gbc3.gridx=1;
gbc3.gridy=0;
lay3.setConstraints(r1,gbc3);
r2=new JRadioButton("女 ",false);
r2.setEnabled(false);
gbc3.anchor=GridBagConstraints.WEST;
gbc3.gridx=1;
gbc3.gridy=1;
lay3.setConstraints(r2,gbc3);
ButtonGroup bg=new ButtonGroup();
bg.add(r1);
bg.add(r2);
p3.add(lS);
p3.add(r1);
p3.add(r2);
mp.add(p3);

//GridBag布局 添加子面板4上的年级标签和列表框
GridBagLayout lay4=new GridBagLayout();
GridBagConstraints gbc4=new GridBagConstraints();
p4.setLayout(lay4);
lG=new JLabel("年级:");
gbc4.anchor=GridBagConstraints.EAST;
gbc4.gridheight=1;
lay4.setConstraints(lG,gbc4);
String[] str1={"一年级","二年级","三年级","四年级"};
iG=new JList(str1);
iG.setEnabled(false);
iG.setFixedCellWidth(80);
iG.setVisibleRowCount(4);
sc=new JScrollPane(iG,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
gbc4.anchor=GridBagConstraints.WEST;
gbc4.weightx=1.0;
gbc4.weighty=0.0;
gbc4.gridheight=4;
lay4.setConstraints(sc,gbc4);
p4.add(lG);
p4.add(sc);
mp.add(p4);

//GridBag布局 添加子面板5上的系别标签和下拉列表框
GridBagLayout lay5=new GridBagLayout();
GridBagConstraints gbc5=new GridBagConstraints();
p5.setLayout(lay5);
lD=new JLabel("系别:");
gbc5.anchor=GridBagConstraints.EAST;
lay5.setConstraints(lD,gbc5);
String[] str2={"计算机系","英语系","机械系","建筑系"};
cDep=new JComboBox(str2);
cDep.setEnabled(false);
gbc5.anchor=GridBagConstraints.WEST;
lay5.setConstraints(cDep,gbc5);
p5.add(lD);
p5.add(cDep);
mp.add(p5);

//边界布局 添加子面板6上的表格标签和表格
BorderLayout blay=new BorderLayout();
p6.setLayout(blay);
lT=new JLabel("显示已注册学员的所有信息:");
String[][] data=
{
{"阿龙","35","男","一年级","计算机系"},
{" "," "," "," ","计算机系"},
{" "," "," "," ","计算机系"},
{" "," "," "," ","计算机系"},
{" "," "," "," ","计算机系"},
{" "," "," "," ","计算机系"}
};
String[] names={"姓名","年龄","性别","年级","系别"};
ta=new JTable(data,names);
ta.setEnabled(false);
Dimension dim=new Dimension(380,60);
ta.setPreferredScrollableViewportSize(dim);
st=new JScrollPane(ta);
p6.add("North",lT);
p6.add("Center",st);
mp.add(p6);

//流布局P7上的两个按钮
FlowLayout flay;
flay=new FlowLayout(FlowLayout.RIGHT,10,15);
p7.setLayout(flay);
b1=new JButton("注册(Z)");
b1.setEnabled(false);
b2=new JButton("保存(S)");
b2.setEnabled(false);
p7.add(b1);
p7.add(b2);
mp.add(p7);

//GridBag布局 添加主面板上的两个控件和容器面板
GridBagLayout glay=new GridBagLayout();
GridBagConstraints gbc=new GridBagConstraints();
mp.setLayout(glay);
gbc.gridwidth=GridBagConstraints.REMAINDER;
gbc.anchor=GridBagConstraints.NORTHWEST;
glay.setConstraints(lH,gbc);
gbc.gridwidth=1;
glay.setConstraints(cBox,gbc);
glay.setConstraints(p1,gbc);
gbc.gridwidth=GridBagConstraints.REMAINDER;
glay.setConstraints(p2,gbc);
gbc.gridwidth=1;
glay.setConstraints(p3,gbc);
glay.setConstraints(p4,gbc);
gbc.gridwidth=GridBagConstraints.REMAINDER;
glay.setConstraints(p5,gbc);
gbc.gridwidth=GridBagConstraints.REMAINDER;
glay.setConstraints(p5,gbc);
gbc.anchor=GridBagConstraints.NORTHEAST;
gbc.gridwidth=GridBagConstraints.REMAINDER;

}

}
public class XueYuan
{
public static void main(String[] args)
{
new FrameTest();
ConTest f=new ConTest();


}
}

2006-01-24 11:28
bagger
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:33
帖 子:891
专家分:0
注 册:2005-8-16
收藏
得分:0 
一个文件中只能有一个是PUBLIC的CLASS,你的文件里有两个!
还有getContentPane()不是静态方法,不能直接使用,必须得有JFRAME的实例才能调用这个方法!
大概就是这样!

【三元毕业设计论文】
三元论文真的只有三元钱
客服QQ:742670649
http://shop35094218./
2006-01-24 14:00
飘飘叶子
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:34
帖 子:597
专家分:10
注 册:2005-8-17
收藏
得分:0 

你的类没有继承JFrame,却使用getContentPane()方法,当然会出错


向着软件工程师的目标前进!
2006-01-24 15:44
weizheng
Rank: 1
等 级:新手上路
威 望:2
帖 子:286
专家分:0
注 册:2005-4-21
收藏
得分:0 
应该还可以这样解决吧:
Container cp = getContentPane();
cp.add(mp);

温和如玉,完美纯正。
2006-01-24 19:26
快速回复:关于JAVA界面程序的问题,谁会啊
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019293 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved