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