#can't print object name
57 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @rapid warren! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
here is the code that Im using from controller class (which makes the object) and the class that is used
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.TextField;
public class Controller{
@FXML
TextField nameField, findField;
@FXML
<T> void showME(ActionEvent event) {
//System.out.println(nameField.getText());
testingclass temp = new testingclass<T>(nameField.getText());
System.out.println(temp);
//testingclass(nameField.getText());
//testingclass.nope();
}
@FXML
void findME(ActionEvent event) {
//findField
System.out.println(temp.name);
}
}```
String name;
protected static void nope(){
System.out.println("322");
};
testingclass(String name){
this.name = name;
//System.out.println(testingclass.this.name);
}
}
is there a way I can call testingclass<T> with Controller and find out the name of that class?
.
You mean create an object of type testingClass and get the name variable?
If so then
System.out.println(temp.name);
provided the 2 classes are in the same package
If they aren't in the same package then have a getter
both are in the same package, and it seems I am able to create different objects as the memory parameter is different always
uhh... I guess?
I want to - once I pressed a button - add an object to a red area and be able to select and edit it
So what is the issue with this?
Aug 29, 2023 4:19:37 PM javafx.fxml.FXMLLoader$ValueElement processValue
WARNING: Loading FXML document with JavaFX API of version 19 by JavaFX runtime of version 17
com.example.testingclass@3076f4e8```
I pressed the Create button and it gave me com.examples...
I pressed Show and nothing happened
Its printing out com.example.... because you are printing out the testingClass object instead of the testingClass name field
<T> void showME(ActionEvent event) {
//System.out.println(nameField.getText());
testingclass temp = new testingclass<T>(nameField.getText());
System.out.println(temp);
//testingclass(nameField.getText());
//testingclass.nope();
// Label label = new Label();
}
@FXML
void findME(ActionEvent event) {
//findField
System.out.println(temp.name);
//System.out.println( getClass().getSimpleName());
}```
showME is what makes a object and shows me that it made it
findME is what is supposed to show me an object that was made once I input the name of an object im searching for
@FXML
<T> void showME(ActionEvent event) {
//System.out.println(nameField.getText());
testingclass temp = new testingclass<T>(nameField.getText());
System.out.println(temp);
//testingclass(nameField.getText());
//testingclass.nope();
// Label label = new Label();
}
@FXML
void findME(ActionEvent event) {
//findField
System.out.println(temp.name);
//System.out.println( getClass().getSimpleName());
}
😮 how did you do that?
THANK YOU!
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
yes, its supposed to tell me that the object was made
the fundME should search for that place and display that object
You are not storing the objects anywhere so how do you want to search for it?
am not? but... I made it
testingclass temp = new testingclass<T>(nameField.getText());
This creates an object, and assigns it to the temp variable. Maybe you want to store them in an object variable array or something so that they are shown?
yes, I want to store them and display in future after they are created... which I thought I did
I tried to use generics like <T> but I feel like I messed up
Yeah theres no need for generics
How about you have an object variable List of testingClass objects. Everytime you click create, add to that list. Then go through each object in the list, get all the names and set the textfield to the names
so... something like...
list<> List = [];
object(){}
createObj(obj name){
List[list.length] = obj name;
} ```
This message has been formatted automatically. You can disable this using /preferences.
List<testingClass> myObjects = new ArrayList<testingClass>();
@FXML
void showME(ActionEvent event) {
testingclass temp = new testingclass(nameField.getText());
System.out.println(temp);
myObjects.add(temp);
String str = getNameList();
//here - set the testfield to the string str
}
private String getNameList() {
String objectString = "";
for (TestingClass object: myObjects) {
objectString += object.name + "\n";
}
return objectString;
}
@FXML
void findME(ActionEvent event) {
String str = getNameList();
//here - set the testfield to the string str
}
can I be honest with you?
I don't fully understand what "<TestingClass>" in first line does...
Its just saying that the list is a list of testingClass objects
I Fixed up the code a little
so... if I want to call a ... ?variable? ...from myObjects and change a specific aspect of it. will I be able to?
You mean if you want to get an object from the list and change a property of the object?
myObject[1] = variable1
variable1 {
name: "here",
type: 7
container: "label"
} ```
This message has been formatted automatically. You can disable this using /preferences.
myObjects.get(index) retreives an object from the list at the specified index
can I go myObj[1]. name = "new name goes here"?
you can do
myObjects.get(0).name = "anything";
If it was an array and not a list, then you could have done
myObjects[0].name = "anything";
._. I feel like I should know this... before even thinking of getting into gui and stuff
Without meaning to sound rude you need to brush op on core java
thank you, I will
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
thank you