Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can i set the interface for the TicTacToe game project?
    primarykey
    data
    text
    <p>I am trying to make the interface for the Tic tac toe. I am using the JLabels method for my 9 fields. There is no error in the program but there is something that i don't know how to do it. Please read below for my problem &amp; please give me suggestion</p> <pre><code> import javax.swing.*; import java.awt.*; import java.awt.geom.*; public class ticTac extends JFrame { static JLabel label0 = new JLabel(); static JLabel label1 = new JLabel(); static JLabel label2 = new JLabel(); static JLabel label3 = new JLabel(); static JLabel label4 = new JLabel(); static JLabel label5 = new JLabel(); static JLabel label6 = new JLabel(); static JLabel label7 = new JLabel(); static JLabel label8 = new JLabel(); static JLabel[] choiceLabel = new JLabel[9]; static ImageIcon burger = new ImageIcon("Cross.jpg"); public static void main(String []args) { new ticTac().show(); } public ticTac() { setVisible(true); setSize(450,450); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); getContentPane().setLayout(new GridBagLayout()); GridBagConstraints myGrid = new GridBagConstraints(); GridBagConstraints gridConstraints; choiceLabel[0] = label0; choiceLabel[1] = label1; choiceLabel[2] = label2; choiceLabel[3] = label3; choiceLabel[4] = label4; choiceLabel[5] = label5; choiceLabel[6] = label6; choiceLabel[7] = label7; choiceLabel[8] = label8; </code></pre> <p><strong>This method draws the Labels from 1 to 9 in a horizontal row, so i don't want that, i want my program will draw three box in one row, and three boxes in second row and three boxes. please help me.</strong> </p> <pre><code> for (int i = 0; i &lt; 9; i++) { gridConstraints = new GridBagConstraints(); choiceLabel[i].setPreferredSize(new Dimension(burger.getIconWidth(), burger.getIconHeight())); choiceLabel[i].setOpaque(true); choiceLabel[i].setBackground(Color.RED); gridConstraints.gridx = i; gridConstraints.gridy = 0; gridConstraints.insets = new Insets(10, 10, 10, 10); getContentPane().add(choiceLabel[i], gridConstraints); pack(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); setBounds((int) (0.5 * (screenSize.width - getWidth())), (int) (0.5 * (screenSize.height - getHeight())), getWidth(), getHeight()); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload