6 Replies - 350 Views - Last Post: 04 June 2014 - 08:39 PM Rate Topic: -----

#1 dodgersfan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 29-November 13

how to access methods from other classes using buttons in javafx

Posted 04 June 2014 - 07:06 PM

i have a javafx class that has buttons and textfields. i will post more code if you guys need it but here is the code for a button, and i want the button to make a new object but im having trouble setting the constructor
Label label = new Label("Type");
GridPane.setHalignment(label, HPos.RIGHT);
TextField textField = new TextField();

Label label2 = new Label("First Name");
GridPane.setHalignment(label2, HPos.RIGHT);
TextField textField2 = new TextField();
	            				
Label label3 = new Label("Last Name");
GridPane.setHalignment(label2, HPos.RIGHT);
TextField textField3 = new TextField();
	            				
Label label4 = new Label("Email");
GridPane.setHalignment(label2, HPos.RIGHT);
TextField textField4 = new TextField();
	            				

Button Add = new Button("Add");
Add.setOnAction(new EventHandler<ActionEvent>(){
@Override
public void handle(ActionEvent e){
Student st = new Student(textField, null, textField2, textField3, textField4, null, null);
db.printDatabase(); //just to test if when i clicked the button it would print this method from another class. 
}
});


after i create the object i will insert the object in an arraylist of person objects

Is This A Good Question/Topic? 0
  • +

Replies To: how to access methods from other classes using buttons in javafx

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10646
  • View blog
  • Posts: 39,539
  • Joined: 27-December 08

Re: how to access methods from other classes using buttons in javafx

Posted 04 June 2014 - 07:17 PM

What sort of trouble with the constructor? Please be specific.
Was This Post Helpful? 0
  • +
  • -

#3 dodgersfan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 29-November 13

Re: how to access methods from other classes using buttons in javafx

Posted 04 June 2014 - 07:26 PM

View Postmacosxnerd101, on 04 June 2014 - 07:17 PM, said:

What sort of trouble with the constructor? Please be specific.

i tried to set the information on the textfields to be inserted in the Student constructor but i get this error: The constructor Student(TextField, null, TextField, TextField, TextField, null, null) is undefined. the constructor takes parameters of type string, class, string, string, string, clss, null all in order
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10646
  • View blog
  • Posts: 39,539
  • Joined: 27-December 08

Re: how to access methods from other classes using buttons in javafx

Posted 04 June 2014 - 07:29 PM

So you should pass Strings, not the TextFields. See the getText() method on TextField.
Was This Post Helpful? 0
  • +
  • -

#5 dodgersfan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 29-November 13

Re: how to access methods from other classes using buttons in javafx

Posted 04 June 2014 - 07:47 PM

View Postmacosxnerd101, on 04 June 2014 - 07:29 PM, said:

So you should pass Strings, not the TextFields. See the getText() method on TextField.

so how can i turn what the user enters on the testfields as strings, i tried casting but i got an error saying that i cant use casting
Was This Post Helpful? 0
  • +
  • -

#6 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10646
  • View blog
  • Posts: 39,539
  • Joined: 27-December 08

Re: how to access methods from other classes using buttons in javafx

Posted 04 June 2014 - 08:04 PM

I just told you. Use the getText() method on the TextFields.

Not to be rude, but it sounds like you don't have a good handle on Java. That's fine, but I strongly encourage you to get your basics down, especially your OOP. You really need it to deal with GUIs at any practical level. Otherwise, it's frustrating to try and debug things. Speaking from experience.

Best of luck!
Was This Post Helpful? 1
  • +
  • -

#7 dodgersfan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 29-November 13

Re: how to access methods from other classes using buttons in javafx

Posted 04 June 2014 - 08:39 PM

View Postmacosxnerd101, on 04 June 2014 - 08:04 PM, said:

I just told you. Use the getText() method on the TextFields.

Not to be rude, but it sounds like you don't have a good handle on Java. That's fine, but I strongly encourage you to get your basics down, especially your OOP. You really need it to deal with GUIs at any practical level. Otherwise, it's frustrating to try and debug things. Speaking from experience.

Best of luck!

sorry about that, i type that because i didn't see the getText() method in the api, but i fixed it and now everything works, thanks for the help
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1