Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Components not appearing in frame

Status
Not open for further replies.

groovygarden

Programmer
Aug 23, 2001
63
Hi, could someone help me work out what I'm doing wrong...?
I'm trying to get a frame to "pop-up" showing the highest test marks.

The code to create the frame is below. A frame does appear but it is empty...

Code:
import javax.swing.*;
import java.awt.*;

public class displayBoard extends JFrame {

    ScoreBoard gamescores;
    displayBoard(ScoreBoard scores){
	gamescores = scores;
    }

    public displayBoard() {
   
        JLabel[] theScores = new JLabel[5];
        JPanel scorePane = new JPanel();
        setContentPane(scorePane);

        for (int i=0; i<gamescores.noScores; i++){
        theScores[i]= new JLabel();
        theScores[i].setText(Long.toString  
           (gamescores.highScore[i].getTime()));
        scorePane.add(theScores[i]);
    }
  }
}
displayBoard is called like this:
Code:
displayBoard display = new displayBoard(this);
display.show();
As I said, a frame appears but it is completly empty...

Any suggestions gratefuly received...!
 
You have two methods in your piece of code
Code:
displayBoard(ScoreBoard scores){
and
Code:
public displayBoard() {


check to see which one you are calling (I'll give you a clue, you ain't calling the one that does the work)


There is something else you might want to look at too -
using
Code:
setContentPane()
when you could just add directly to the JFrame (time/reasource waste creating a JPanel for no real reason).
Although I'm not sure if this is wrong or wasteful as I have never seen it done before. Does anyone else know about this? Is it worth doing? -------------------------------------------
There are no onions, only magic
-------------------------------------------
 
Concerning setting components directly on a JFrame - I've done that before and for a basic screen it's fine. Using panels tends to make screens easier to figure out if you have a complex screen using many different layout managers. For this reason I tend to put everything on panels now and just place the panels where I want them.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top