Help with the basics please

hello, i am trying to create a window that displays a grid of 100 buttons arranged 10 x 10. I then would like to place a couple of buttons nicely beneath this grid that might exit the program or whatever.
my problem here is that i can't control the size of the grid the two nested for loops create and it just fills the entire window and dosen't even stay in a 10 x 10 formation, instead it randomly arranges them to fit the two buttons in at the bottom!
is there some sort of setSize comand i can use so the grid is set to a certain size, maybe of the EAST of the screen?????
here is my code so far!
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class trialgrid extends JFrame
public trialgrid()
               JFrame frame = new JFrame("One Player");
               frame.setSize(620, 650); // sets size of window displayed
               Container content = frame.getContentPane();     
               JPanel grid = new JPanel();                         
               content.setLayout(new GridLayout(10, 10)); // contains the grids info
               content.setSize(100, 100); // this is doing nothing!!!
               for (int i = 0; i < 10; i++)
                    for (int j = 0; j < 10; j++)
                         JButton square = new JButton();
                         square.setBackground(Color.blue); //nested for loops to create 10 x 10 grid of buttons
                         content.add(square);
               content.add(grid, BorderLayout.NORTH); // trying to create some sort of layout
               JPanel form = new JPanel(); // second panel that i want to go beneath grid of buttons
               form.add(new JButton("OK"));
               form.add(new JButton("Exit"));
               content.add(form, BorderLayout.SOUTH); // here i'm trying to put south below "north" grid
               frame.setVisible(true);
               frame.setResizable(false);
               frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     public static void main (String args[])
     trialgrid gl = new trialgrid();
}

1.
The only problem i have left is one of my original
l ones..... i need to be able to control the actual
size (height and width) of the grid that is produced
by the for loops!!
Because i want to set the size of the window to 620
by 650 pixels i wondered if you could control the
size of the panel and then maybe centralize it in the
middle so it would have spaces either side and top
and bottom??
Read More about:- Layout managers. setPreferredSize(), getPreferredSize() etc
Subclass a JPanel so that it returns your preferred Dimensions
2.
The thing about the buttons is i am later going to
use something like mouseClicked(MouseEvent);
getX(),
getY() to locate the mouse's location to
manipulate actions. So im not sure yet if i need to
be able to name each button or get rid of the buttons
completely!!If you want the effect of buttons and don't want to go to all the extra trouble of interpreting which one was clicked from the mouse coordinates, which is going to be a real pain if you resize anything.. you could try something along these lines...
       private void fillPanelWithLotsOfButtons( JPanel inPanel )
                      JButton currentButton;
                      String s = "";
                      int buttonNumber = 0;
                       GridLayout grid = new GridLayout( 10, 10, 5, 5 ); // 5Pixel spaces Horizontal and vertical
                      inPanel.setLayout( grid );
                     for( int i = 0 ;  i < 10 ; i ++ )
                                  for( int j = 0; j < 10 ; j ++ )
                                              buttonNumber = ( i * 10 ) + j;
                                              s =  Integer.toString( buttonNumber).trim();
                                              currentButton = new JButton(); // you might want to add a Subclass of Button that is set to your wanted size....
                                             // Or you could do currentButton = new JButton( s );
                                             currentButton.setActionCommand( s ); // will be "0", "1", "2", ......................................
                                             currentButton.addActionListener( this ); //  assumes that this classs implements ActionListener
                                             inPanel.add( currentButton );
        // Then Further on in your code
       // you can tell which button was pressed fairly easily
      public void actionPerformed( ActionEvent event )
                        String myAction = event.getActionCommand();
                        int buttonNumber = Integer.parseInt( myAction );
                        System.out.println( "Button Number " + buttonNumber );
       }or something along those sort of lines
To Flounder, that idea does interest me a lot, i have
been thinking i need more panels, maybe East, North
and West and fill these with ships, a title and
instructions respectively. **To make sense of this i
am creating a battleships game** So i need to make
another 5 panels really so i'm not sure if i could
add all these to a 6th panel?
After reading this, I'd suggest using JToggleButton
you could make a custom subclass with appropriate Images, for selected and not selected
any code or suggestions greatly appreicated!! Thank
you

Similar Messages

  • Multiple Users Login ( Help With The Code ) Please.

    Hi all. Please help me...
    I'm using www.wix.com to create my websites.
    but since Wix.com don't able us to have member system conecet to database, i use Flash SWF As3 files...
    Please can anyone help me with the Code?
    Username=1    /Password= 1    /Url= www.1.com
    Username=2    /Password= 2    /Url= www.2.com
    Username=2    /Password= 2    /Url= www.2.com
    *If user name 1 or 2 or 3 correct. Show massage ex: Welcome back, if not correct " Bad login"
    *When login, it will open the url but in new page after the old one closed.
    + There is anyway to add " Password recovaring box too"?
    but not connected to datdabase as i said?
    Please help me, please! i areadly have code but it don't work for more than one user.
    Thank u soooo much!!
    Loai

    Here's the code i have already,,
    but i don't know how to add more than one user + when login it open new window ( popup ) i want it to open in the same window...
    Please help.
    stop();
    //hide the password
    //pass_txt.displayAsPassword = true;
    //adding event listener to the login button
    login_mc.addEventListener(MouseEvent.CLICK, loginUser);
    function loginUser(e:MouseEvent):void{
    //if both username and password are correct let the user logged in
    if(name_txt.text == "1" && pass_txt.text == "1"){
    navigateToURL( new URLRequest( "http://www.wix.com/designersgroup/tutorials/9-1" ), "_blank" );
    display_txt.text = "Going to secure area";
    else if(name_txt.text != "1" && pass_txt.text != "1"){
    display_txt.text = "Login failed!";
    if(name_txt.text == "2" && pass_txt.text == "2"){
    navigateToURL( new URLRequest( "http://www.wix.com/designersgroup/tutorials/9-2" ), "_blank" );
    display_txt.text = "Going to secure area";
    else if(name_txt.text != "2" && pass_txt.text != "2"){
    display_txt.text = "Login failed!";

  • Help with the wireless, please.

    I am not having a problem with the iPod's wireless, because it seems to work fine at my friend's house on his unprotected wireless.
    The problem is my secured, with a WEP key, internet.
    It worked for a little while, but after a month it decided to not work. It connects when the network isn't secured, so I know it's an issue with the WEP key. I want to change my security to a WPA key, and I use an Actiontec GT701-WG Wireless router/gateway. I went to change the security to WPA, but it asks for a whole slew of things I don't know. As anybody ever setup a network with this type of router, and if yes, please tel me how to setup a WPA key!
    Thanks in advance for any help.

    Oh, and just in case this information is useful, my iPod can connect to the network, password and SSID are accepted. The little "wi-fi" icon appears at the top with a full signal.

  • I would need help with the following please: I need to save some of my email on a disk. I was going to Print, then Save PDF but then I am stuck. Help please. Thanks. Elisabeth

    I would need help with saving some eamil messages to a disk to unclutter my email. How can I do this please?
    Thanks.
    Elisabeth

    Open the email and then from the File menu select Save As Rich Text Format. That'll save it to open in TextEdit. If you want a pdf then open the email and do command-p (Print) and then from the PDF drop down box lower left corner select Save as PDF.

  • Little help with the G5 please!

    I have had my 5G ipod for a while now, and have had very few problems.
    Recently, I charged my ipod as usual and unplugged it the next morning to a full battery picture across the entire screen. I could not shut off the ipod. I tried all of the normal tricks and tried connecting it to my computer, but no matter what I do/did the ipod still shows a full battery icon. It died after a few hours, so I tried charging it again. Even during charging it showed the full battery icon.
    Is there something wrong with the ipod or did I do something wrong?

    try doing what i call RCDC.
    RCDC (Restore, Charge, Drain, Charge)
    1) RESTORE your iPod
    2) CHARGE your iPod
    3) DRAIN your iPod (to do this play you music while you sleep)
    4)re-CHARGE your iPod
    Doing so should re-calibrate your battery. This should work.
    Prof.
    MacBook 2.16GHz 1GB RAM 120GB   Mac OS X (10.4.10)   30GB White iPod w/ Video Gen. 5///4GB iPod nano Product (RED)

  • Need Help with the basics

    I'm attempting to take something in post fix notation and compute its calculation
    I'm having problems with my main and passing things to and from the stack. The print statement is just there to make sure its taking the #s in correctly
    Ex. 1 3 - 4 5 * +
    = 18
    import java.util.*;
    public class ABStack // Array-based implementation of a stack data structure
    //instance variables
    int [] pile; // This array holds the contents of the stack. The stack grows rightward from element 0.
    int count; // # of elements in stack. This value is also the index of the next available array element.
    public ABStack(int size) //constructor
    if(size > 1)
    pile = new int[size];
    else
    pile = new int[1];
    count = 0;
    public boolean isEmpty()
    return(count==0);
    public boolean isFull()
    return(count==pile.length);
    public int size()
    return count;
    // Add a new value to the top of the stack.
    // Do nothing if the stack is full.
    public void push(int n)
    //add n to stack top
    if(!isFull()) //have room
    pile[count]=n;
    count++;
    // Remove (and return) th value on the top of the stack.
    // If the stack is empty, return -99999 as a sentinel value.
    public int pop()
    if(isEmpty())
    return -99999;
    else
    count--;
    return pile[count];
    public static void main(String[] args)
    Scanner sc = new Scanner(System.in);
    System.out.print("Please enter numbers in Postfix notation: ");
    String note = sc.nextLine();
    char note2[] = note.toCharArray();
    int opt1, opt2;
    char c;
    for (int i=0;i < note2.length;i++)
    if (note2>= '0'&& note2[i]<='9')
    String nextchar = "" + note2[i];
    int nextnum= Integer.parseInt(nextchar);
    System.out.print(+nextnum); // Can't figure out how to pass my stuff to and from the stack
    Message was edited by:
    jaydon34
    Message was edited by:
    jaydon34

    import java.util.*;
    public class ABStack // Array-based implementation of a stack data structure
    //instance variables
    int [] pile; // This array holds the contents of the stack. The stack grows rightward from element 0.
    int count; // # of elements in stack. This value is also the index of the next available array element.
    public ABStack(int size) //constructor
    if(size > 1)
    pile = new int[size];
    else
    pile = new int[1];
    count = 0;
    public boolean isEmpty()
    return(count==0);
    public boolean isFull()
    return(count==pile.length);
    public int size()
    return count;
    // Add a new value to the top of the stack.
    // Do nothing if the stack is full.
    public void push(int n)
    //add n to stack top
    if(!isFull()) //have room
    pile[count]=n;
    count++;
    // Remove (and return) th value on the top of the stack.
    // If the stack is empty, return -99999 as a sentinel value.
    public int pop()
    if(isEmpty())
    return -99999;
    else
    count--;
    return pile[count];
    public static void main(String[] args)
    Scanner sc = new Scanner(System.in);
    System.out.print("Please enter numbers in Postfix notation: ");
    String note = sc.nextLine();
    char note2[] = note.toCharArray();
    int opt1, opt2;
    char c;
    for (int i=0;i < note2.length;i++)
    if (note2>= '0'&& note2<='9')
    String nextchar = "" + note2;
    int nextnum= Integer.parseInt(nextchar);
    System.out.print(+nextnum); // Can't figure out how to pass my stuff to and from the stack
    }Message was edited by: 

  • I had a major power out last night while using Lr5 Help with the below please

    I had a major power out last night while using Lr5, we have power back now but when launching Lr5 i get this error and I have rebooted 2 times nows with no results. I have a normal pc, and this is the error message i am getting.......Lightroom encountered an error when reading from its preview cache and quit, so i say ok and still nothing works. i am trying to process my event photos from yesterday and i need to get this fixed urgently!!! please help

    Delete the Preview Cache folder.
    It is in the same main folder as the LR catalog. Usually in your Username folder.
    Once delete LR will rebuild it once LR is opened.

  • Can you help with the coding please? I am trying to create a moveable pin by clicking and dragging.

    import mx.transitions.Tween;
    import mx.transitions.easing.*;
    /* Mouse Click Event
    Clicking on the specified symbol instance executes a function in which you can add your own custom code.
    Instructions:
    1. Add your custom code on a new line after the line that says "// Start your custom code" below.
    The code will execute when the symbol instance is clicked.
    gage.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);
    function fl_MouseClickHandler(event:MouseEvent):void
    // Start your custom code
    // This example code displays the words "Mouse clicked" in the Output panel.
    trace("Mouse clicked");
    // End your custom code
    function rotation(350, 182) {
       return Math.atan2(dy, dx) * 180/Math.PI;
    gage.onRelease = function() {
       var newAngle:Number = rotation(_xmouse-this._x, _ymouse-this._y);
       var dist:Number = Math.abs(newAngle - this._rotation);
       this._rotation %= 360;
       if(dist > 180)     {
          if(newAngle > this._rotation) {
             newAngle -= 180;
          } else {
             newAngle += 180;
       new Tween(this, "_rotation", Strong.easeOut, this._rotation, newAngle, 1, true);

    You appear to have just collected a variety of code snippets and thrown them together, including a section of AS2 code ( gage.onRelease = function() {... )
    The suggestion I offered yesterday still stands.  You should find a tutorial regarding AS3 and the atan2 function.  Beyond that, what you show suggests this is a school assignment.  You should seek help from your fellow students and instructor if that is the case.

  • Help with the basics.

    1. Does backing up (MacBook Pro, iPhone 4, iPad 2) to iCloud REPLACE  backing things up elsewhere? I have always backed things up to a separate storage drive. Do I still need to do my own separate back up?
    2. Does iCloud back up my MacBook Pro completely - system, data, etc.?
    Thanks!

    1) It's always advisable to have a second (and even third) backup, just in case something should happen to the first.
    2) No, iCloud doesn't backup Macs at all - it only syncs the data types you have selected for syncing in the iCloud system preferences pane.

  • Need some help with the colour profile please. Urgent! Thanks

    Dear all, I need help with the colour profile of my photoshop CS6. 
    I've taken a photo with my Canon DSLR. When I opened the raw with ACDSee, the colour looks perfectly ok.
    So I go ahead and open in photoshop. I did nothing to the photo. It still looks ok
    Then I'm prompt the Embedded Profile Mismatch error. I go ahead and choose Discard the embedded profile option
    And the colour started to get messed up.
    And the output is a total diasater
    Put the above photo side by side with the raw, the red has became crimson!!
    So I tried the other option, Use the embedded profile
    The whole picture turns yellowish in Photoshop's interface
    And the output is just the same as the third option.
    Could someone please guide me how to fix this? Thank you.

    I'm prompt the Embedded Profile Mismatch error. I go ahead and choose Discard the embedded profile option
    always use the embedded profile when opening tagged images in Photoshop - at that point Photoshop will convert the source colors over to your monitor space correctly
    if your colors are wrong at that point either your monitor profile is off, or your source colors are not what you think they are - if other apps are displaying correctly you most likely have either a defective monitor profile or source profile issues
    windows calibrate link:
    http://windows.microsoft.com/en-US/windows7/Calibrate-your-display
    for Photoshop to work properly, i recall you want to have "use my settings for this device" checked in Color Management> Device tab
    you may want to download the PDI reference image to check your monitor and print workflows
    and complete five easy steps to profile enlightenment in Photoshop
    with your settings, monitor profile and source profiles sorted out it should be pretty easy to pinpoint the problem...

  • Hi, please help with the installation of Lightroom 4, I bought a new Mac (Apple) and I want to install a software that I have on the album cd. My new computer does not have the drives. Can I download software from Adobe? Is my license number just to be ab

    Hi, please help with the installation of Lightroom 4, I bought a new Mac (Apple) and I want to install a software that I have on the album cd. My new computer does not have the drives. Can I download software from Adobe? Is my license number just to be able to download the srtony adobe.

    Adobe - Lightroom : For Macintosh
    Hal

  • I need help with the photo stream. Everytime I try to open it on my PC it says photo stream is unable and I have tried everuthing to enable it but it doesn't work. Any help, please?

    I need help with the photo stream. Everytime I try to open it on my PC it says photo stream is unable and I have tried everuthing to enable it but it doesn't work. Any help, please?

    Freezing, or crashing?
    ID on the Mac can produce reports that may (or may not) prove helpful in diagnosing the problem. I suspect this is something not directly related to InDesign, and maybe not to any of the Adobe apps directly since you seem to be having a problem in more than one. That often inidcates a problem at the system level.
    Nevertheless, it won't hurt to try to gather the reports. You'll find driections for how to generate them, and to post them on Pastebin.com (then put a link to them here) so we can see what's going on at Adobe Forums: InDesign CS5.5 Not Responding
    Do you happen to run a font manager? If so, which one, and waht version?

  • Please can anyone help with the continuing password rejection problem with email.Ipad and other systems work fine but despite reloading my password on imac it bounces back.Apple store has been visited and I have tried everything they suggest.

    Please can anyone help with the continuing password rejection problem with email on my imac.My Ipad and other systems work fine but despite reloading my password on imac it bounces back.Apple store has been visited and I have tried everything they suggest.

    I use free Yahoo mail webMail access because folders I created in webmail access doesn't get set up in Apple Mail. While I was searching for post about password and keychain issues, I stumbled on several threads that complain about Mail folder issues, so I'm holding off on Apple Mail.
    On the password and keychain issue that your post is all about.  I've been using login keychain to save and automatical fill my login screens for a year or so successfully, with Safari and Chrome. Automatic form fill also works for Facebook login. Unfortunately, about 4 to 6 months ago, automatic password form fill stopped working with Yahoo webmail, while still worked for GMail (Safari and Chrome). I tried deleting the password entry for my two Yahoo email accounts to start fresh, but neither Safari not Chrome will even ask me if I want to save the password. I was so frustrated that I eventually installed the keypassX 0.43 (password manager) that is quite primitive sompare to OS X's keychain (when it works). Probably no surprise to you yet.
    The surprise, to me at least, is that, for whatever reason, password auto form-fill from keychain started working again for Yahoo webmail login on Safari about 5-7 days ago. Still doesn't work on Chrome!
    Two tips I can share, at least with webmail access:
    1. Password is save only for one of my yahoo mail accounts. When I login in with my other yahoo account, I get no prompt to save the password, and form fill doesn't work when I try to log in a second time with my other Yahoo mail account.
    2. On inspection of my login keychain, I see a webform password item saved for my Yahoo account that works with keychain. The name of the password is: login.yahoo.com(MyAccountName1#). When I open the password item and look in the Access Control tab, I see Safari and Chome are listed as allowed to access this password item..
         I also an "Internet password" item with a name of just login.yahoo.com. When I open the the password item, it looks just like the password item created for MyAccountName#1, but the MyAccountName#2 is listed in the Account field. Inside the Access Control tab, no apps are listed in access permission. I added Safari and Chrome to the lists of allowed app, saved the password item.
    Now when I bring up the Yahoo login page(by bookmark) on Safari, form fill fills in MyAccountname#1 for name and the proper password and I can login in. When I change the name to MyAccountName#2, the correct password is retrieved and I can log in! Alas, it still doesn't work on Chrome.
    BTW, I changed the password item type from "Internet password" to "Web Form password" and saw no difference! I also edited the name to be "login.yahoo.com (MyAccountName#2)" to look like the web form password item that works, but it has no effect either.
    From my experimentation, here's my observation:
    1. A Web Form password item is created for the first account name(MyAccountName#1) for login.yahoo.com and typed as Web Form password. When I log in using MyAccountName#2, an Internet Password is created, but no applications are listed as allowed to access the password item, even when the password item was created after just logged in and logged out to yahoo with the account name and password for MyAccountName#2.
    2. Manually adding Safari as an app that is allowed to use the password item works. Doesn't work with Chrome!
    The version of Safari I'm using is Version 5.1.7 (6534.57.2). My installed version of Chrome is Version 21.0.1180.79 beta.

  • Please, could you help with The System Error?

    Hi guys,
    Please could someone help me with The system error: The Parameter is incorrect? which appears on the screen when I open Adobe Photoshop?
    It is Starter edition3.0 and so far it worked ok and suddenly this message haunts my screen. If I clic OK, whole application disappears. I tried hundred times and checked it is 5.1.2600 and my notebook has got Windows XP Profesional.
    Any advice hunging around?
    ThaaankxJ

    Thank you mark, I'll try.
    J
    Date: Fri, 18 Mar 2011 17:17:20 -0600
    From: [email protected]
    To: [email protected]
    Subject: Please, could you help with The System Error?
    Hi orion,
    Sorry that was the impression made by the support agent. If the version of the software that you have is 3.0 or 3.2, then the catalog can be upgraded when you run the trial version of Photoshop Elements. Version 8 had no time limitations, not sure if version 9 will timeout after 30 days or not.
    Just install, and when you launch, Elements will automatically convert the catalog to a format that it can read.
    -Mark
    >

  • A little bit of help with Bind variables please

    Hi,
    I am having a bit of trouble with bind variables I have been looking at the Dev guide and the forum to try and achieve this and it is still not happening for me, could anybody please help or point me in the right direction:
    I have created a simple PersonVO with the basic query:
    Select distinct full_name from xxml_people where person_id = :1
    In the PersonVOImpl.java I have added the method:
    public void initQuery(String personId)
    Number person = null;
    try
    person = new Number(personId);
    catch
    (Exception e){}
    setWhereClauseParam(1,person);
    executeQuery();
    Then in the PersonAM I have added the method:
    public void initPersonQuery(String personId)
    getPersonVO1().initQuery(personId);
    I then call this method in my processRequest section of my page controller:
    PersonAMImpl am = (PersonAMImpl) pageContext.getRootApplicationModule();
    String personId = "581";
    am.initPersonQuery(personId);
    When I try and run this I get the error:
    oracle.apps.fnd.framework.OAException: oracle.jbo.SQLStmtException: JBO-27122: SQL error during statement preparation. Statement: SELECT distinct full_name from xxml_absence_calendar where person_id = :1
    java.sql.SQLException: ORA-01006: bind variable does not exist
    Am I binding the variables correctly? Or am I making some stupid mistake?
    I am ultimately looking to create a messageChoice where the logged in user will see a list of all organisations underneath him and the one level above. I plan to do this by passing the User’s Organisation name into a VO query using the organisation as a Bind Variable. I think once I have worked out how to bind variables this should be straight forward.
    Many Thanks

    Even though the parameter binding values may be same, you should never use the positional param more than once. So always go for the format
    select distinct full_name from xxml_people where supervisor_id = :1
    UNION
    select distinct full_name from xxml_people where person_id = :2
    --Shiv                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Maybe you are looking for

  • Trying to install winebottler but won't install completely- error log included

    I'm trying to get internet explorer 6 to run so I tried to install winebottler. It gets half-way through install and pauses at loading "flash". I'm using these instructions: http://osxdaily.com/2010/04/20/run-internet-explorer-on-your-mac/ Install lo

  • X6 Issues

    I use a X6 8gb with firmware V21.0.004 Issues that are faced by me:- 1. Wifi signal gets lost even after having a signal strength of 2/3, this problem is not face by my  E-71, I also found that i didn't face this problem when i have full signal stren

  • How to do a fresh install of OSX

    I just bought a new Macbook Air for my wife. It didn't come with any re-install / system software. If I need to reinstall the OS for some reason (which I do have to do from time to time on my other computers), how do I do this on an Air? I have Mount

  • Nested Table

    Hi All Description: I use oracle 8.1.7 table vouchz(7,000,000 records), unique index (vz_major, vz_minor) type create or replace type taccrec is object (acc_major number(4), acc_minor number(8)); create or replace type tacctbl is table of taccrec; Ex

  • How to transfer new applications from the iphone to itunes?

    When I want to update the IOS to 7 Itunes I get an Itunes warning "There are new bought apps in the Iphone that hasn't been transfered to Itunes" , How do I transfer the apps to Itunes?. All the apps are updated in both the Iphone and Itunes.