java - No output from JFrame? -


So I'm trying to create a tectonic board, though it is not showing anything. (A main square but it just makes "GameBoard")

Any help will be greatly appreciated, thank you in advance.

So I said that the component can not believe I forgot that, I should be tired.

But now what I get is a red square. Public GameGord () {GeFrem Frame = New GeFram (); Frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); Frame Setbacks (0, 0, 195, 215); Frame.setSize (new dimension (300, 400)); Int count = 1; Rectangle board [] [] = new rectangle [3] [3]; For (int row = 0; line; lt; board.length; row ++) {for (integer col = 0; col & lt; board [line] length; cola ++) {if (count == 2) {board [row] [Col] = new rectangle (1,1,1,1); Board [row] [col] .setBackground (Color.RED); Frame.add (board [row] [col]); Count--; } Else {board [row] [col] = new rectangle (1,1,1,1); Board [row] [col] .setBackground (Color.BLACK); Frame.add (board [row] [col]); Count ++; }}} Frame.pack (); Frame.setVisible (true); Rectangular square:

  public square rectangle JComponent {public rectangle (int x, int y, int w, int h) {super (); Setbound (X, Y, W, H); SetBackground (Color.black); } Public Zero Color (Graphics G) {g.setColor (getBackground ()); G.fillRect (0, 0, getWidth () - 1, getHeight () - 1); Paintchildren (g); }   

}

logically, steps for you Do not really miss the board on your Jeffrey:

  frame.ed (...); In your loop   

, you are making the Jephragram and rectangle, but never add rectangles to your JFrams. @Emidd said, JeffRam.add () does not accept thumb, so you will need to write a class that reciprocates JComponent under its paintComponent () method Increases to color.

Display problem (see red only):

You have to set layout manager for your JFrame ; I think GridLayout will be most appropriate in your case:

  ... JFrame frame = new JFrame (); Frame.setLayout (new grid layout (3,3)); ...    

Comments

Popular posts from this blog

java - NullPointerException for a 2d Array -

python - Assemble mpeg file unable to play in mediaplayer -

c# - NameSpace Manager or XsltContent to parse aspx page -