这是一些颂歌,在 fields.getText() 中声明值后,它通过递归函数计算公式。但是java不喜欢在actionPerformed按钮下有任何“公共”。我从来没有使用过其中之一……但是您认为 ActionListener 可以完成这项工作吗?有任何想法吗?
private void calculateButtonActionPerformed(java.awt.event.ActionEvent evt) {
public int Method() { //underlined red
int n = Integer.parseInt(objectsChooseField.getText());
int r = Integer.parseInt(chooseFromField.getText());
int result = C( n, r );
}
public int C( int n, int r ) { //underlined
int res = faculty( n ) / ( faculty( r ) * ( n - r ));
return res;
}
public int faculty( n ) { //underlined
if ( n > 1 )
return n * faculty( n - 1 );
return 1;
}
}
编辑:
我想我可能对乔的回答有点字面意思……但你的意思是这样的……?
public int Method() { //moved above actionPerformed
private void calculateButtonActionPerformed(java.awt.event.ActionEvent evt) {
int n = Integer.parseInt(objectsChooseField.getText()); //continued method?
int r = Integer.parseInt(chooseFromField.getText());
int result = C( n, r );
}
//rest of code below