我是编程的新手,因为我没有找到解决问题的方法,所以再次发布。我正在编写一个由三个文件组成的简单项目。在主类中,我构建了 gui:
// AlladinLamp.java
import statements go here
public class AlladinLamp {
int fnh;
JComboBox runners;
other variables go here
actionListener and other methods go here, including
public int getFNH() { return fnh; }
ActionListener runnersActionListener = new ActionListener() {
@Override
public void actionPerformed( ActionEvent e ) {
String runnersNumber = ( String )runners.getSelectedItem();
fnh = Integer.parseInt( runnersNumber );
hNam = new String[ fnh ];
hNum = new int[ fnh ];
hVal = new int[ fnh ];
jtxt = new JTextField[ fnh ];
reducedFNH = reduce( fnh );
}
};
public AlladinLamp() {
gui built here...
String[] numberOfRunners = { "8", "9", "10", "11", "12",
"13", "14", "15", "16", "17",
"18", "19", "20", "21", "22" };
runners = new JComboBox( numberOfRunners );
runners.setMaximumRowCount(5);
runners.addActionListener( runnersActionListener );
...
}
public static void main( String args[] ) {
SwingUtilities.invokeLater( new Runnable() {
@Override
public void run() {
AlladinLamp lamp = new AlladinLamp();
}
});
}
另一个文件没有收到跑步者组合框生成的值
// 进程.java
import statements go here
public class Processes {
int fullNH;
AlladinLamp lamp;
public Process() {
lamp = new AlladinLamp();
fullNH = lamp.getFNH();
...
}
第二个文件中没有读取变量 fnh。有人可以建议我做错什么吗?提前致谢。