Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 7th, 2006, 01:21 AM
xreddawg909x xreddawg909x is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2005
Posts: 91 xreddawg909x User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 27 m 20 sec
Reputation Power: 13
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?

Reply With Quote
  #2  
Old October 7th, 2006, 03:08 AM
costas costas is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 407 costas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 3 h 25 m 24 sec
Reputation Power: 12
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

Reply With Quote
  #3  
Old October 7th, 2006, 07:38 PM
xreddawg909x xreddawg909x is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2005
Posts: 91 xreddawg909x User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 27 m 20 sec
Reputation Power: 13
the " super ()" says it doesnt accept strings only layouts such as

BorderLayout();
GridLayout();
FlowLayout();

Reply With Quote
  #4  
Old October 7th, 2006, 11:56 PM
xreddawg909x xreddawg909x is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2005
Posts: 91 xreddawg909x User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 27 m 20 sec
Reputation Power: 13
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

Reply With Quote
  #5  
Old October 8th, 2006, 12:16 AM
daniel_g daniel_g is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 60 daniel_g User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 h 3 m 50 sec
Reputation Power: 12
Use setText()
Example:
jButton1.setText("RESTART");

Reply With Quote
  #6  
Old October 8th, 2006, 04:39 AM
xreddawg909x xreddawg909x is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2005
Posts: 91 xreddawg909x User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 27 m 20 sec
Reputation Power: 13
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 ?

Reply With Quote
  #7  
Old October 8th, 2006, 09:14 AM
costas costas is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 407 costas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 3 h 25 m 24 sec
Reputation Power: 12
Hey xreddawg909x,
the "super()" works fine for me. Did you put "extends JFrame" when creating the class as I showed in the post?

Reply With Quote
  #8  
Old October 9th, 2006, 03:15 AM
daniel_g daniel_g is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 60 daniel_g User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 h 3 m 50 sec
Reputation Power: 12
Code:
super("TicTacToe"); //title


I think in his case, he doesn't really need that.

Reply With Quote
  #9  
Old October 16th, 2006, 11:04 PM
xreddawg909x xreddawg909x is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2005
Posts: 91 xreddawg909x User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 27 m 20 sec
Reputation Power: 13
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" ?

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > Size of window


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap