SuperSharp
Programmer
Hi there, I am having a few difficulties trying to return a function, located in a class to another class. I have just started java so I am not that great at it, but I am learning (slowly).
Basically, I am creating a GUI quiz. We have been given the classes for a command line version and we just have to implement it into GUI. The part I am having trouble with is the highscore table. I am trying to call the fuction from the highscore class and display the table in a lable within another class.
I have tried everything I can think of but I keep getting different errors. I think the 'display()' function within the highscore class, needs a return to display it, but I don't know how to return it all, only like a string or number etc.
This is how I am calling it:
Its not liking thay because of the '.display()' because you cannot display a void. This has really been bugging me and I am really quite confused. If anyone can help at all that would be brilliant!
Thanks very much for taking the time to read this,
Edd Marshall
Basically, I am creating a GUI quiz. We have been given the classes for a command line version and we just have to implement it into GUI. The part I am having trouble with is the highscore table. I am trying to call the fuction from the highscore class and display the table in a lable within another class.
I have tried everything I can think of but I keep getting different errors. I think the 'display()' function within the highscore class, needs a return to display it, but I don't know how to return it all, only like a string or number etc.
Code:
public void display()
{
System.out.println("\n\n\tHighest Scores");
System.out.println("\t==============");
for (int i=0; i<table.length; i++)
{
System.out.print("\t" + (i+1) + "\t");
if (table[i] != null)
{
table[i].displayHighScore();
}
else
{
System.out.println("---");
}
}
}
Code:
HighScoreTable HS = new HighScoreTable();
hS = new JLabel(HS.display());
labelArea.add(hS);
Thanks very much for taking the time to read this,
Edd Marshall