ネタ心者歓迎! 今更ながらにJava相談室

このエントリーをはてなブックマークに追加
145デフォルトの名無しさん
すいません、教えてください!!!コンパイルできないんです!!外部の独立したリスナーにしたいんですけど・・・・

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

class Kadai5a extends JPanel{
Person hito;
JTextField hField, wField;
JLabel hyoujun, hantei, himando, message;
JPanel dataPanel;
OutListener listener;
Kadai5a(){
message = new JLabel(" ");
dataPanel = new JPanel();
setLayout(new BorderLayout());
add(message, BorderLayout.WEST);
add(dataPanel,BorderLayout.SOUTH);

hField = new JTextField(10);
wField = new JTextField(10);
hyoujun = new JLabel();
hantei = new JLabel();
himando = new JLabel();
listener = new OutListener(this);
hField.addActionListener(listener);
wField.addActionListener(listener);
dataPanel.setBackground(Color.white);
dataPanel.setLayout(new GridLayout(5,2));
dataPanel.add(new JLabel("身長(cm)"));
dataPanel.add(hField);
dataPanel.add(new JLabel("体重(Kg)"));
dataPanel.add(wField);
dataPanel.add(new JLabel("標準体重(Kg)"));
dataPanel.add(hyoujun);
dataPanel.add(new JLabel("BMI(理想値:22)"));
dataPanel.add(hantei);
dataPanel.add(new JLabel("肥満度(%)"));
dataPanel.add(himando);

hito = new Person();
}
public static void main(String args[]) {
JFrame f = new JFrame("Himando");
Kadai5a h = new Kadai5a();
Container c = f.getContentPane();
c.add(h, BorderLayout.CENTER);
f.pack();
f.setVisible(true);
}
}
146続き:01/11/02 16:36
class OutListener implements ActionListener{
Kadai5a kadai;
public OutListener(Kadai5a h){
kadai = h;
}


public void actionPerformed(ActionEvent e){
float fHeight, fWeight;
try{
fHeight = Float.parseFloat(kadai.hField.getText());
}
catch (NumberFormatException error){
fHeight = 0.0F;
}
kadai.hito.setHeight(fHeight);
try{
fWeight = Float.parseFloat(kadai.wField.getText());
}
catch (NumberFormatException error){
fWeight = 0.0F;
}
kadai.hito.setWeight(fWeight);
if(e.getSource() == kadai.hField) {
if(fHeight <= 0) {
message.setText("正しい数値を入力してください");
kadai.hField.requestFocus();
}
else {
message.setText(" ");
kadai.wField.requestFocus();
}
}
else if(e.getSource() == kadai.wField) {
if(fWeight <= 0) {
message.setText("正しい数値を入力してください");
kadai.wField.requestFocus();
}
else {
message.setText(" ");
kadai.hField.requestFocus();
}
}
if( (fHeight > 0) && (fWeight > 0) ){
kadai.hyoujun.setText(Float.toString(hito.calcStdWeight()));
kadai.hantei.setText (Float.toString(hito.calcBMI()));
kadai.himando.setText(Float.toString(hito.calcHimando()*100));
}
}
}
147続き:01/11/02 16:36

class Person{
private float weight;
private float height;

float getWeight() { return weight; }
float getHeight() { return height; }
void setWeight(float w) { weight = w; }
void setHeight(float h) { height = h; }

float calcStdWeight(){
return (height*height*22/10000F);
}

float calcBMI(){
return (weight*100F*100F/height/height);
}

float calcHimando(){
float bmi = calcBMI();
return (bmi-22)/22;
}
}
148145,146,147:01/11/02 16:37
どこが間違っているんですかね????教えてください、お願いします!!