How can I move a graphic ?

I have two classes set up. One of them has the graphic sitting in teh center of the panel, while the other class sets up the menu and action listener things. In one of the menu items I have four options, up, down, left, and right. How can I make it so when I select one of them, it moves the graphic X number of pixels in the corresponding direction? I am having trouble with the action listener things I guess.. Any help?
Thanks.

import javax.swing.*;
import java.awt.*;
public class ColorPanel extends JPanel
{   private int x;
    private int y;
    ColorPanel(int vertical, int horizontal)
        setPreferredSize(new Dimension(300,300));
        setBackground(Color.white);
        x = horizontal;
        y = vertical;
    public void paintComponent (Graphics g)
        super.paintComponent(g);
        g.setColor(Color.black);
        g.drawRect(0, 0, 50, 50);
        g.drawString("Goal", 10, 30);
        g.fillOval(x, y, 10, 10);
}and
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ColorFrame extends JFrame
{   private int x;
    private int y;
    ColorFrame()
    {   int origx=150; int origy=150;
        panel = new ColorPanel(x,y);
        getContentPane().add(panel, BorderLayout.CENTER);
        JMenuBar menuBar = new JMenuBar();
        setJMenuBar(menuBar);
        JMenu fileMenu = new JMenu("File");
        menuBar.add(fileMenu);
        fileMenu.add(createMoveItem("Up", x, y+=20));
        fileMenu.add(createMoveItem("Down", x, y-=20));  
        fileMenu.addSeparator();
        fileMenu.add(new ExitItem("Exit"));
        pack();
        setVisible(true);
    public JMenuItem createMoveItem(String label, final int x, final int y)
        JMenuItem item = new JMenuItem(label);
        class MenuItemListener implements ActionListener
            public void actionPerformed (ActionEvent evt)
                panel.repaint();
        item.addActionListener(new MenuItemListener());
        return item;
    class ExitItem extends JMenuItem implements ActionListener
        ExitItem(String label)
            setText(label);
            addActionListener(this);
        public void actionPerformed (ActionEvent evt)
            System.exit(0);
    private ColorPanel panel;
}

Similar Messages

  • How can i move video and music and narration all at once in the project library

    how can i move video, narration and music all at once in the project library  it is only moving the video

    Select the directory with your pngs in it.
    Right-click>Browse with Adobe Bridge
    Select your pngs
    Tools>Photoshop>Load to photoshop layers (not sure how many layers this can handle--you may wind up having to do this in batches)
    Save your new psd
    In Flash, create a new symbol with a blank timeline
    Ctrl-R, navigate to the psd you made earlier
    Select all the Photoshop layers
    Check "create MovieClips for these layers."
    Convert layers to keyframes or flash layers (not important, since you probaby don't need to keep this symbol)
    OK
    You'll have Movie Clips, not Graphic Symbols, but maybe you can write or find a JSFL to convert them and then you can block select them, click the Properties button, and change the type from MovieClip to Graphc.

  • How can I move apps from one computer to the other?

    How can I move apps from one computer to the other?
    (preferably without iCloud)

    Backup your iTunes library to an external drive and onto the other computer
    http://support.apple.com/kb/ht1751

  • Home computer crashed.  How can I move stuff from iPod Touch to a new computer?

    Our home computer crashed.  How can I move stuff from iPod touch to a new computer?

    - Transfer iTunes purchased by:
    iTunes Store: Transferring purchases from your iPhone, iPad, or iPod to a computer
    - Transfer other stuff via the third-party programs discusses in this prevous discussion:
    Best iPod to PC

  • How can I move photos from my computer to a Thumb drive?

    How can I move photos from my computer to a Thumb drive?

    https://discussions.apple.com/message/16881894#16881894
    2 way to get the icon...
    Finder>Preferences>General, check what you want to show on Desktop.
    Finder>Preferences>Sidebar, check what you want to show in the Sidebar of all windows.

  • How can I move contact from one group to another?

    HOW CAN I MOVE A CONTACT FROM ONE GROUP TO ANOTHER GROUP?

    You usually make ​​contact groups via a computer (Mac or PC). If you use a mac and sync. via iCloud, you can go into Contacs.app and organize your contacts as you wish. Then (if) you sync with iCloud the groups you've changed or created will be displayed on your iPhone and (or) iPad.
    Hope this helped you.

  • How can I move bookmarks from one computer to another.  JUST BOOKMARKS, NOT ANYTHING ELSE

    How can I move Bookmarks from my MacBook Pro to my iMac; just Bookmarks, nothing else.

    Safari Bookmarks?
    Export bookmarks as a HTML file to a usb stick or something.
    Put the USB in your other computer and import bookmarks 

  • How can I move the ODI Work Repository from one server to another server?

    How can I move the ODI Work Repository from one server to another server?

    Hi,
    If you would like to move your source models, target models and project contents from Work repository 1 to another work repository.
    I.e. Dev. server to Prod Server.
    1. Firstly, replicate the master repository connections i.e. with same naming conventions manually
    2. Go to Dev. Server work repository -> File Tab -> Click on Export work repository (save it in a folder)
    3. After exporting, you can view the xml files in the folders.
    4. Now, Open the Prod. server and make sure you already replicated mas. rep. details.
    5. Now, right click on model and import source model in synonym mode insert_update (select source model from the folder where your xml file located)
    6. Similarily, import again target then Project.
    Now, check. It should work.
    Thank you.

  • How can I move my e mails from another provider on my I pad to icloud storage

    I Have 15,000 e mails I have that I need to keep but would like to move them to the cloud how can I move them from my e mail account to the cloud they are using up 10gig of storage on my I pad and would rather use the icloud storage rather then the hard drive. It won't let me update the operating system due to the hard drive being too full. Please help

    Use migration assistant, email it to the other computer or transfer the file using iChat.

  • How can I move an icon/file from one screen of my ipad to another?

    How can I move an icon/file from one screen on my ipad to another?

    Press and hold the icon until they start to wiggle. Then while holding it, drag it to the edge of the screen and wait for the page to switch, then let go of the app

  • How can I move an original Version from one Project to another Project?

    How can I move an original Version from one Project to another Project?

    From the Aperture User Manual:
    To move an image into a different project
    Drag the image [from the Browser] into another project in the Library inspector.

  • How can I move my left over money from my UAE account into USD for my American itunes account?

    How can I move my left over money from my UAE account into USD for my American itunes account?

    How can I go back to my US account then?? I only have .03 aed left..

  • Can any one tell me how can I move to a different folder pictures, that I've cloned, without them staying aggregated? They all come together to the other folder and I don't want that- thanks

    Can any one tell me how can I move to a different folder pictures, that I've cloned, without them staying aggregated? They all come together to the other folder and I don't want that… thanks

    There's more to it than that.
    Folders in Aperture do not hold Images.  They hold Projects and Albums.  You cannot put an Image in a Folder without putting it in a Project or an Album inside that Folder.
    The relationship between Projects and Images is special:  every Image must in a Project, and can be in only one Project.
    Images can be in as many Albums you want.  Putting an Image in an Album does not move it from the Project that holds it.
    You can make as many Versions from a Master as you want.
    What you want to do may appear simple to you, but it still much adhere to how Aperture works.  I still can't tell exactly what you are trying to do (specifically: Images don't live in Folders; moving an Image from a Folder is non-sensical).
    It can be very confusing (and frustrating) to get going with Aperture -- but it does work, and can be enormously helpful.  If you haven't, take a look at the video tutorials on Apple's Aperture support site.
    I feel as though I haven't helped you much -- but we need to be using the same names for interface items in order to get anything done -- and my sense is that you still haven't learned the names of the parts.

  • How can I move my /library folder to another drive?

    I'll try and keep this as brief as possible. (tl;dr version: My library folder is on the wrong drive. How can I move it?)
    About 18 months ago I switched the HDD in my mid 2009 MBP for an SSD and replaced the optical drive with a larger HDD for storage, which I then moved my home folder onto (though of course not the library folder).
    This weekend the HDD got corrupted and I had to do a full erase/restore through time machine, and until I had reformatted the HDD I could not even log in. Once I had erased it I could log in again, but although the old library folder still exists on the boot SSD, it has replaced the (of course now missing until my TM restore is complete) home folder with a new one on the HDD and set up a new default library folder.
    I could copy the old library files into the new folder, but I'd prefer to have the library on the SSD, so what I want to know is how would I get OSX to recognise the old library? Or if I just updated the new one, could I move it?
    I know moving the library is a bit of a minefield, so I'm hoping one of you can help!

    You should leave the Library folder that is at top-level on the Boot drive right where it is.
    The ~/Library (in your user_Id) folder should be moved off the Boot drive with the rest of your User files if you choose to move the Home folders.
    What are you talking about?

  • How can I move some track from music folder to the podcast or audiobook?

    I have a lot of audiobook in my hard drive.When I add these files to library,they place in the music section.How can I move Them to the audiobook section?
    I've tried to chenge their genre to the Podcasts or Books,but there is nothing happened.

    So, if she purchased a song from iTunes in her library, I will also have to purchase the same song to add to my library?

Maybe you are looking for