Moving a Button?

Hello everyone,
We finally got our program working the way we want it except for the button's placement. We discovered that the button is placed in the direct middle and we can't get the button to move to the bottom of the screen. We want to move the button but it seems like I can't with GridBagLayout or GridBagConstraints. I'm not even sure which variables I would have to change inorder to do it. Right now, the program plays wav music thanks to Brackeen's book & files. It takes up the full screen like a real computer game and has a background image. There's another image for the game's title which pops up in the center of the screen, but I know how to move that around. If I push the Esc button on the keyboard, the game exits. Then the button in the center of the screen can also exit when pressed, but it is currently blocking the title of the game. We want to move the button below the title, but we haven't found a suitable way besides making a transparent picture that would move the button. Can anyone help us out with this? Thanks
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.sound.sampled.AudioFormat;
import com.brackeen.javagamebook.sound.SoundManager;
import com.brackeen.javagamebook.sound.*;
import com.brackeen.javagamebook.input.*;
import com.brackeen.javagamebook.graphics.*;
import com.brackeen.javagamebook.test.*;
class Graphic4 extends JFrame implements ActionListener
    private JButton startButton, newButton = createButton("Title.gif");
    private static ImagePanel ip = new ImagePanel("Title Screen.jpg", "Title.gif");
    private Image Title = loadImage("Title.gif");
    protected GameAction exit;
    private static boolean isRunning, switchB = true;
    protected InputManager inputManager;
     public Graphic4()
          //Makes it Full Screen.
          setUndecorated(true);
          GridBagConstraints grid = new GridBagConstraints();
          GridBagLayout gridBagLay = new GridBagLayout();
          //Creates the Start Button.
          startButton = createButton("Start.gif");
          grid.gridwidth = GridBagConstraints.SOUTH;
          System.out.println (gridBagLay.getLayoutAlignmentX(ip));
          System.out.println (gridBagLay.toString());
          //Sets the Location of the Title.
          ip.setLocation (342, 244);
          ip.setLayout(gridBagLay);
          ip.add(startButton, grid);
          //Doesn't work.
          ip.setButtonLocation(460, 500);
          //Adds it to the Content Pane.
          getContentPane().add(ip);
          //Makes it pop up.
          setExtendedState(MAXIMIZED_BOTH);
          addKeyListener(new KeyListener()
               public void keyPressed(KeyEvent event)
                    //Does nothing until released.
               public void keyReleased(KeyEvent event)
                    if (event.getKeyChar() == KeyEvent.VK_ESCAPE)
                         //Exits the program.
                         System.exit(0);
               public void keyTyped(KeyEvent event) {}
          startButton.addActionListener(new ActionListener()
              public void actionPerformed(ActionEvent e)
                  // fire the "exit" gameAction
                  System.exit(0);
     public Image loadImage(String fileName)
        return new ImageIcon(fileName).getImage();
     public JButton createButton(String name)
         String imagePath = name;
         ImageIcon iconRollover = new ImageIcon(imagePath);
         Cursor cursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
         // create the button
         JButton button = new JButton();
         button.addActionListener(this);
         button.setIgnoreRepaint(true);
         button.setFocusable(false);
         button.setBorder(null);
         button.setContentAreaFilled(false);
         button.setCursor(cursor);
         button.setIcon(iconRollover);
         button.setRolloverIcon(iconRollover);
         button.setPressedIcon(iconRollover);
         return button;
       public void actionPerformed(ActionEvent e)
        Object src = e.getSource();
        if (src == startButton)
           exit.tap();
        else
             exit.tap();
    public void checkSystemInput()
        if (exit.isPressed())
            stop();
    public void stop()
        isRunning = false;
    public void createGameActions()
        exit = new GameAction("exit",
            GameAction.DETECT_INITAL_PRESS_ONLY);
        inputManager.mapToKey(exit, KeyEvent.VK_ESCAPE);
     public static void main(String[] args)
          new Graphic4().setVisible(true);
          AudioFormat PLAYBACK_FORMAT =
         new AudioFormat(44100, 16, 2, true, false);
         SoundManager soundManager = new SoundManager(PLAYBACK_FORMAT);
         Sound titleMusic = soundManager.getSound("movie02.wav");
          soundManager.play(titleMusic);
class ImagePanel extends JPanel
     Image img, sImg;
     int x = 0, y = 0, bx = 0, by = 0;
     public ImagePanel (String fileName, String fileName2)
          try
               img = javax.imageio.ImageIO.read(new java.net.URL(getClass().getResource(fileName), fileName));
               sImg = javax.imageio.ImageIO.read(new java.net.URL(getClass().getResource(fileName2), fileName2));
          catch(Exception e){/*handled in paintComponent()*/}
     public void setLocation (int x1, int y1)
          x = x1;
          y = y1;
     public void setButtonLocation (int x1, int y1)
          bx = x1;
          by = y1;
     public void switchBackground (String fileName)
          try
               img = javax.imageio.ImageIO.read(new java.net.URL(getClass().getResource(fileName), fileName));
          catch(Exception e){/*handled in paintComponent()*/}
     public void paintComponent(Graphics g)
          super.paintComponent(g);
          if(img != null) g.drawImage(img, 0,0,this.getWidth(),this.getHeight(),this);
          else g.drawString("No image file found", 50, 50);
          if(sImg != null) g.drawImage(sImg, x, y ,this);
          else g.drawString("No image file found", 100, 100);
}

using the code from my reply to your other recent post, it is modified so the
button is at the bottom. You should be able to make the same changes to yours.
Basically changes the layout to a borderlayout
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class FullScreen extends JFrame
  public FullScreen()
    setUndecorated(true);
    ImagePanel ip = new ImagePanel();
    ip.setLayout(new BorderLayout());
    JPanel buttonPanel = new JPanel();
    buttonPanel.setOpaque(false);
    JButton btn = new JButton("Exit");
    buttonPanel.add(btn);
    ip.add(buttonPanel,BorderLayout.SOUTH);
    getContentPane().add(ip);
    setExtendedState(MAXIMIZED_BOTH);
    btn.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent ae){
        System.exit(0);}});
  public static void main(String[] args) {new FullScreen().setVisible(true);}
