Guest User

Untitled

a guest
Mar 18th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. if (button.id == Info_205_btn) {
  2. System.out.println("clicked");
  3. subject_name.setText("stanly");
  4. }
  5.  
  6. @FXML
  7. private void chooseSubject() {
  8. for (int i = 0; i < buttonInfo.length; i++) {
  9. buttonInfo[i] = new Button("Info"+i);
  10. buttonInfo[i].setId("Info"+i);
  11. int finalI = i;
  12. buttonInfo[i].setOnAction(event -> checkID(buttonInfo[finalI]));
  13. }
  14. }
  15.  
  16.  
  17. @FXML
  18. private void checkID(Button button){
  19. System.out.println("running");
  20.  
  21. if (button.getId().equals("Info0")) {
  22. System.out.println("clicked");
  23. subject_name.setText("stanly");
  24. }
  25. else if (button.getId().equals("Info1")) {
  26. System.out.println("clicked");
  27. subject_name.setText("stanly1");
  28. }
  29. }
  30.  
  31.  
  32. @Override
  33. public void initialize(URL url, ResourceBundle rb) {
  34. chooseSubject();
  35. }
  36.  
  37. button.setOnAction(event -> checkID(button));
  38.  
  39. private void checkID(Button button){
  40. if (button.getId().equals("Info_205_btn")) {
  41. System.out.println("clicked");
  42. button.setText("stanly");
  43. }
  44. else if (button.getId().equals("Info_206_btn")) {
  45. System.out.println("clicked");
  46. button.setText("stanly");
  47. }
  48. //So on
  49. }
  50.  
  51. for (int i = 0; i < buttonList.length; i++)
  52. button[i].setOnAction(event -> checkId((Button) event.getSource()));
  53.  
  54. import javafx.application.Application;
  55. import javafx.geometry.Pos;
  56. import javafx.scene.Scene;
  57. import javafx.scene.control.Button;
  58. import javafx.scene.layout.VBox;
  59. import javafx.stage.Stage;
  60.  
  61.  
  62. public class Main extends Application {
  63. @Override
  64. public void start(Stage primaryStage) {
  65. Button[] buttonList = new Button[10];
  66.  
  67. for (int i = 0; i < buttonList.length; i++) {
  68. buttonList[i] = new Button("Button "+i);
  69. buttonList[i].setId("Button"+i);
  70. buttonList[i].setOnAction(event -> checkId((Button) event.getSource()));
  71. }
  72.  
  73. VBox root = new VBox();
  74. root.setAlignment(Pos.CENTER);
  75. root.getChildren().addAll(buttonList);
  76. Scene scene = new Scene(root);
  77. Stage stage = new Stage();
  78. stage.setWidth(200);
  79. stage.setScene(scene);
  80. stage.show();
  81. }
  82.  
  83. private void checkId(Button button) {
  84. for (int i = 0; i <= 10; i++) {
  85. if(button.getId().equals("Button" + i))
  86. if(!button.getText().equals("Button " + i + " Clicked"))
  87. button.setText("Button " + i + " Clicked");
  88. else
  89. button.setText("Button " + i);
  90. }
  91. }
  92.  
  93. public static void main(String[] args) { launch(args); }
  94. }
Add Comment
Please, Sign In to add comment