我正在为各个城市之间的距离创建一个转换计算器。但是我在如何从转换方法调用计算时遇到问题。比如这里:
private class ComboBoxListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
int selectedRow = destinationBox.getSelectedIndex();
int selectedCol = originBox.getSelectedIndex();
distanceText.setText(fileData[selectedRow + 1][selectedCol + 1]);
}
}
private class RadioButtonListener implements ActionListener
{
public void actionPerformed (ActionEvent event)
{
if (event.getSource() == kilometersRadioButton)
{
distanceLabel.setText("Distance (kilometers):");
avgspeedLabel.setText("Avg. Speeg (kph): ");
}
else if (event.getSource() == milesRadioButton)
{
distanceLabel.setText("Distance (miles): ");
avgspeedLabel.setText("Avg. Speeg (mph): ");
}
}
}
这部分是二维数组选择值的地方,我的目的是在单击单选按钮时进行从英里到公里的计算。我从中绘制的文件默认以英里为单位。
public class MetricConverter
{
public static double milesToKilometers(double miles) //This static method holds the miles to kilometers conversion equation
{
return miles * 1.609;
}
public static double kilometersToMiles(double kilometers) //This static method holds the kilometers to miles conversion equation
{
return kilometers / 1.609;
}
}
这是转换方法。我如何称呼它们,因为数组的值在 TextField/String 中。
谢谢你,