class ImagePanel extends JPanel
  Image img;
  public ImagePanel()
    try
      img = javax.imageio.ImageIO.read(new java.net.URL(getClass().getResource("Test.gif"), "Test.gif"));
    catch(Exception e){/*handled in paintComponent()*/}
  public void paintComponent(Graphics g)
    super.paintComponent(g);
    if(img != null) g.drawImage(img, 0,0,this.getWidth(),this.getHeight(),this);
    else g.drawString("No image file found",50,50);
}

Similar Messages

  • Moving a button - should be simple right?

    I just can't eliminate the 'jumping' that is happening when I move a button using the mouseDragged event:
    private void myBtnMouseDragged(java.awt.event.MouseEvent evt) {
    myBtn.setLocation(evt.getX(),evt.getY());
    The above call was added by this:
    myBtn.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
    public void mouseDragged(java.awt.event.MouseEvent evt) {
    myBtnMouseDragged(evt);
    It works, but the object jumps all around while moving (it does move with the mouse though). Also, it falls behind the mouse...shouldn't X and Y be tracking the mouse? I tried several different variations on this theme, but the 'jumping' was always a problem (realized some cool things though!).
    I will keep looking through the forums...
    Thanks for any replies, sorry for my ignorance!
    JR

    This is strange...if I use validate() after setLocation(), the button doesn't move at all:
    public void myBtnMouseDragged(java.awt.event.MouseEvent evt) {
    myBtn.move(evt.getX(),evt.getY());
    validate();
    jTextField1.setText("mouseloc " + evt.getX() + ", " + evt.getY());
    The text field is showing me the X,Y of the mouse in real time though.
    hmmmmmm...
    There has to be something internally that is keeping track of the original location of the component, correct? So move(), and setLocation() are only temporary?
    JR

  • Is moving of button pannel of c7 normal?

    button pannel of my new c7 is moving and m worried

    it`s sad but it`s normal :-(
    the button pannel on my C7 is also moving and when i looked at another pieces, they have it also. i try to ignore it all the time, but i could not ignore the color failure of amoled display when displaying gray color, it shows up purple. i sended it to nokia care for replacement.
    Nokia 701
    (RM-774, Symbian Belle, 111.030.0609)

  • Moving Kudos button on forum messages?

    Hey Everyone -
    I found out that I can move the Kudos button in forum messages inside the message body, next to the reply button. I think it may make sense in this location because it is more apparent that you are giving the message kudos.  In it's current location just under the avatar, it sort of blends in with the user credentials and could be overlooked. 
    I plan to go ahead with this change soon but I wanted to see if there are reasons that the button is better off in its current location.  I've attached two images with the Kudos button in the proposed location - the first is what you would normally see for a message and the second is what you would see if you started the thread and had the ability to accept a reply as a solution.
    Thanks,
    Laura

    Moving the Kudos button looks good! But I'm with Ray, can you move the "Accept as Solution" inline with the others? (See below)
    a.lia-user-name-link[href="/t5/user/viewprofilepage/user-id/88938"] {color: black;} a.lia-user-name-link[href="/t5/user/viewprofilepage/user-id/88938"]:after {content: '';} .jrd-sig {height: 80px; overflow: visible;} .jrd-sig-deploy {float:left; opacity:0.2;} .jrd-sig-img {float:right; opacity:0.2;} .jrd-sig-img:hover {opacity:0.8;} .jrd-sig-deploy:hover {opacity:0.8;}

  • When I customize the toolbar moving all buttons to the left side of the url field, the X button disappears. It reappears when placed to the right of the url field. (FireFox 4))

    This is actually less of a question and more of a bug report. When I searched for "report bug" this was the best and most likely place I could find that would actually accept input and not direct me to static links. This issue is repeatable.

    Firefox 4.0 has a combined Reload and Stop and Go button that appears at the right end of the location bar.
    To restore the Firefox 3 appearance you can use these steps:
    * Open the "View > Toolbars > Customize" window to move the Stop and Reload button out of the location bar.
    * Move the Reload and Stop buttons to their previous position at the left side of the location bar.
    * Set the order to "Reload - Stop" to get a combined "Reload/Stop" button.
    * Set the order to "Stop - Reload" or separate them otherwise to get two distinct buttons.

  • Issue with page processing - confirmation message & show /hide a button..

    Hello,
    I am working on a to do list application.
    I have events and for each event, I show list of tasks (grouped in reports based on the calculated task's status).
    In one region I have a drop down list of events and a Select Event button.
    For each task, I had to create a CLOSE option (initially I used a link, but the requester wanted a confirmation before closing the task).
    Now I have a checkbox for each task (generated dynamically with apex_item.checkbox(1,task_id)).
    Closing a task in my application means to set the end_date to sysdate.
    I followed the instructions from
    http://download-west.oracle.com/docs/cd/B31036_01/doc/appdev.22/b28839/check_box.htm#CEGEFFBD. I've created also a button and a process and updated the sql from "delete" to "update".
    The process is set: OnSubmit - After Computations and Validations; Run Process Once per page visit (default).
    The issue number 1 is that I see the confirmation message (that tasks have been closed) every time I reload the page (the same when I click Select_event button).. not only after I press on that Close_task button..
    For issue number 2, I have to mention that I've added a condition to show / hide the Close_task button, only if I have at least 1 task in the report.
    The issue number 2 is that I see the button only if I click 2 times on the Select_Event button.. The same is for hide.
    I feel like I am missing something very important about how to synchronize different events(buttons clicks), processes..
    help..?
    Thank you!
    Anca

    This forum is magic..
    As soon as write here, I find the answer!
    Issue 1: I fixed it by specifying this: When Button Pressed (Process After Submit When this Button is Pressed) and my button. I miseed this 1st time.
    Issue 2: I moved the button after the report.. and now it's working just fine!
    I did this about it for some time before asking the question here.. but I just had to write here and got the right answer ;)
    Have a nice day!
    Anca

  • Simple Button Target Question

    Just wondering...
    Say I have a button that leads to menu 2... what is the general usage pattern? do you generally set you button to go to another button on menu 2, or is common practice simply to go to [Menu] target of menu 2? If not to the [Menu] target, why to a button?
    Thanks yet again...

    If you do not set a button as target, then it goes to the default button on the menu, which may get switched depending on where the buttons are and how you moved the buttons. It is a question of your navigation scheme that you want. I usually target a button as a matter of course and check all navigation also for where I want things to go/behave.

  • Get buttons on a master to show up on all pages on export.

    Argh! This issue has been driving me nuts for days.
    I’m creating a course calendar at work and have some navigational buttons that I’ve created a buttons master, which I then applied to the content master. In my InDesign documents, the buttons show up on every page that I want but when I export to an interactive pdf, they only show up on 3 pages. When you go into the tools editing view in Acrobat, I can see that the buttons exist but they don’t show up!?
    The layers in InDesign are such that the navigational buttons are the top most layer.
    I have no idea what’s going on. This happened a few weeks ago and I fixed it by moving the buttons to the separate button master instead of having them exist on the content master. But now it’s reverting back to the same issue.
    Thoughts?

    on Mac OS X there is no icloud enabled apps at this time. iWork09 for Mac wont sync your data to iCloud.
    To get documents to the cloud and thus to your IOS5 devices you need to visit www.icloud.com/iwork and manually upload your files  ( or use drag and drop from Mac Desktop to the browser ).
    This is no joke. Spreaded all over this support forums you find people that wondered how to do it until it was found out that iwork syncing is only enabled on iOS but not on OSX.

  • Help with buttons/actionscript

    I've got a movieclip acting as a button.  Code on the button itself handles roll-over/-out states, and I define an onRelease function in the main timeline as follows:
    backBut.onRelease=function(){
         gotoAndPlay(1);
    This code takes the movie back to the first frame and works on the third frame.  For some reason, though, the same code on the fifth frame has no effect.  The button doesn't do anything.  I have tried using the same button, I tried inserting a new keyframe with a new button, renaming the button, etc. and for some reason I just can't get it to work on the fifth frame.
    If it helps to visualize, I am essentially making a menu.  The first frame contains buttons to take you to submenus, located on following slides.  This button to go back to the original menu is on each frame with a submenu, but for some reason only works on one of them.  Thanks in advance for your help.

    Try moving that button in frame 5 to it's own layer.  If it's the same llibrary symbol, what happens is the name from the preceding instance gets inherited, along with other characteristics.  If frame 4 doesn't do anything, instead of a new layer, just try putting a blank keyframe between the buttons in frames 3 and 5.  This may not be the problem at all, but it's my first guess at the possible problem.

  • Problem with the "mail me" button

    Since I installed both Iweb 09 and Snow Leopard, there is a problem with the "mail me" buttons on my websites. Nothing happens when i click on it even if i see my web adress when my cursor is on the button.
    Do somebody had the same problem and do you know how to avoid it.
    Thanks a lot

    I checked your site and found that the mail me button was not overlapping or touching any other object and positioned entirely in the footer of the page. All looks good and it works for me. You might try moving the button, logo and counter to the bottom of the page content section, publish and see if that makes a difference for those computers that can't.
    Try the following on your Macbook, open Safari, clear the cache (CommandOptionE), load your site and try again. If that makes it work for your MB tell your friends to clear their caches and try again. Might be something as simple as that.

  • ITunes 12: Buttons missing in dialog boxes (not visible)

    Hello.
    Since using iTunes 12 (in my case: German version) buttons like YES/NO or OK/CANCEL are not shown in smaller dialog boxes when iTunes wants to interact with the user and asks question whether to do this or to do that.
    The buttons are just not visible, the boxes are too small and they cannot be resized (= fixed size). I think this could be due to longer German texts in the dialog boxes compared to the English language version.
    The buttons are there but cannot be seen or clicked.
    Screen resolution is 1920x1200 and text zoom factor is 100% in Windows 7. Window size for these dialog boxes seems to be hard-corded and due to line breaks and longer texts in German the YES/NO buttons seem to get an unexpected carriage return moving the buttons out of the visible area.
    Please fix this!
    Kind regards,
    Argentinos

    Example: here a part of the buttons is visible but in many dialog boxes they are completely cut off.

  • Why are the forward and backward buttons so close to the play/pause button on the lock screen?

    The quickest way to control the playing of music or podcasts is on the lock screen after double tapping the button. The controls for forward, rewind and play/pause are way too close together. There seems to be no logical reason for having them so close when there is room on the screen. Is there a way of moving these buttons?

    No.  But tell apple about your concern http://www.apple.com/feedback/

  • Where is firefox's STOP button gone Now?!!!

    firefox updated itself to version 29.0.1 This update removed some of my customized toolbar icons like ieview, and moved Home button to the far right, added some icons I removed from toolbar last time because they are useless to me, and my STOP button is gone! Where is the stop button? It's not under customize!!! I'm seriously considering Opera, or Chrome now. It's was bad enough when the "programmers" removed the ESC function so some websites now take forever to load Junk and I get ticked off after 10 seconds and have to click click Stop! But now Stop is missing too...
    Un-Friggin' believable!!! >:(

    It's inside URlbar , when you press F5, you will see it !
    Or Reset FF : Help > Trouble > Reset
    Or using Classic Theme Restorer : https://addons.mozilla.org/vi/firefox/addon/classicthemerestorer/

  • Buttons / popups hidden behind background why ?

    In CS5.5 the popup button areas I draw on an ' over ' state are drawn under the background - whether background is a bitmap or sold color.  The corresponding popup text also appears behind the background.  Arranging and sending to front or back doesn't help.  I had this working before and suddenly I can't do it.....I'm trying to make a map with rollover popup text.  Making the background layer invisible allows construction but the swf  has hidden popups.
    This is the quick tut I learned it on ...followed it and it worked at first.  Now following it doesn't work for anything new.  Tried on 2 computers. Does it work for anyone? 
    waveav.us/rollover.pdf
    Thanks!

    Thanks Kglad,
    Simply moving the button layer above the background layer showed the button rectangles, hence changing the display list I believe.  Thanks again for quick reply.
    Date: Sun, 24 Feb 2013 13:10:44 -0800
    From: [email protected]
    To: [email protected]
    Subject: buttons / popups hidden behind background why ?
        Re: buttons / popups hidden behind background why ?
        created by kglad in Flash Pro - General - View the full discussion
    is the parent of the background and the parent of the popup the same? if yes, that re-adding the popup to the display list will add it above the background. if no, you will need to rethink your setup or re-add the parent of the popup so it's above the parent of the background.
         Please note that the Adobe Forums do not accept email attachments. If you want to embed a screen image in your message please visit the thread in the forum to embed the image at http://forums.adobe.com/message/5098686#5098686
         Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/5098686#5098686
         To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/5098686#5098686. In the Actions box on the right, click the Stop Email Notifications link.
         Start a new discussion in Flash Pro - General by email or at Adobe Community
      For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

  • Menu buttons off TV screen

    I have a 2 hour idvd project with scene selections. On the main menu the button that gets highlighted when choosing "Play Movie" or "Scene Selection" is moved off to the left of the screen, but only on the TV. It's so far to the left it doesn't even show on the TV screen, which is widescreen. In iDVD itself the button highlights look just fine, and are well within the TV safe area.
    The project is in 16:9, using the"Sport" theme.
    Any ideas?
    Lisa

    Yes, I tried the dvd player settings, too. Same problem still.
    In iDVD I've tried moving the button & text to the center of the screen, which has brought the actual button just barely onto the tv screen so it can be seen. Doesn't make the design look good, though.
    I've used other themes in which the highlighted button doesn't show up in the same place on the computer as it does on the TV. Sometimes it is moved left, sometimes right. Any ideas why?
    Thanks,
    Lisa

Maybe you are looking for

  • 23" Cinema Display with DVI-ADC Adapter.  Won't turn on with 8800 card...

    I am running Windows XP on a pc. I have had the ACD 23" with the DVI to ADC adapter for 4 years now and it has been flawless. I ran this using an nVidia 6800 Ultra card and then an 8800 GTS 640 MB card. All was well. I just got a 2 new cards for 2 di

  • Syncing video across several Apple TV units

    Hi, I want to use a NAS and several AppleTV units as a audio/video distribution system at home. I know that you can sync audio between different units but is it possible to do the same with video? What I want to be able to do, for example, is to be w

  • Load a excel file

    Hi all, I am sorry i am asking this question here but i cant find TOAD specific thread. I want to load an excel file from OS to my database table using TOAD. Can anyone tell me how to do this? Thanks Edited by: user10380680 on Nov 6, 2008 3:17 PM

  • Send PDF via Mail-Adapter

    Which tags you are talking about? Is your pdf is the payload or an attachment? May be you can look at swapping of payload if you can send the PDF as an attachment. VJ

  • ESS transport - help required

    Hi All, I need a sugession from u folks, for my below doubt. We have 4 j2ee servers. 1. JDI 2. EP development 3. EP Quality 4. EP Production We have deployed ESS Webdynpro applications in all 3 (EP development, quality and production) and running goo