JApplet and the Images --PLEASE reply fast

the problem is i am trying to put a .gif image into JApplet. no matter what i do it just DOESNT WANNA WORK! can anyone please post an example of working one?

import java.applet.*;
import java.awt.*;
import java.io.*;
import java.lang.*;
import java.util.*;
import java.lang.Object.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.border.LineBorder.*;
import javax.swing.border.*;
import javax.swing.*;
import java.awt.*;
import java.applet.*;
import java.util.Random;
public class MoveTheSquare  extends JApplet implements ActionListener
     public static int size = 100;
       public     static        int life = 80;
        public     static       int eneLife=50;
     private AudioClip ohboy2= getAudioClip(getDocumentBase(), "ohboy2.wav");
//      public Image bricks = getImage(getDocumentBase(),"bricks.gif");
    public static void main(String[] args)
        ApplicationFrame frame = new ApplicationFrame();
        frame.setBounds(50, 50, 900, 900);
        frame.setVisible(true);
        new ApplicationFrame();
    private static class ApplicationFrame extends JFrame
        public ApplicationFrame()
        super("Move the Sticky Figure!");
           // setDefaultCloseOperation(EXIT_ON_CLOSE);
            setSize(500, 600);
            JPanel content = new JPanel();
            ((JPanel) getContentPane()).setOpaque(true);
           // new WindowListener(1);
             ImageIcon bricks = new ImageIcon("bricks.gif");
             JLabel backlabel = new JLabel(bricks);
            getLayeredPane().add(backlabel, new Integer(Integer.MIN_VALUE));
            backlabel.setBounds(0,0,20000,2560);
            setLocation(500,600);
              //WindowListener1 = new WindowAdapter() {
              //public void windowClosing(WindowEvent e) {
              //System.exit(0);
              //setVisible(true);
            initUi();
        private void initUi()
            Container cp = getContentPane();
            Image img = getImage(getDocumentBase(), "bricks.gif" );
            cp.add(new MyPanel(img));
            cp.setLayout( new BorderLayout(0, 10) );
          //   addWindowListener1();
            cp.add( new JLabel(" Move the Sticky with the arrow keys:"), BorderLayout.NORTH );
            // Create the playing board and the squar
            Square sq = new Square( new Point(100, 100), 10 );
            Board board = new Board(sq);
            cp.add( board, BorderLayout.CENTER );
            // Register Key Bindings to move the square around. Read about the
            InputMap im = getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
            ActionMap am = getRootPane().getActionMap();
            // The LEFT arrow will move the suare to pixels two the left
            MoveSquareAction moveLeft = new MoveSquareAction(board, -3, 0);
            KeyStroke keyStrokeLeft = KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0);
            im.put( keyStrokeLeft, "left" );
            am.put( "left", moveLeft );
            // The RIGHT arrow will move the suare to pixels two the right
            MoveSquareAction moveRight = new MoveSquareAction(board, 3, 0);
            KeyStroke keyStrokeRight = KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0);
            im.put( keyStrokeRight, "right" );
            am.put( "right", moveRight );
            // The UP arrow will move the suare two pixels up
            MoveSquareAction moveUp = new MoveSquareAction(board, 0, -3);
            KeyStroke keyStrokeUp = KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0);
            im.put( keyStrokeUp, "up" );
            am.put( "up", moveUp );
            // The DOWN arrow will move the suare two pixels down
            MoveSquareAction moveDown = new MoveSquareAction(board, 0, 3);
            KeyStroke keyStrokeDown = KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0);
            im.put( keyStrokeDown, "down" );
            am.put( "down", moveDown );
            pack();
    // Class that represents the playing board
    private static class Board extends JPanel
          private Square square;
        public Board(Square sq)
            square = sq;
            setOpaque(true);
            setBorder( new LineBorder(Color.GREEN));
        int x=1;
        public void  paintComponent(Graphics g)
            super.paintComponent(g);
            g.drawImage( img, currentX, currentY, this );
               if (x==1)
            Point location = square.getLocation();
            String coordX = String.valueOf(location.x);
            String coordY = String.valueOf(location.y);
            String slife = String.valueOf(life);
                //g.drawImage(bricks, 0, 0, 500, 16, this);
              g.setColor(Color.red);
               g.fillRect(240,240,250,250);
               g.setColor(Color.GREEN);
               g.fillRect(0,00,40,40);
               g.setColor(Color.black);
            g.drawLine(location.x-5,location.y+5,location.x,location.y);
               g.drawLine(location.x+5,location.y+5,location.x,location.y);
               g.drawLine(location.x,location.y,location.x,location.y-7);
               g.drawLine(location.x-4,location.y-4,location.x,location.y-7);
               g.drawLine(location.x+4,location.y-4,location.x,location.y-7);
               g.fillOval(location.x-3,location.y-15,8,8);
               g.drawString(coordX,20,20);
               g.drawString(coordY,20,30);
               g.drawString("YOUR LIFE:", 00,70);
               g.drawString(slife,70,70);
               Random generator = new Random();
              int takeaway = generator.nextInt(25);
                 int fight = generator.nextInt(50);
               if (fight==4)
              x=0;
             life= life-takeaway;
              JOptionPane.showMessageDialog(null, "YOU ARE BEING ATTACKED!!!!! YOU LOST HEALTH:" +takeaway);
                slife = String.valueOf(life);
             g.drawString(slife,70,70);
             if (life<=0)
             JOptionPane.showMessageDialog(null, "you lose. bye.");
             System.exit(0);
             if (((location.x>=240) && (location.y>=240)) &&((location.x<=490) && (location.y<=490)))
             JOptionPane.showMessageDialog(null, "you Win! bye.");
             System.exit(0);
       Random generator = new Random();
       int fight = generator.nextInt(50);
       if (fight==1)
       x=1;
        public Square getSquare()
            return square;
    // The Action class that implements moving the square:
    private static class MoveSquareAction extends AbstractAction
        // The board this action acts on:
        Board board;
        // The number of pixels to move in the X- and Y-directions:
        int pixelsToMoveX;
        int pixelsToMoveY;
        public MoveSquareAction(Board board, int pixelsToMoveX, int pixelsToMoveY)
            this.board = board;
            this.pixelsToMoveX = pixelsToMoveX;
            this.pixelsToMoveY = pixelsToMoveY;
        public void actionPerformed(ActionEvent e)
            // Move the square and repaint the board:
            board.getSquare().moveX(pixelsToMoveX);
            board.getSquare().moveY(pixelsToMoveY);
            board.repaint();
    // Class that represents the black square we move around
    private static class Square
        private Point     location;
        private int          size;
        public Square(Point loc, int size)
            location = loc;
            this.size = size;
        public Point getLocation()
            return location;
        public int getSize()
            return size;
        public void moveX(int pixels)
            location.x += pixels;
        public void moveY(int pixels)
            location.y += pixels;
    public void actionPerformed(ActionEvent e)
             ohboy2.loop();//sound
}

