I wrote a class called Creature.java that creates a random creature object with various body stats. The Creature class extends MonsterGUI.
I used Netbeans to create a new jFrame form, called MonsterGUI.java to create a GUI to display the creature objects' stats using jLabels.
In MonsterGUI I have a private jLabel called jLabel4 that is originally set to "--------".
The Creatures class has methods - getting/returning an int - called setWidth() to set the Width, and getWidth() to return the Width of the Creature.
Under the MonsterGUI main method, I can create a Creature object, and call the getWidth() and setWidth() methods:
public static void main(String args[]) {
Creature ant = new Creature();
ant.randCreatureGenerator();
ant.creatureStats();
ant.setWidth(8);
System.out.println(ant.getWidth());
I want to change MonsterGUI's jLabel4 to what the newly created Creature object's getWidth() method returns.
I have tried doing this by creating a MonsterGUI private method:
private void Changer(java.beans.PropertyChangeEvent evt) {
String label = Integer.toString(getWidth()); //cast the int to a string for jLabel4 to use
jLabel4.setText(label); //sets jLabel4 to String label
}
This changes jLabel4 to "132" which shows that I am not accessing the newly creatued Creature object's getWidth() method.
Could someone please help me understand how to access the new Creature objects' methods to change the MonsterGUI's private variables?
Thanks,