javafx - 我不能在 AccountController 中为全名和钱设置文本。错误代码是“不能从静态上下文引用非静态变量”
问题描述
我不能用静态设置文本。请帮我在 AccountController 中设置全名和钱的文本。请让我举几个例子
我将 String full1 和 String money 从 Menu 传递到 Account 并设置 Text 有错误
菜单控制器类
public class MenuController implements Initializable {
@FXML
private Text nameuser;
String account;
void setData(String fullname, String username) {
nameuser.setText(fullname);
account = username;
}
@FXML
private void btnsp(ActionEvent event) throws Exception {
try {
Connection con;
con = Connect.Connect();
PreparedStatement pstm = con.prepareStatement("select fullname, money from account where username = ?");
pstm.setString(1, account);
ResultSet result = pstm.executeQuery();
if(result.next()) {
System.out.println(result.getString(1));
System.out.println(result.getString(2));
} else {
System.out.println("Fail!");
}
String fullname1 = result.getString(1);
String money = result.getString(2);
FXMLLoader loader = new FXMLLoader(getClass().getResource("Account.fxml"));
Parent root = loader.load();
Scene scene = new Scene(root);
Stage app_stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
AccountController MenuController = loader.<AccountController>getController();
AccountController.setData(fullname1, money);
app_stage.hide();
app_stage.setScene(scene);
app_stage.show();
} catch (SQLException ex) {
System.out.println("SQLException");
System.out.println("Error message: " + ex);
}
}
}
帐户控制器类
public class AccountController implements Initializable {
@FXML
private Text fullname;
@FXML
private Text money;
static void setData(String fullname1, String money) {
fullname.setText(fullname1);
fullname.setText(money);
}
}
解决方案
推荐阅读
- c++ - 访问数据库 - QODBC 驱动程序在管理员上执行授权
- swift - Swift 中的元组与对象
- ngx-restangular - 无法在 ionic 4 项目上工作的 ngx-restangular 出现错误:找不到模块“core-js/fn/object”
- xml - 如何从xslt中的嵌套标签中提取子元素
- javascript - 提高 Angular 应用程序的 Docker 构建速度
- stm32 - lm35 上的 GSM 噪音
- c++ - 如果 X 是某个有序容器 S 的迭代器 S.begin(),那么 prev(X) 是什么,例如 S 是一个集合?
- html - 如何在ui中显示渲染的html文本?
- c++ - (c++) 打印字符数组字符串的单词问题
- c++ - C++中同一函数的多个定义