我遇到了代码问题...
package application;
import java.net.URL;.... more import statements
public class MainController{
@FXML
private Label lblStatus;
@FXML
private TextField txtUsername;
@FXML
private TextField txtPassword;
/*This method allows user login and when login is successful then user is taken to the main screen.*/
public void Login (ActionEvent event) throws Exception {
if (txtUsername.getText().equals("user") && txtPassword.getText().equals("pass")) {
lblStatus.setText("Login Success");
Stage primaryStage = new Stage();
Parent root = FXMLLoader.load(getClass().getResource("/application/RestScene.fxml"));
Scene scene = new Scene(root,400,400);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setTitle("Restaurant Advisor");
primaryStage.setScene(scene);
primaryStage.show();
}
else
{
lblStatus.setText("Login Failed");
}
}
//Button for Makiyaki
public void changeScreenButtonPushed(ActionEvent event) throws Exception {
Parent Makiyaki = FXMLLoader.load(getClass().getResource("Makiyaki.fxml"));
Scene MakiyakiSCN = new Scene(Makiyaki);
Stage MakiyakiWNDW = (Stage)((Node)event.getSource()).getScene().getWindow();
MakiyakiWNDW.setScene(MakiyakiSCN);
MakiyakiWNDW.show();
}
//Button for Qdoba
public void changeScreenButtonPushed2(ActionEvent event) throws Exception {
Parent Qdoba = FXMLLoader.load(getClass().getResource("Qdoba.fxml"));
Scene QdobaSCN = new Scene(Qdoba);
Stage QdobaWNDW = (Stage)((Node)event.getSource()).getScene().getWindow();
QdobaWNDW.setScene(QdobaSCN);
QdobaWNDW.show();
}
//Button for Ian's
public void changeScreenButtonPushed3(ActionEvent event) throws Exception {
Parent Ian = FXMLLoader.load(getClass().getResource("Ian's.fxml"));
Scene IanSCN = new Scene(Ian);
Stage IanWNDW = (Stage)((Node)event.getSource()).getScene().getWindow();
IanWNDW.setScene(IanSCN);
IanWNDW.show();
}
//Button for Build-a-Burger
public void changeScreenButtonPushed4(ActionEvent event) throws Exception {
Parent BBurger = FXMLLoader.load(getClass().getResource("Build-a-Burger.fxml"));
Scene BBurgerSCN = new Scene(BBurger);
Stage BBurgerWNDW = (Stage)((Node)event.getSource()).getScene().getWindow();
BBurgerWNDW.setScene(BBurgerSCN);
BBurgerWNDW.show();
}
public void changeScreenButtonPushed5(ActionEvent event) throws Exception {
Parent Kawa= FXMLLoader.load(getClass().getResource("Kawa.fxml"));
Scene KawaSCN = new Scene(Kawa);
Stage KawaWNDW = (Stage)((Node)event.getSource()).getScene().getWindow();
KawaWNDW.setScene(KawaSCN);
KawaWNDW.show();
}
//Table for ratings, in progress
@FXML
public TableView<Table> tableview;
@FXML
public TableColumn<Table, String> colNam;
@FXML
public TableColumn<Table, Integer> colRat;
@FXML
public TableColumn<Table, String>colRest;
@FXML
public TextField txtFieldName;
@FXML
public TextField txtFieldRating;
@FXML
public TextField txtFieldRestaurant;
public void initialize(URL location, ResourceBundle resources) {
colNam.setCellValueFactory(new PropertyValueFactory<>("TableName"));
colRat.setCellValueFactory(new PropertyValueFactory<>("TableRating"));
colRest.setCellValueFactory(new PropertyValueFactory<>("TableRestaurants"));
tableview.setItems(observableList);
}
//Menu items? in progress
ObservableList<Table> observableList = FXCollections.observableArrayList(
new Table ("Test", 1, "makiyaki"));
@FXML
public void buttonSubmit(ActionEvent event) {
Table table = new Table (txtFieldName.getText(), Integer.parseInt(txtFieldRating.getText()), txtFieldRestaurant.getText());
tableview.getItems().add(table);
}
ObservableList list = FXCollections.observableArrayList();
@FXML
public ListView<String> menuMakList;
void initialize1(URL location, ResourceBundle resources) {
loadMenuMak();
}
public void loadMenuMak() {
list.removeAll(list);
String rest1 = "Build-a-Burger";
String rest2 = "Ian's Pizza";
String rest3 = "Makiyaki";
String rest4 = "Insomnia Cookies";
String rest5 = "Jimmy John's";
String rest6 = "Five Guys";
list.addAll(rest1,rest2,rest3,rest4,rest5,rest6);
menuMakList.getItems().addAll(list);
}
}
我的问题是,由于我的登录方法最终无法正常工作,因此无法初始化该类。我正在尝试初始化表格视图和列表视图方法。我该怎么做?我想做的是让用户将数据实现到表视图中,而我想手动将数据插入到列表视图中。我将我遇到最大麻烦的人标记为“进行中”