|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Size of window
the window that opens up run i try and compile the source files is just the titlebar (top portion) any reason why its like this even when i set the size?
Code:
public static void main(String[] args)
{
JFrame show = new JFrame("TicTacToe");
JComponent x = new Main(); // jPanel content is coded in the constructor
show.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
show.setSize(400,500);
show.pack();
show.setVisible(true);
x.setOpaque(true);
show.setContentPane(x);
}
should i use .setSize(new dimension(x,x)); instead? |
|
#2
|
|||
|
|||
|
The setSize(x,y) must be in the constructor! Something like this:
Code:
class Window extends JFrame { //should use extends JFrame
......
public Window()
{
super("TicTacToe"); //title
setSize(x,y); //you must set here the size
JPanel mainPanel = new JPanel();
.......
SetContentPane(mainPanel);
}
public static void main(String[] args)
{
JFrame show = new Window();
show.Show();
}
Also, the panel must be in the constructor(see above). Hope I helped!! Costas |
|
#3
|
|||
|
|||
|
the " super ()" says it doesnt accept strings only layouts such as
BorderLayout(); GridLayout(); FlowLayout(); |
|
#4
|
|||
|
|||
|
can i change the String values of buttons ?
Code:
public String one_one, one_two, one_three, two_one, two_two, two_three, three_one, three_two, three_three,marker;
public main()
{
Sq1_1 = new JButton(one_one);
Sq1_1.setPreferredSize(new Dimension(45,45));
Sq1_1.addActionListener(this);
ButtonGroup bgroup = new ButtonGroup();
bgroup.add(XButton);
bgroup.add(OButton);
radioPanel.setLayout(new GridLayout(0, 1));
radioPanel.add(XButton);
radioPanel.add(OButton);
XButton.addActionListener(this);
OButton.addActionListener(this);
radioPanel.setBorder(BorderFactory.createTitledBor der(BorderFactory.createEtchedBorder(), "First Player"));
}
public void actionPerformed(ActionEvent evt)
{
if (evt.getSource() == Sq1_1)
{
one_one = marker;
Sq1_1.setEnabled(false);
}
if ( evt.getSource() == XButton)
{
marker = "X ";
}
else if(evt.getSource() == OButton)
{
marker = "0";
}
}
}
what im tryin to do is when the player sets the radio button to "X" it sets the Label of the button to "X" when that button is clicked or if the player sets the radio button to "O " it sets that button label to "0" when clicked, though when the radio button is clicked it just disables and stays label-less , few hints would be greatly appreciated .. thanx |
|
#5
|
|||
|
|||
|
Use setText()
Example: jButton1.setText("RESTART"); |
|
#6
|
|||
|
|||
|
coo thanx, anyways i tried using .setLabel(string_variable);
and it keeps giving me a warning of depreciated.... somethin or other should i be concerned with this warning ? |
|
#7
|
|||
|
|||
|
Hey xreddawg909x,
the "super()" works fine for me. Did you put "extends JFrame" when creating the class as I showed in the post? |
|
#8
|
|||
|
|||
|
Code:
super("TicTacToe"); //title
I think in his case, he doesn't really need that. |
|
#9
|
|||
|
|||
|
havin a bit of a problem
for a tictactoe problem im trying to get it to alternate to the other String when a radio button is placed on an X or O Code:
// when a button representing a space on a tictactoegrid is pressed, count is incremented (9 max)
if(evt.getSource() == OButton)
//first player is O
{
if(count%2 == 0)
{
marker = "O";//starting move, and every move after 2nd player is "O"
}
else if (count%2 ==1)
{
marker ="X"; // every move after the first player is X
}
}
else if(evt.getSource() == XButton)
//first player is X
{
if(count%2 == 0)
{
marker ="X"; // starting move, if radio button is on "X" then move 0, move 2, move4 etc.. is X without switching the radio button
}
else if(count%2 ==1)
{
marker ="O"; // every move after the 1st player is O
}
}
but i have to "reemphasize" the radio button for it to continue. any way to have it switch between X and O just by leaving the radiobutton "selected" ? |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Java Development > Size of window |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|