Issues with ActionListener and KeyListener, what am i doing wrong?

basically the program will complie, but not run properly, in appletviewer or a browser. The code for the buttons will be added later, but the test code seems to be working ok. The code for KeyListener does not move the square in the applet as it should, and when i close the applet it will dump a long error message to the dos window. if i comment out Action listener then KeyListener will work fine. if i comment out KeyListener then the applet will close with no error message to the dos window.
i'm new to java and i don't know if i am doing anything wrong. please help, thankyou.
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class Project22 extends Applet implements KeyListener, ActionListener {
private int score = 0;
private int speed = 5;
private int [] frame = {500, 500};
private int [] sqr_loc = {235, 235};
private char keyinput;
private Button new_b = new Button("New Ball");
private Button ext_app = new Button("Exit");
private int junk = 0; // debug
private Label message = new Label("start"); // debug
public void actionPerformed(ActionEvent event) {
Object source = event.getSource();
if(source == new_b) {    // not coded yet
++junk;
message.setText(Integer.toString(junk));
else if(source == ext_app) {     // not coded yet
++junk;
message.setText(Integer.toString(junk));
public void keyTyped(KeyEvent event) {}
public void keyPressed(KeyEvent event) {
     int keycode = event.getKeyCode();
if(keycode == KeyEvent.VK_RIGHT) {
if(sqr_loc[0] < 475) {
sqr_loc[0] += speed;
repaint();
else if(keycode == KeyEvent.VK_LEFT) {
if(sqr_loc[0] > 0) {
sqr_loc[0] -= speed;
repaint();
else if(keycode == KeyEvent.VK_UP) {
if(sqr_loc[1] > 0) {
sqr_loc[1] -= speed;
repaint();
else if(keycode == KeyEvent.VK_DOWN) {
if(sqr_loc[1] < 475) {
sqr_loc[1] += speed;
repaint();
public void keyReleased(KeyEvent event) {}
public void paint(Graphics g) {
g.drawRect(sqr_loc[0], sqr_loc[1], 25, 25);
}     // end paint
public void init() {
add(new_b);
add(ext_app);
add(message);
new_b.addActionListener(this);
ext_app.addActionListener(this);
addKeyListener(this);
requestFocus();
}     // end Project22

Perhaps the error message can help to determine the problem?

Similar Messages

  • All my purchased song from iTunes are not playing complete (iPod and computer with Windows Vista), unexpectedly stops and continues with next song. What am I doing wrong?

    All my purchased song from iTunes are not playing complete (iPod and computer with Windows Vista), unexpectedly stops and continues with next song. What am I doing wrong?

    Are the songs playing whole in iTunes? if not download them again.
    else read this Apple Support Article on your problem
    Have a nice day!

  • HT1343 On my 4 1/2 year old Macbook I could select multiple files  by highlighting a file and then moving cursor over a file lower in the list, and pressing shift-control-click. I can't do that in now with Mac Pro.  What am I doing wrong?

    ghlighting a file and then moving cursor over a file lower in the list, and pressing shift-control-click. I can't do that in now with Mac Pro.  What am I doing wrong?

    Holding down the control key will invoke "right-click."
    Depending on the View, holding down Shift will with either toggle the selection (Icon View), or it will make a continuous selection from the previous selection (List View or Column View).
    The only way to make a continuous selection in Icon View is to drag out a selection marquee around or through the icons.
    I can't remember the behavior of previous OS's.

  • I can receive but not send emails with my skynet account - what am I doing wrong ?

    I can receive but not send emails with my skynet account - what am I doing wrong ?
    I have no problems with my Yahoo account but I can not send emails with my skynet account.
    Actually in iPhone :
    Outgoing Mail Server > SMTP "relay.skynet.be"
    Primary server > Not Configured > Off
    Thank you ...

    When you set them up, did you set up both the incoming and outgoing email servers separately, and did you enter the correct SMTP server name, and enter your userid and password even though it says "optional"?
    Something else to try, if you haven't, is delete the accounts, connect the iPhone to iTunes, on the Info tab check the box to sync mail server settings, then sync. This should duplicate the settings from your computer to your iPhone.

  • Using my apple ID and password on Mobile Me, I get the message  "Verification Failed"  .  Could not communicate with the server.  What am I doing wrong?

    Using my Apple ID and password on Mobile Me, I get the message "Verification Failed".  Could not communicate with the server"  What am I doing wrong?

    There is a MobileMe forum.  You might have better luck their.

  • HT4623 just got a new i pad mini and its not syncing with my computer. What am i doing wrong

    just got a new ipad mini and its not syncing with my computer. What am i doing wrong

    What version of iTunes are you using? It needs to be version 11.x.
    iPad not appearing in iTunes
    http://www.apple.com/support/ipad/assistant/itunes/
    iOS: Device not recognized in iTunes for Mac OS X
    http://support.apple.com/kb/TS1591
    iOS: Device not recognized in iTunes for Windows
    http://support.apple.com/kb/TS1538
    IOS: Syncing with iTunes
    http://support.apple.com/kb/HT1386
    Apple - Support - iPad - Syncing
    http://www.apple.com/support/ipad/syncing/
     Cheers, Tom

  • Banner with a clickable link, what am I doing wrong???

    I am trying to make a web banner out of an image I have with a link added so when you click the banner it takes you to the website. It looks fine on my computer but when I saved and email it the image is gone but the link still works. What am I doing wrong?

    HTML emails require you to save the images on a server then link to those images with absolute links in the email.
    The recipient's email client also needs to be set up to view images (many aren't).

  • Dragging a JPopupMenu around with a mouse. What am I doing wrong?

    Hello,
    I need to move a JPopupMenu around with a mouse, but it isn' working out as expected.
    Menu is being moved erraticaly, jumping here and there a bit, and lagging behind the mouse movements.
    Although it is moving in general direction of mouse drags.
    Anyone has an idea what am I doing wrong?
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class JPopupMenuDragTest {
        public static void main(String[] args) {
            new JPopupMenuDragTest();
        JPanel contents = new JPanel();
        DraggablePopupMenu popup = new DraggablePopupMenu();
        public JPopupMenuDragTest() {
            contents.setPreferredSize(new Dimension(512, 384));
            contents.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    popup.show(contents, e.getX(), e.getY());
            showFrame(contents);
        void showFrame(JPanel contents) {
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setContentPane(contents);
            f.pack();
            f.setLocationRelativeTo(null);
            f.setVisible(true);
        class DraggablePopupMenu extends JPopupMenu implements MouseListener, MouseMotionListener {
            JButton btnDragger = new JButton("drag me");
            int clickx, clicky, menux, menuy;
            public DraggablePopupMenu() {
                add(btnDragger);
                btnDragger.addMouseListener(this);
                btnDragger.addMouseMotionListener(this);
            public void mousePressed(MouseEvent e) {
                clickx = e.getX();
                clicky = e.getY();
                Point locationOnScreen = getLocationOnScreen();
                menux = locationOnScreen.x;
                menuy = locationOnScreen.y;
            public void mouseDragged(MouseEvent e) {
                int xOffset = e.getX() - clickx;
                int yOffset = e.getY() - clicky;
                setLocation(menux + xOffset, menuy + yOffset);
            public void mouseClicked(MouseEvent e) {}
            public void mouseReleased(MouseEvent e) {}
            public void mouseEntered(MouseEvent e) {}
            public void mouseExited(MouseEvent e) {}
            public void mouseMoved(MouseEvent e) {}
    }

    Thanks, that kind of works. The point is, I have to use Java 1.5, which does not support getX/YOnScreen for MouseEvents.
    I changed the code to:
            public void mouseDragged(MouseEvent e) {
                Point p = e.getPoint();
                SwingUtilities.convertPointToScreen(p, (Component) e.getSource());
                setLocation(p.x - clickx, p.y - clicky);And everything seems fine, until iI drag the popup out of the containing JFrame.
    Then the disco starts.
    If you can find the answer for this, tat would be great, but thanks anyway.

  • ICloud not pushing apps between iPad and iPhone what am I doing wrong

    I have a new iPad2 and a new iPhone4.  I put iOS5 on both of them.  My understanding of this was when you purchased an app on one device it would push to your other devices.  I did this and the apps do not push to my other device.  I use the same Apple ID for both if that matters.  I set up iCloud on both devices, turned everything "on" and created an @me account.  What am I doing wrong?  Thank you in advance for any help...feeling like an iDiot

    I believe you are misunderstanding.  You don't sync apps between iPad and iPhone, and iCloud has nothing to do with any of this.  There is a setting in Settings -> Store where you can set each device to automatically download NEW apps, meaning that when you buy a new app on one device, the other automatically downloads it.  However, this is for new downloads only.
    For your existing apps, you can simply connect each device to your computer and move the desired apps to it in iTunes.  Or you can go to the App Store and re-download those apps.

  • I just bought an Ipod Nano for my husband from a friend. We cannot figure how to add songs. I have an Ipod Touch and everything I pull up on Itunes is dealing with mine...I can't do anything with his Nano. What are we doing wrong?

    I purchased an Ipod Nano from someone yesterday. How do I register it in my name and unregister the previous owner. I have a 4th gen Ipod touch and was told I could add songs from my library to the nano but we can't seem to do anything with it. HELP please!!

    Connect it to your computer and restore it as a new device. Then chose what music you want to sync with it and do so just like your Touch does.

  • HT2515 My cam works fine with every program except yahoo.  If I just sign into yahoo or even if I use ichat for yahoo, the webcam button will not highlight up.  How can I fix this and/or what am I doing wrong?

    Hello, my father recently passed (using his ID) and I took over the payments on his mac and took his computer.  I am not that familiar with mac, but am usually computer savy.  However, this one has me stumped.  I have no problem starting the built in cam and it seems to work fine with all other programs I've tried using it with.  However, it will not work with yahoo.  Whether I use normal yahoo messenger or if I try using Yahoo through I chat.  The cam button will not light up, therefore, it is not clickable.  Which ultimately means I cannot use my cam on yahoo, which is something I use 99% of the time compared to other programs.  So why is this happening and what solutions can I take to try and fix this?  The mac I am using is: Mac OS X, Version 10.7.4
    Thank you for any and all help, it is much appreciated. 

    Welcome to Apple Discussions!
    1) If the iTunes preference window is open when you connect your iPod, the iPod will not be recognized by iTunes.
    Also, iPods can work with many iTunes libraries, so that is not the problem here.
    Is all the software on your computer up to date?
    iTunes
    iPod Updater
    Updating iPod's Software
    Does the iPod show up in My Computer when connected to your computer? Does it say Do Not Disconnect?
    Try the steps listed here...
    iPod shows up in Windows but not in iTunes
    If you are going to use your iPod with multiple iTunes libraries (home and school)...
    Using iPod with multiple computers
    2) What part aren't you understanding. Here are a couple of free programs you can use to convert videos...
    MPEG Streamclip
    Videora iPod Converter
    The programs should come with documentation and instructions to convert videos.
    3) You can go to file-->add file to library, file-->add folder to library, or have iTunes open and drag the files into the iTunes library while viewing the library.. You can also import from CDs.
    iTunes needs to be adding the songs to the iPod. You cannot just add the song files to the iPod.
    btabz

  • TextFrames and Stories - what am I doing wrong?

    Hi,
    I have got problem with TextFrames and Stories in InDesign. So, I am executing this script:
    var myFrame = app.selection[0];
    var myStory = myFrame.parentStory;
    myID = myStory.id;
    alert("Sel: " + myID);
    alert("Story id: " + myStory.textFrames.length);
    First of all I'm getting handle to selected textFrame, then I am getiing handle and ID of Story, which contain this textFrame. Everything here works fine and we get here proper Story ID. But, when I execute the last line, I always get length=0. Why? If I selected a textFrame, which is a part of the story (I got the parentStroy attibute), the "length" in the last line should be always at least 1. But this is 0. I cannot understand why.
    So, how can I get all textFrames which belong to the story? I could admit, that when I execute this line:
    myStory.exportFile(myFormat, myFile);
    the content of the textFrame is put to file (like expected)....

    Probably because you're using CS3 or CS4. In these versions of InDesign, the Story.textFrames collection is the collection of text frames that are inline or anchored to the story.
    What you are interested in is the textContainers property (which is an array, by the way, so be careful about addressing the last member; you have to use: myStory.textContainers[myStory.textContainers.length - 1]).
    Actually, you can use:
    myStory.textContainers[0].endTextFrame;
    which is a clearly anachronistic name for what should now be called endTextContainer. This is less typing, but takes twice as long because it involves two calls to the object model.
    Dave

  • TS1347 My Outlook is set up and I'm trying to import contacts from my iphone into Outlook with no sucess.  What am I doing wrong?

    I am trying to import my contacts into Outlook from my iphone.  I can not get it to work.  My Outlook is all set up and running...

    IIf you previously had items backing up to the iCloud, changing to the new phone will take a while depending on how much data and apps your restoring to the new phone. If your like me with 1,000's of pics and videos, it's gonna take a while. Make sure your phone I plugged in, your on wifi and let it do its things. If you see all your apps updating, then it's doing something. If this is not your issue, then it could be the phone froze up. I have the 6 plus and recently switched from the 5, and it took a long time to restore from the cloud. Restoring from iTunes is quicker I guess, but I didn't have that option at the time and was dying to use the new phone I eaitrd 2 weeks for. Anyways, good luck and I hope I answered something for you.

  • External monitor with external mouse and keyboard. what am I doing wrong?

    I got a iBook G3 with 600 MHz , 640 RAM, running 10.4.10. I bought a external keyboard, mouse and got a free ViewSonic Monitor from school so I hoped that I would be able to use all of these while the lid of my computer was closed. I close it, wait a few seconds, press random keys on my external keyboard to wake it up and it at first appears that it works but then it just goes back to sleep after about 1 min at the most. If you could help me I'd appreciate it. THANKS!!!!

    You aren't doing anything wrong; the iBook is supposed to sleep whenever you close it. It's designed to work that way, ostensibly so that it won't overheat.
    Apple's word on the matter can be found in this Apple Knowledge Base article:
    http://docs.info.apple.com/article.html?artnum=88199
    Others have addressed the problem by simply darkening the display with the F1 key and leaving the iBook open an inch or so.

  • [unsolved] BCache issues - Can't figure out what I'm doing wrong

    My setup is as follows:
    SSD on /dev/sda
    HDD on /dev/sdb
    I'm doing a EFI setup, so basically I need nothing more that an ESP and ROOT partition on /dev/sdb. I don't mind too much if the ESP partition is cached, but I suspect that could cause problems.
    There's really no need to cache ESP, so my approach have been to only cache the root partition:
    make-bcache -B /dev/sdb2 -C /dev/sda
    Which seem to work.
    After this everything seems to go wrong. I've tried several different approached and following the arch, gentoo and the official guide, but regardless I continually stumble.
    Following the arch guide: https://wiki.archlinux.org/index.php/Bcache I run in to trouble already at step 3.
    for i in /dev/sd*; do echo $i; echo $i > /sys/fs/bcache/register_quiet; done
    But as I understand it, the fact that I can't write to register_quiet just mean that I don't need to. Well, that doesn't sound very sensible.
    Apparently I can skip step 4., but even so I've tried different approaches as I said. However, no matter what I do, I end up missing /dev/bcache0, /sys/block/bcache0 or something similar, thus preventing me from continuing.
    At this point I have no other options than to ask a few question here, and maybe get some advice.
    1. In the case described, does sdb need to become backing device, or is it sensible to only make sdb2 (root) the backing device? [probably solved]
    2. Assuming that sdb need to become the backing device, will EFI boot even be possible? [solved]
    3. is btrfs a necessity, or is any file system in theory viable? [Suspect I don't need to use btrfs]
    4. Whatever questions you may think I've left out. [still have issues]
    Thanks and best regards.
    Last edited by zacariaz (2013-08-19 15:15:12)

    Just a small update.
    I think I did it mostly right on the last try, however, I couldn't boot:
    Attempting to register /dev/sda with bcache
    ash: write error: Invalid argument
    Attempting to register /dev/sdb with bcache
    ash: write error: Invalid argument
    Attempting to register /dev/sdb1 with bcache
    ash: write error: Invalid argument
    Attempting to register /dev/sdb2 with bcache
    ash: write error: Invalid argument
    Waiting 10 seconds for device /dev/bcache0 ...
    ERROR: device '/dev/bcache0' not found. Skipping fsck
    ERROR: Unable to find root device '/dev/bcache0'.
    The only thing that comes to mind it that I made two boot entries with gummiboot, as I wasn't sure if I should define sdb2 or bcache0 as the root partition, but if that was the issue, I should at least get a boot menu I would think.
    So that's how it is right now. I haven't got a clue what might be wrong.
    Best regards.

Maybe you are looking for

  • Terms of Payment for credit memo

    Dear Friends: I have created  terms of payment (Z12). This has to be used in credit memo in customer - T.code F-27 .But in customer master, there is a different terms of payment.How can i use the newly created terms of payment(Z12) in T.code F-27. Th

  • Keyboard backlight on rMBP not automatically illuminating, what's wrong?

    Setting is on, used to work, but no longer does How can I fix this? Ignore- fixed turned setting off, rebooted turned it on , rebooted fixed.

  • Problems after playing COD4

    I have had problems with my imac freezing up after exiting COD4 (Mac version not Windows in Boot Camp) in Multiplayer mode (no problems in single player mode), not all the time but sometimes. Also starting up the next day it has sometimes not mounted

  • Patch p11879896_112020_Generic failed with req comp missing error

    Hi, Applying the subject patch on Linux 32 with opatch apply -invPtrLoc /u01/app/oraInventory/oraInst.loc failed (with the message Patch 11879896: Required component(s) missing : [ oracle.sysman.console.db, 11.2.0.2.0 ] ), the debug follows below. An

  • Brother printer won't print thru labview

    I have looked at the two big threads about printing via USB printers, but they don't address my issue. I recently upgraded to Windows 7, and now my report generation code will not work.  Anytime i attempt to print thru LV, the LED on my Brother print