标题:又遇到问题了,请教一下。关于JFrame容器添加组件的.
只看楼主
极速尽
Rank: 1
等 级:新手上路
帖 子:59
专家分:0
注 册:2005-8-13
 问题点数:0 回复次数:2 
又遇到问题了,请教一下。关于JFrame容器添加组件的.

想做一个有界面的,公制和英制转换的.
遇到一个问题.添加组件到容器的时候用的方法是从书上看来的.
错误提示是要我加")".
环境里好象没有识别这个方法.
具体代码如下,希望大家有空指点一下.不要笑话我.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Conversion extends JFrame{
private static final double KILOMETERS_PER_GALLON=1.609344;
private static final double LITERS_PER_GALLON=3.785411784;
private static final double GRAMS_PER_OUNCE=28.349523125;
private static final double HECTARES_PER_ACRE=0.40468564;
GridBagConstraints gbc;
GridBagLayout gb;
public Conversion(){
MyPanel mp=new MyPanel();
Container con=getContentPane();
con.setLayout(gb);

gbc=new GridBagConstraints();

JTextField texMile=new JTextField();
JTextField texGallon=new JTextField();
JTextField texOunce=new JTextField();
JTextField texAcre=new JTextField();

JLable lbMile=new JLable("=");
JLable lbGallon=new JLable("=");
JLable lbOunce=new JLable("=");
JLable lbAcre=new JLable("=");

JTextField texKillometers=new JTextField();
JTextField texLiters=new JTextField();
JTextField texGrams=new JTextField();
JTextField texHectares=new JTextField();

gbc.fill=GridBagConstraints.HORIZONTAL;
addComponent(texMile,0,0,2,1);
gbc.fill=GridBagConstraints.HORIZONTAL;
addComponent(lbMile,0,1,2,1);


}

public void addComponent( Component c,int row,int col,int nrow,int,ncol ){
gbc.gridx = row;
gbc.gredy = col;

gbc.gridwidth=ncol;
gbc.gridheight=nrow;

gb.setConstraints(c,gbc);
add(c);
}

}
还没有完成.就是方法addComponent提示有问题.

搜索更多相关主题的帖子: JFrame 组件 容器 
2006-01-29 02:37
牛虻
Rank: 1
等 级:新手上路
威 望:1
帖 子:472
专家分:0
注 册:2004-10-1
得分:0 
//there are so much mistakes in yr code ,
//i use red color to mark them all ,
//hope u can do it better next time^_^
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Conversion extends JFrame{
private static final double KILOMETERS_PER_GALLON=1.609344;
private static final double LITERS_PER_GALLON=3.785411784;
private static final double GRAMS_PER_OUNCE=28.349523125;
private static final double HECTARES_PER_ACRE=0.40468564;
GridBagConstraints gbc;
GridBagLayout gb;
public Conversion(){
MyPanel mp=new MyPanel(); //MyPanel must be yr owen class,right?
Container con=getContentPane();
con.setLayout(gb);

gbc=new GridBagConstraints();

JTextField texMile=new JTextField();
JTextField texGallon=new JTextField();
JTextField texOunce=new JTextField();
JTextField texAcre=new JTextField();

JLable lbMile=new JLable("="); //all of 'JLable' should be 'JLabel'
JLable lbGallon=new JLable("=");
JLable lbOunce=new JLable("=");
JLable lbAcre=new JLable("=");

JTextField texKillometers=new JTextField();
JTextField texLiters=new JTextField();
JTextField texGrams=new JTextField();
JTextField texHectares=new JTextField();

gbc.fill=GridBagConstraints.HORIZONTAL;
addComponent(texMile,0,0,2,1);
gbc.fill=GridBagConstraints.HORIZONTAL;
addComponent(lbMile,0,1,2,1);


}

public void addComponent( Component c,int row,int col,int nrow,int,ncol ){ //an unnecessary comma
gbc.gridx = row;
gbc.gredy = col; //should be gbc.gridy

gbc.gridwidth=ncol;
gbc.gridheight=nrow;

gb.setConstraints(c,gbc);
add(c);
}

}

[此贴子已经被作者于2006-1-29 13:36:37编辑过]


土冒
2006-01-29 13:35
极速尽
Rank: 1
等 级:新手上路
帖 子:59
专家分:0
注 册:2005-8-13
得分:0 
首先我没有写注释,给帮忙的兄弟,带来困难,先抱歉一个,以后一定注意.写的清楚.
感谢楼上的,这么热心.

唉,又是拼写错误,真不知道我这么粗心,能不能做个称职的程序员.

2006-01-31 00:39



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-44154-1-1.html




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

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