View Single Post
  #1 (permalink)  
Old 01-18-2008, 10:39 PM
Mastergeek666 Mastergeek666 is offline
Member
 
Join Date: Jan 2008
Posts: 1
Mastergeek666 is on a distinguished road
Problems with JPanels and displaying
Hey I'm having a problem, I made one panel for my buttons and then when I made another to put a label underneath the buttons, my buttons disappeared. Can anyone help?
/code
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class TicTacToe extends JFrame implements ActionListener
{
private JButton btns[];
Font f12 = new Font("Freestyle Script", 0, 42);

public TicTacToe()
{
super ("Tic-Tac-Toe");
btns = new JButton[9];
JPanel pane = new JPanel();
JPanel pane2 = new JPanel();
JLabel players = new JLabel("TEST");
Container con = getContentPane();
con.add(pane);
con.add(pane2);
pane2.add(players);
for(int i = 0; i < 9; i++)
{
btns[i] = new JButton(String.valueOf(i));
btns[i].setFont(f12);
btns[i].setText("");
}
for(int i = 0; i < btns.length; i++)
{
btns[i].addActionListener(this);
pane.add(btns[i]);
btns[i].setPreferredSize(new Dimension(100, 100));
}
setBounds(400, 250, 400, 550);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false);
}

public static void main(String[] args)
{
TicTacToe panel = new TicTacToe();
}
public void actionPerformed(ActionEvent e)
{
for (int i=0; i<btns.length; i++)
{
if(e.getSource() == btns[i])
{
switch(i)
{
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
btns[i].setText("X");
}
}
}
}
void Turns()
{
int x = 0;
int o = 1;
}
void Player1(int x)
{

}
void Player2(int o)
{

}
}
\code

There's my code, right now im just doing design but I'm having problems with the panels and the label.
Reply With Quote
Sponsored Links