Similar Messages

  • I inserted my new 8gb 4x4 RAM but when i boot up the computer and choose this computer it only says that i have 4gb ram inserted and the computer isn't faster then with 2gb!? please help me! I have a MBP from 2009

    I ordered my RAM 8GB from OWC (other world computing) and when i inserted the ram and booted up my computer it says that i only have inserted 4gb ram and the computer isn't faster than it was with 2gb!!! please help me... I've got a MacBook Pro (mid 2009)

    Improperly seating memory is the curse of everyone, even experts.  No one wants to "break" the memory or the slot by pushing too hard.
    So, try again.  Push maybe *just a twinge* harder to seat the memory (just a twinge).
    As to speed ... memory mainly lets you keep more things active concurrently.  Unless you were severely overtaxing your old memory and causing huge "Page Out" counts, only faster HD makes huge speed increases.

  • Big Colour and detail changes between Original Nikon RAW files and the images created on the Preview page!

    Big Colour and detail changes between Original Nikon RAW files and the images created on the Preview page! Yes there are distinct visual changes when I preview my Nikon NEF RAW Files.Please note I do not use iPhoto at all.
    If you view it as a contact sheet straight from the original folder there are no alterations but the moment you double click and want to 'Preview' it, this new preview page introduces very noticeable distortions : lighter shading goes missing and colour goes darker e.g orange turns red and mid blue goes deep blue!  Alarmingly the little column on the left of the preview page showing the collection shows the original file colours and then after a few seconds show the new distorted image...you can see this visible change and it takes place after a few seconds once you double click! Also if you use Apple's 'Cover Flow' to preview, this function will replace your original RAW file with the new 'altered preview' image!
    I have raised this with Apple but they have yet to reply...has anyone ever experienced this? I have used my Mac book for 18months only noticed it about 5 days ago!
    I went to Apple store and we tried it in other laptops and Macs and it happened to all of them so we think this is a software issue and not down to the laptop.
    Any help is much appreciated!

    Big Colour and detail changes between Original Nikon RAW files and the images created on the Preview page! Yes there are distinct visual changes when I preview my Nikon NEF RAW Files.Please note I do not use iPhoto at all.
    If you view it as a contact sheet straight from the original folder there are no alterations but the moment you double click and want to 'Preview' it, this new preview page introduces very noticeable distortions : lighter shading goes missing and colour goes darker e.g orange turns red and mid blue goes deep blue!  Alarmingly the little column on the left of the preview page showing the collection shows the original file colours and then after a few seconds show the new distorted image...you can see this visible change and it takes place after a few seconds once you double click! Also if you use Apple's 'Cover Flow' to preview, this function will replace your original RAW file with the new 'altered preview' image!
    I have raised this with Apple but they have yet to reply...has anyone ever experienced this? I have used my Mac book for 18months only noticed it about 5 days ago!
    I went to Apple store and we tried it in other laptops and Macs and it happened to all of them so we think this is a software issue and not down to the laptop.
    Any help is much appreciated!

  • I have one iPhone 8GB. after making upgrade of iTunes and software of iPhone, it's impossible to use the iPhone. There's no service! doesn't acept the code PIN! it only make emergency calls and the image in the phone is to conect to iTunes.What can i do?

    I have one iPhone 8GB. After making un upgrade of iTunes and software of iPhone, it's impossible to use it. There's no service! doesn't acept PIN code! it only makes emergency calls and the image in the iPhone is the sign to connect to iTunes. What can i do to solve it?

    Where are you and where did you get the phone.  This sounds like a classic symptom of someone who bought an iPhone that originated in the U.S. which was then hacked so it would run on a carrier network other than AT&T... Then, when updating the phone, it becare re-locked to AT&T.
    If that's what happened, you now own a paperweight. AT&T will NOT unlock them for any reason.
    If this isn't the case, please clarify where you are, what carrier you have and where you got the phone so we can begin troubleshooting.

  • I am trying to import developed images from LightRoom 5 in o Photoshop 6.  I am receiving this message and the images will not open.....'Could not open scratch file because the file is locked, you do not have necessary access permissions or another progra

    I am trying to import developed images from LightRoom 5 Photoshop 6 for further editing.  I am receiving this message and the images will not open.....'Could not open scratch file because the file is locked, or you do not have necessary access permissions or another program is using the file.  Use the 'Properties' command in the Windows Explorer to unlock the file. How do I fix this?  I would greatly appreciate it if you would respond with terms and procedures that a computer ignorant user, such as me, will understand.   Thanks.

    Have you tried restoring the Preferences yet?

  • I am trying to import developed images from LightRoom 5 into Photoshop 6.  I am receiving this message and the images will not open.....'Could not open scratch file because the file is locked, you do not have necessary access permissions or another progra

    I am trying to import developed images from LightRoom 5 into Photoshop 6.  I am receiving this message and the images will not open.....'Could not open scratch file because the file is locked, you do not have necessary access permissions or another program is using the file.  Use the 'properties' command in the Windows Explorer to unlock the file'.  This has not happened before.  How do I change this?

    Could not open a scratch file because the file is locked or you do not have the necessary access privileges. (…) | Mylen…
    Mylenium

  • I have an IPad 2 and an Iphone4, but as it suggests that I can click a photo on my iPhone and the image will also reflect simultaneously on my IPad does not happen, though I have activated cloud on my iPhone. What could be the problem.???

    I have an IPad 2 and an Iphone4, but as it suggests that I can click a photo on my iPhone and the image will also reflect simultaneously on my IPad does not happen, though I have activated cloud on my iPhone. What could be the problem.???
    Also in my iPhone4 the photos that I have downloaded manually from my computer cannot be erased from the phone, how do i do this.???

    Sounds like you are not running iOS 5 ..........
    Update your iPad 2 to iOS 5............
    I purchased an iPad 2 for my wife for Xmas and it did not come with iOS 5 so I had to update it......
    http://www.apple.com/icloud/get-started/
    http://support.apple.com/kb/HT4972

  • Make the link from the single cell of Bex Report and the image of bill

    Hi guys,
    my client scan every bill and archive the image by File.net technology.
    In our Bex Report we have the Bill number and we want to make the link from the single cell and the image of bill.
    The possible paths to solve the problem are:
           Replicate the image in BW and crate a link from the single cell and the image of document.
           Create an URL link from the single cell and the image of document archived on File.net server.
    In witch way we can to implement the two paths?
    Thank you.
    Alessandro

    Hi Alessandro,
    Have you seen "How To…Enhance your Web Query with the Table Interface"?
    You can find it in media library:
    https://websmp105.sap-ag.de/~form/sapnet?_SHORTKEY=01100035870000194044
    Best regards,
    Eugene

  • HT5019 I connect my macbook pro to an Epson wireless projector. The macbook can see the projector wirelessly and the image on the macbook is displayed on the projector. However on system ref., the arrangement tab does not show and thus cannot have multipl

    I connect my macbook pro to an Epson wireless projector. The macbook can see the projector wirelessly and the image on the macbook is displayed on the projector. However on system ref., the arrangement tab does not show and thus cannot have multiple view.
    I am trying to project Pro Presenter on the Epson projector such that I have the detail screen on the macbook and only the screen I want people to see on the projector display. This has not been possible because the arrangement tab on the Display section of the System Preference is not showing. If i tried to search for the arangement, it comes back with the message that there is not other source detected, hence the arrangement tab is not showing.
    I have also tried to connect the Epson directly to the Macbook but it still the same result, so its not because it is a wireless connection. Can someone advise me jhow to go around this problem. I have used windows before and it is very easy to extend ptojection on windows, but this system seems to be frustrating to me.
    Thanks,
    Toks

    Hi Toksyb!
    You may want to try clearing out the PRAM on your computer. This process is explained through this article:
    About NVRAM and PRAM
    http://support.apple.com/kb/ht1379
    Thanks for using the Apple Support Communities!
    Cheers,
    Braden

  • I downloaded a vector file from Shutterstock. How do I edit the text in Photoshop? If i enlarge the image- the pixels are awful and the image is distorted.

    i downloaded a vector file from Shutterstock. How do I edit the text in Photoshop? If i enlarge the image- the pixels are awful and the image is distorted.

    jessicae28493569 wrote:
    i downloaded a vector file from Shutterstock. How do I edit the text in Photoshop? If i enlarge the image- the pixels are awful and the image is distorted.
    What is the file format of the vector you downloaded?  Custom Shapes have a .PSP extension, and are placed according to this table.
    Preference filenames and locations in Photoshop CC
    They will then be loadable from the Custom Shapes drop down — click on the cog icon > Load shape > Find your downloaded vector.
    Once placed in the image, it will appear as a Shape layer, and can be edited with the Path, and Direct Selection tools (black and white arrows on the toolbar)

  • Last night suddenly when I right-click-view-images in firefox, they appear centered and against a black background. It's usually meant to be a white background and the image appearing at top left. How to revert it?

    I'm having trouble with something in firefox, it's quite minor but still bugs me. Last night suddenly when I right-click-view-images in firefox, they appear centered and against a black background. It's usually meant to be a white background and the image appearing at top left. I can't remember what I did to change this if it's my fault; if someone knows how to revert it I'd be thankful.

    cor-el : thanks for the pointers! I wish the solution isn't an add-on every time ... if such long-standing behaviour is going to change, the least that could be done is put in an about:config option to get back the old behaviour.

  • I'm having problems with videos, they shake and the images break up back and forth into striped colors, how do I fix this?

    I'm having problems with videos, they shake and the images break up back and forth into striped colors, how do I fix this?

    1) This is because of software version 1.1. See this
    thread for some options as to how to go back to 1.0,
    which will correct the problem...
    http://discussions.apple.com/thread.jspa?threadID=3754
    59&tstart=0
    2) This tends to happen after videos. Give the iPod a
    minute or two to readjust. It should now be more
    accurate.
    3) This?
    iPod shows a folder icon with exclamation
    point
    4) Restore the iPod
    5) Try these...
    iPod Only Shows An Apple Logo and Will Not Start
    Up
    iPod Only Shows An Apple Logo
    I think 3,4, and 5 are related. Try the options I
    posted for each one.
    btabz
    I just noticed that one of the restore methods you posted was to put it into Disk Mode First rather than just use the resstore straight off, I Have tried that and seems to have solved the problem, If it has thank you. previously I have only tried just restoring it skipping this extra step. Hope my iPod stays healthy, if it doesnt its a warrenty job me thinks any way thanks again

  • My MacBook Pro gets really hot when I open a video file of any kind and the video starts lagging and the image fades away, also with anything that starts the fan. Is extremely hot on the left upper corner. Is there something I can do about it?

    My MacBook Pro gets really hot when I open a video file of any kind and the video starts lagging and the image fades away, also with anything that starts the fan. Is extremely hot on the left upper corner. Is there something I can do about it?

    You are still under warranty.  Call Apple Care. Make sure you get a case number as all repairs have an additional 90 days of warranty. 
    #1 - You have 14 days from the date of purchase to return your computer with no questions asked.
    #2 - You have 90 days of FREE phone tech support.
    #3 - You have the standard one year Apple warranty.
    #4 - If you've purchased an AppleCare Protection Plan, your warranty last for 3 years.   You can obtain AppleCare anytime up to the first year of the purchase of your computer.
    Take FULL advantage of your warranty.  Posting on a message board should be done as a last resort and if you are out of warranty or Apple Care has expired.

  • I forgot my security question and the answer . please can you provided

    i forgot my security question and the answer . please can you provided

    The Three Best Alternatives for Security Questions and Rescue Mail
        1. Use Apple's Express Lane.
              Go to https://expresslane.apple.com ; click 'See all products and services' at the
              bottom of the page. In the next page click 'More Products and Services, then
              'Apple ID'. In the next page select 'Other Apple ID Topics' then 'Forgotten Apple
              ID security questions' and click 'Continue'. Please be patient waiting for the return
              phone call. It will come in time depending on how heavily the servers are being hit.
         2.  Call Apple Support in your country: Customer Service: Contact Apple support.
         3.  Rescue email address and how to reset Apple ID security questions.
    A substitute for using the security questions is to use 2-step verification:
    Two-step verification FAQ Get answers to frequently asked questions about two-step verification for Apple ID.

  • Movies purchased from iTunes get choppy and the image stutters and skips

    I have at least 11 movies that I have either downloaded directly from iTunes or received through iTunes because they were bundled as a digital copy with a BD.
    I have a mid 2009 Macbook Pro with 8 GB of RAM and a 2.53 GHz Intel Core 2 Duo processor. OS 10.9.5.
    ANY time I try to watch one of the movies through iTunes, either on my computer screen or an external display, they reach a point where they start pausing and then speeding up or freezing then playing again a few seconds later having skipped some of the frames in-between, causing me to have to rewind them to see the things I missed. And they don't always skip/chop at the same places either. But it does seem to get worse the longer I watch.  The sound plays normally throughout but the images mess up. I am beyond frustrated by this. I just want to be able to watch my movies and the special features without also wanting to throw my whole system out of the window.
    I want to be able to watch these movies on my television, and eventually I want to get an AppleTV so I can stream them, but will that just keep messing up too? Because if so then I don't want to waste my money. (Really I would rather be able to stream them using one of the many devices I already own but that's another issue entirely). I'm a film major and this is very dear to me and I just need an answer.
    If anyone knows of a fix or at least not a fix but a dejecting truth about my situation I would appreciate the input.

    When you have the problem, note the exact time: hour, minute, second.  
    These instructions must be carried out as an administrator. If you have only one user account, you are the administrator.
    Launch the Console application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad and start typing the name.
    The title of the Console window should be All Messages. If it isn't, select
              SYSTEM LOG QUERIES ▹ All Messages
    from the log list on the left. If you don't see that list, select
              View ▹ Show Log List
    from the menu bar at the top of the screen.
    Each message in the log begins with the date and time when it was entered. Scroll back to the time you noted above.
    Select the messages entered from then until the end of the episode, or until they start to repeat, whichever comes first.
    Copy the messages to the Clipboard by pressing the key combination command-C. Paste into a reply to this message by pressing command-V.
    The log contains a vast amount of information, almost all of it useless for solving any particular problem. When posting a log extract, be selective. A few dozen lines are almost always more than enough.
    Please don't indiscriminately dump thousands of lines from the log into this discussion.
    Please don't post screenshots of log messages—post the text.
    Some private information, such as your name, may appear in the log. Anonymize before posting.

Maybe you are looking for

  • Macbook Pro 7.1 not booting up after Software update

    Hello everyone, I have a problem, but first some context? I recently got my mom's old Macbook Pro(7.1) with Intel's 2.4 Ghz C2D and Nvidia 320M graphics. A small upgrade from my 2009 MBP(5.5) but is in much better shape than my old machine. In that u

  • The App store application crashes whenever I try to open the application. What can I do?

    The App store application crashes whenever I try to open the application. What can I do?

  • Rendering dicom image in ADF page

    ADF/JDeveloper11g Hi dear Experts, I am working on implementing to render dicom image in JSP page as featured in [Oracle DB 11g multimedia|http://www.filibeto.org/sun/lib/nonsun/oracle/11.1.0.6.0/B28359_01/appdev.111/b28416/ch_cncpt.htm] . I f anyone

  • Text element issue

    hi, Hi, In a custom trasaction , I have text element . When I transport that text upper regions , I am not able to see in transaction. But I can see that text in the Text-symbols( Program->GOTO--> text-symbols) let me know any suggestions. thnks.

  • MediaSource 5 takes up to 3 minutes to start

    Hi, I just intsalled the X-fi USB and found that it takes a long time to load its applications, especially creative mediasource 5. Anyone know why this might be?