Problem in the game bomberman with  the position of the icon bomb

hi
in this code the player move with arrows in any where and when u press the space button bomb appear
but the bomb not appear in the position where the player stay and the player go to anthor place
please test my code to understande my problem
import javax.swing.JFrame;
public class Mainprogram extends JFrame {
    private MainBord mainbord;
    public Mainprogram() {
        mainbord = new MainBord();
        addKeyListener(mainbord);
        getContentPane().add(mainbord);
    public static void main(String[] args) {
        JFrame frame = new Mainprogram();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(800, 900);
        //frame.setResizable(false);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class MainBord extends JPanel implements KeyListener {
    private BufferedImage bord;
    private JLabel bomabr_label;
    private JPanel bombar_panel;
    private ImageIcon divider_icon,bombar_icon,bomb_icon;
    private Graphics g;
    private int x;
    private int y;
    private int dividerSize = 40;
    public MainBord() {
        drawimage();
        drawComponents();
    private void drawComponents() {
        divider_icon = new ImageIcon(getClass().getResource("wall.gif"));
        bombar_icon = new ImageIcon(getClass().getResource("bombar.gif"));
        bomb_icon=new ImageIcon(getClass().getResource("bomb.gif"));
        x = (bord.getWidth() - (divider_icon.getIconWidth() + dividerSize) * 8) / 2;
        y = (bord.getHeight() - (divider_icon.getIconHeight() + dividerSize) * 8) / 2;
        for (int i = 0; i < 8; ++i) {
            for (int j = 0; j < 8; ++j) {
                divider_icon.paintIcon(this, g, (divider_icon.getIconWidth() + dividerSize) * i + x, (divider_icon.getIconHeight() + dividerSize) * j + y);
        bombar_panel = new JPanel();
        bomabr_label = new JLabel(bombar_icon);
        bombar_panel.add(bomabr_label);
    private void drawimage() {
        bord = new BufferedImage(800, 900, BufferedImage.TYPE_INT_RGB);
        g = bord.getGraphics();
        g.setColor(Color.ORANGE);
        g.fillRect(0, 0, 1000, 1000);
    @Override
    public void paint(Graphics g) {
        super.paint(g);
        g.drawImage(bord, 0, 0, this);
        bombar_icon.paintIcon(this, g, x - bombar_icon.getIconWidth(), y - bombar_icon.getIconHeight());
    public void keyTyped(KeyEvent e) {
    @Override
    public void keyPressed(KeyEvent e) {
        switch (e.getKeyCode()) {
            case KeyEvent.VK_RIGHT:
                x += 5;
                break;
            case KeyEvent.VK_LEFT:
                x -= 5;
                break;
            case KeyEvent.VK_UP:
                y -= 5;
                break;
            case KeyEvent.VK_DOWN:
                y += 5;
                break;
            case KeyEvent.VK_SPACE:
                x=bombar_icon.getIconWidth();
                y=bombar_icon.getIconHeight();
                bomb_icon.paintIcon(this, g, x+dividerSize, y+dividerSize);
                break;
        repaint();
    public void keyReleased(KeyEvent e) {
}the problem in the last case in the switch
please refactor it to ucerstande how you do this .
the picture use in my code here:
http://www.4shared.com/file/75272822/8ecd434d/pictures.html
thanks
beshoy

you're doing it all wrong
1) don't use getGraphics()
2) don't override paint() for swing components - override paintComponent()
3) do all your graphics in paintComponent - not in the listener
your problem is that the bomb should appear over the 'player' when spacebar pressed?
if so, I've stripped your code down to just that problem.
if this works the way you want it to, then simply modify your main program accordingly
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class MainBord extends JPanel {
    private ImageIcon bombar_icon,bomb_icon;
    private int x = 100;
    private int y = 100;
    boolean paintBomb = false;
    public MainBord() {
        setFocusable(true);
        bombar_icon = new ImageIcon(getClass().getResource("player.gif"));
        bomb_icon=new ImageIcon(getClass().getResource("bomb.gif"));
        addKeyListener(new KeyAdapter(){
          public void keyPressed(KeyEvent e) {
            switch (e.getKeyCode()) {
                case KeyEvent.VK_RIGHT:
                    x += 5;
                    break;
                case KeyEvent.VK_LEFT:
                    x -= 5;
                    break;
                case KeyEvent.VK_UP:
                    y -= 5;
                    break;
                case KeyEvent.VK_DOWN:
                    y += 5;
                    break;
                case KeyEvent.VK_SPACE:
                    paintBomb = true;
                    break;
            repaint();
    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.setColor(Color.ORANGE);
        g.fillRect(0, 0, getWidth(), getHeight());
        bombar_icon.paintIcon(this, g, x, y);
        if(paintBomb) bomb_icon.paintIcon(this, g, x, y);
        paintBomb = false;
class Mainprogram{
    public static void main(String[] args) {
      SwingUtilities.invokeLater(new Runnable(){
        public void run(){
          JFrame frame = new JFrame();
          frame.getContentPane().add(new MainBord());
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setSize(800, 600);
          //frame.setResizable(false);
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
}

Similar Messages

  • Big Fish Games stop working in Mavericks.  What do I do? I have re-installed them and the manager app, and nothing.  I have not gotten an answer from Big Fish tech staff.  Thought the problem might be with Maverick.  all the games worked with Snow Leopard

    Big Fish Games stop working in Mavericks.  What do I do? I have re-installed them and the manager app, and nothing.  I have not gotten an answer from Big Fish tech staff.  Thought the problem might be with Maverick.  all the games worked with Snow Leopard
    Any body have this kind of problem.  What was done to correct it. . .

    I can't wait to get a new phone as well. LG Revolution owners should be comped for this phone if Verizon intends to keep them as customers.

  • We like to play games with Spigo. But the games do'nt come totaly on the PC. I think they are 75 %. Can you help us? r.sissing@planet.nl

    # Question
    We like to play games with Spigo. But the games do'nt come totaly on the PC. I think they are 75 %. Can you help us? [email protected]

    Do you mean that the game doesn't load or that you do not see the complete page?
    Reset the page zoom on pages that cause problems: <b>Beeld > Zoomen > Herinitialiseren</b> (Ctrl+0 (zero))
    * [[Page Zoom]]
    * [[Text Zoom]]

  • I can't connect anymore on Game Center with my account on the Ipod Touch of my girlfriend, I sign in then it ask me the password of my girlfriend's account and automaticaly log me on her account... What can I do?

    I can't connect anymore on Game Center with my account on the Ipod Touch of my girlfriend, I sign in then it ask me the password of my girlfriend's account and automaticaly log me on her account... What can I do?

    Is the camera damaged? Could be a hardware problem.
    Try:
    Close the Camera app in the multitasking bar, then try again.
    Restart/Reset/Restore your iPod. In that order.

  • My husband has a iphone, now i have one to. We want to work with the same calendar, but i want to play in the game center with my own name... how can i do that? and still use the same calendar

    My husband has a iphone 4 8Gb, now i have one to. We want to manage our calendar with icloud. We use the apple id that my husband made, but i want to play in the game center with my one name and games. How can i do that?

    Sounds like you encrypted your iPhone backup, & if so it's asking for the encrypted backup password. Do you have a company Exchange account on your phone?

  • I am having problems with my macbook pro and the dock.  About every fourth time I start the computer, the dock flashes on and off, then goes completely off and all I get is the spinning ball with brief moments of the cursor.  But the computer locks up.

    I am having problems with my macbook pro and the dock.  About every fourth time I start the computer, the dock flashes on and off, then goes completely off and all I get is the spinning ball with brief moments of the cursor.  But the computer locks up.

    Do you have Parallels installed by any chance?  There is a known problem that causes symptoms similar to this.  You do not need to actually be running Parallels at the time and nothing in ActivityMonitor would point to Parallels.  An update corrects the problem:
    http://kb.parallels.com/111541

  • After updating to iOS7 I am trying to log in the Game Center with my  user ID  and it says that is in use and I need to enter another one?

    After updating to iOS7 I am trying to log in the Game Center with my  user ID  and it says that is in use and I need to enter another one?

    You may be able to find your Apple ID at Look up your old and forgotten Apple ID

  • Since you don't allow emails any more – I suspect because of the numerous complaints with your service and the way you treat people that you don't want documented, I am calling and I want this call recorded for future reference. I have been a long time fa

    Since you don’t allow emails any more – I suspect because of the numerous complaints with your service and the way you treat people that you don’t want documented, I am calling and I want this call recorded for future reference.
    I have been a long time faithful customer of vzw and although the past year I have been late on payments many times and really couldn’t afford your exorbitant prices for services lots of other companies offer sometimes three times cheaper than what you charge, I have hung in there trying my best to meet my obligations.
    This month has been no exception. You don’t know the background; the whole story of people’s lives. I know you could care less because all you care about is the profit-the money that comes in.
    I was told when I agreed to pay my bill on the third per the recorded message that I had 14 days to pay…you cut me off anyway. The phones are not the tissue; your suspending my service means I cannot work. I may lose my job…how do you justify that? In any case? The least you could do would be to keep 4986 on and cut the phones off. But no. You refuse to compromise and meet the basic needs of your customer. What does that say about your company? I tried to call back on three separate occasions to tell you I couldn’t pay because of unexpected expenses but couldn’t get out of the automated system…sadly couldn’t get to a real person which also speaks volumes to me.
    All this tells me this is a company I don’t wish to be affiliated with any more. As soon as I can, I will discontinue service with you…I know you could care less. I will honor the remaining portion of the contract but that’s it. You don’t deserve my business. I am a good, hardworking person who, at the sacrifice of myself and my needs, always pays her bills…albeit late at times. I realize others tell you stories and lies to justify themselves. That’s not me. If you knew what I had been through the last 7 yrs you would marvel that I am  still on my feet…don’t judge too quickly. You could be wrong…and in my eyes you are by doing this to me.
    God will see us through this extremely scary time of that I have no doubt. No thanks to your company and lack of understanding and mercy. I am doing the best I can. Sadly you are not.
    See I have choices. MANY choices of providers for services you offer. I don’t have to be treated like this. I don’t have to succumb to your coldness and callousness. I intend to choose better (and cheaper). If your company doesn’t get the “people factor” back you will be sorry.

    Problem here is you admit you cannot afford the service.
    And you want to blame Verizon for losing a job because you have no cell phone.
    If your job depends on that phone I would pay it on time every time if you need a job to pay your bill.
    No other service is going to treat you any different. And if you cannot afford Verizon's monthly invoice how are you going to afford new devices, activation fees, possible security deposits on any other cellular carrier? You can't.
    Also if you made an arraignment to pay and then decide you cannot do so, why should Verizon extend you service or credit, or why is it you want to use the service and data and not pay for it as agreed.
    Get a prepay phone. Its evident the cost is too high for you to afford on post pay.
    Good Luck

  • How can I share the home folder with different accounts on the same mac?

    Hi, here's a question:
    How can I share the home folder with different accounts on the same mac?
    The whole point being not to have to install all my apps, and move all my files each time between users.
    The second thing would be to be able to modify one document on one account, and have it changed on the other account without having to copy it.
    I would like to have a pro and a private account on my mac.
    Thanks for you answers,
    Doug

    Your apps should not be installed in your home folder--they should be in /Applications where every user can access them.
    If you want to share things between users on the same Mac, use the /Users/Shared folder. Keep your home folder private. Trying to defeat the protections on the home folder subfolders just gets messy. I've never bothered to figure out all of the problems associated with it so I can't explain how to do it.
    Even with using Shared, you would need to alter the ACLs on the shared folder in order to allow both users to modify the documents.
    You must create a Group in Users & Groups and put each user in that group. Then create a folder inside /Users/Shared where you want to share the various files.
    Then, add an ACL to the shared folder that gives the group special permissions. on that folder.
    sudo chmod -R +a "<sharinggroup> allow delete,chown,list,search,add_file,add_subdirectory,delete_child,file_inherit,directory_inherit" /Users/Shared/<sharing folder>
    Replace <sharinggroup> and <sharingfolder> with the name of your group and your folder. Then, run the command in the Terminal.
    With that ACL, each user in <sharinggroup> will be able to alter the files created by any user in the group in that <sharingfolder>.
    Essentially, the client OS is not designed for true file sharing among the individual users. It is designed to isolate each user account from the others.

  • The server responded with an error. The request for account "Yahoo" failed. The server responded with "502" to operation CalDAVAccountRefreshQueueableOperation

    The server responded with an error. The request for account "Yahoo" failed. The server responded with "502" to operation CalDAVAccountRefreshQueueableOperation

    I am tired of how Yahoo has gotten worse and worse. It is the ONLY account I get problems with DAILY (even after removing and re-adding). AOL will act up once in a while not taking a saved password but accepting it when OK is clicked.... But Yahoo is always responding with such errors.... Today's calendar error is:
    The request (CalDAVAccountRefreshQueueableOperation) for account “Yahoo” failed.

  • I am trying to link coc between a new ipod and my iPad. The iPad was the old device. I did as I was supposed to by logging in the Game Center, then opening coc, and went thru the tutorial. The Game Center keeps trying to load the new village on my iPad an

    I am trying to link coc between a new ipod and my iPad. The iPad was the old device. I did as I was supposed to by logging in the Game Center, then opening coc, and went thru the tutorial. The Game Center keeps trying to load the new village on my iPad and not the other way around. It basically is trying to make my old village the new village, meaning I lose a lot of progress. How do make it combine the 2? If I cannot, is there a way to remove the new village off the Game Center and add the one I want to be saved? Thank you.

    You'll have to contact the app developer for help with this.

  • I am going to japan with an Ipod nano and Iphone 4. Do I need a converter? or does the one the iphone comes with that plugs into the wall enough?

    I am going to japan with an Ipod nano and Iphone 4. Do I need a converter? or does the one the iphone comes with that plugs into the wall enough? I know i wont need an adapter because it will fit into the wall outlet, but voltage wise, will i need a converter? Japan runs on 100 V. I am so confused on all of this...

    As long as the adapter is 2 pronged, then you should be able to use it without any problems.
    B-rock

  • Every time I try to play scrabble, the game comes up then jumps to the app store prompting to download a different game

    when I try to play scrabble on my iPad the game comes up then jumps to the app store prompting me to download a game, cannot play scrabble.

    Try this  - Reset the iPad by holding down on the Sleep and Home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider - let go of the buttons. (This is equivalent to rebooting your computer.) No data/files will be erased. http://support.apple.com/kb/ht1430
    iOS 7: Help with how to fix a crashing app on iPhone, iPad (Mini), and iPod Touch
    http://teachmeios.com/help-with-how-to-fix-a-crashing-app-on-iphone-ipad-mini-an d-ipod-touch/
    Troubleshooting apps purchased from the App Store
    http://support.apple.com/kb/TS1702
    Delete the app and redownload. (I had to do this once with Scrabble.)
    Downloading Past Purchases from the iTunes Store, App Store and iBooks Store
    http://support.apple.com/kb/ht2519
     Cheers, Tom 

  • I have a Time Capsule on which I back up 2 MacBooks and on my wife's machine she keeps having Airport Utility popping up all the time with a yellow button flashing on the left and a Red button on the right side with a "1" in the middle of it.

    I have a Time Capsule on which I back up 2 MacBooks and on my wife's machine she keeps having Airport Utility popping up all the time with a yellow button flashing on the left and a Red button on the right side with a "1" in the middle of it. Can any one tell me what is wrong. I read where when the yellow light was flashing there was a problem, but I am a novice at this and have no idea where to turn. It seems to be backing up on a regular basis.

    On the Mac......
    Open up Macintosh HD > Applicatons > Utilities > AirPort Utility
    Click on the Time Capsule icon, then click Edit in the small window that appears
    Click the Network tab at the top of the next window
    Change the setting for Router Mode from the current DHCP and NAT to read Off (Bridge Mode), then click Update at the lower right of the window, and wait a full minute for the Time Capsule to restart to a green light.
    Then.....very important
    Power off the Time Capsule and your Arris modem/router for a few minutes
    Start up the Arris first, and let it run a few minutes by itself
    Start up the Time Capsule next the same way
    Your network will now be correct, and your printing capabilities will improve.
    If Time Machine backups do not occur now, post back and we will tackle that next.

  • When I run ical on my mac I get the error:   The server responded with an error. The request for account "Yahoo!" failed. The server responded with "504" to operation CalDAVAccountRefreshQueueableOperation.

    When I run ical on my mac I get the error:  
    The server responded with an error.
    The request for account “Yahoo!” failed.
    The server responded with
    “504”
    to operation CalDAVAccountRefreshQueueableOperation.
    I hit "go online" and almost immediately I get the same message again.  Any ideas?

    I am tired of how Yahoo has gotten worse and worse. It is the ONLY account I get problems with DAILY (even after removing and re-adding). AOL will act up once in a while not taking a saved password but accepting it when OK is clicked.... But Yahoo is always responding with such errors.... Today's calendar error is:
    The request (CalDAVAccountRefreshQueueableOperation) for account “Yahoo” failed.

Maybe you are looking for