Keypress question

Hi
I am completly new to action scriping and have tried
diligently to find the answer in the forums but most of it such a
foreign language to me, so I am hoping someone can help me out with
a straight answer and the exact bit of code I need.
What I need flash to do:
when i press the key "J" it jumps to frame 56 and plays a
movie clip named "j2".
when I let go, the flash file continues where it left off.
I am using Flash 8
Thanks very much
Bill

Bill,
>> when i press the key "J" [should] jump to frame 56
and play a
>> movie clip named "j2".
>> when I let go, the flash file continues where it
left off.
> I am using Flash 8
Okay, the basic "template" for responding to key strokes in
ActionScript
2.0 is this:
var listener:Object = new Object();
listener.onKeyUp = function():Void {
trace("A key has been pressed");
Key.addListener(listener);
In line 1, an arbitrarily named variable, listener, is
declared and set
to an instance of the Object class. This gives you a generic
object that
you can use for just about everything. (Ultimately,
everything in
ActionScript *is* an object -- and each type of Object is
defined by its
class entry in the ActionScript 2.0 Language Reference. Look
up "MovieClip
class" to see what features are available to movie clips;
look up "TextField
class" to see what features are available to dynamic and
input text fields,
and so on.)
In lines 2 - 4, an onKeyUp property is created for the
listener object.
Why onKeyUp? That's an event of the Key class, which handles
keyboard-related phenomena. In this case, you're building an
"event
listener," and the listener object acts as a liaison for the
events of the
Key class. An anonymous function literal is assigned to this
onKeyUp event,
and the function simply traces a message to the Output panel.
In line 5, the Key class is associated with the listener
object, which
wires everything up.
In your original post, you spoke of sending the playhead
somewhere when
a key is pressed, rather than released. That's fine ...
consult the "Key
class" entry in the documentation and you'll find that an
onKeyDown event
also exists. No only that, but a number of properties,
methods, and events.
To do something when only the "J" key is pressed, you could
use an if()
statement ...
var listener:Object = new Object();
listener.onKeyDown = function():Void {
if (Key.isDown(74)) {
// do something
Key.addListener(listener);
What on earth is Key.isDown()? That's a method of the Key
class.
What's 74? That's the key code for the letter "J" (upper- or
lowercase).
How did I know that? I searched "Keyboard Keys and Key Code
Values" in the
Help docs.
In place of "// do something," you would, of course, program
what you
actually want to occur. Based on your original post, that
would be
something like ...
var listener:Object = new Object();
listener.onKeyDown = function():Void {
if (Key.isDown(74)) {
gotoAndStop(56);
Key.addListener(listener);
... that's a start, at least. If you also want a movie clip
on that frame
to play, you'll have to reference that movie clip by its
instance name and
invoke the MovieClip.play() method ...
var listener:Object = new Object();
listener.onKeyDown = function():Void {
if (Key.isDown(74)) {
gotoAndStop(56);
j2.play();
Key.addListener(listener);
IMPORTANT: If the j2 MovieClip instance doesn't already
appear in
whatever frame carries this code, you won't be able to
reference j2 --
because "it doesn't exist" on that frame. You'll have to
either stretch out
that movie clip in the timeline so that it does, and maybe
set its
visibility to 0, then do something like this:
j2._visible = false;
var listener:Object = new Object();
listener.onKeyDown = function():Void {
if (Key.isDown(74)) {
gotoAndStop(56);
j2._visible = true;
j2.play();
Key.addListener(listener);
At any rate, I hope that gives you a good start.
David Stiller
Adobe Community Expert
Dev blog,
http://www.quip.net/blog/
"Luck is the residue of good design."

Similar Messages

  • Lost keypresses and mouse clicks:  Hardware problem?

    I recently bought an Intel MBP, and I've been noticing strange behaviors with regard to keypresses and mouse (touchpad) clicks getting lost sometimes. The problems I'm having are hard to reproduce intentionally, but I can hear the keypresses and mouse button clicks when I do them, yet nothing happens. While it's possible, that I sometimes am hitting the wrong key, I have been paying closer attention lately to this problem, and of course, the mouse button kinda hard to hit incorrectly. Here are some examples of weird things I encounter:
    If I click in a text field in Safari, sometimes the first keypress (and only the first) will get lost.
    Sometimes, the first keypress I type right after clicking gets lost. For instance, just now, I noticed a typo in the above sentence, so I clicked on the character and hit the Delete key. The cursor was in the right place, but the delete didn't happen. I had to press the key again.
    Sometimes, even when the window for sure has focus and the pointer is squarely pointing to a link, the first click on the link won't take. I have to click it again. Since Safari doesn't have adequate feedback for when you click something, that can get particularly frustrating. Similar things happen with buttons in applications or on the title bar.
    If I'm using an X11 app, and I copy/paste with the clipboard, the touchpad won't respond to movement for 2 or 3 seconds afterward. This is particularly visible with "nedit". I don't think this is an "ignore accidental touchpad input" issue, because this only happens with clipboard actions; other keys don't have this effect. I haven't noticed this with native apps.
    However, I have noticed in X11 and native apps, sometimes, Ctrl/Cmd-C and Ctrl/Cmd-V will be ignored. They're never ignored if I selected the text using the keyboard (shift+arrows), but if I select the text with the mouse and then use the shortcut to copy, the copy/paste sometimes doesn't happen.
    I have noticed that if I am more deliberate about clicks (make sure to hold the button down longer), the probability of losing the event SEEMS to be reduced, but not eliminated. Is there a debounce circuit involved that's causing me trouble?
    This kind of loss of input is unusual to me. I have a number of Windows and Linux PCs, and I've never experienced this sort of thing. I've also used a few Macs at school before I got this one and didn't notice anything weird.
    Can anyone shed some light on this for me? It would seem odd that I should have to modify my keyboard/mouse using behavior when switching to the Mac. If the problem is hardware, how can I prove it? (Perhaps I could boot Knoppix from a CD and mess around a bit.) If the problem is software, is this a case of MacOS trying to second-guess user input?
    Thanks!

    Theosib,
    Apple regularly monitors these boards, but you may never see a response from Apple directly. Assume this is a user to user forum. If you are having a problem with the computer and need a response from Apple call 1-800-APLCARE and speak to customer relations at that office if the technician is not able to satisfy your needs.
    Your problem while not unheard of, is more uncommon than the boards may make you believe.
    Remember, Spotlight is constantly indexing. If your hard drive is overfull, it may take longer for Spotlight to index, thus cause a multitasking delay. If you have many Dashboard widgets, they may all be trying to access the net for updates at once, and again, a delay might happen. I've written a FAQ* about several other factors which may affect Mac OS X speed, which could in theory also affect keyboard input:
    http://www.macmaps.com/Macosxspeed.html
    And of course, you should always check Apple menu -> System Preferences -> Keyboard and Mouse to make sure your input settings are the ones most comfortable for you when using the keyboard. It is possible a repeat rate could cause a delay.
    Edit: I attempted to answer another of your questions here recently with an update:
    http://discussions.apple.com/click.jspa?searchID=-1&messageID=3988468
    Please take a look and see if it answers your question.
    * Links to my FAQs may give me some compensation.

  • Text entry box question

    Hey all, I am currently working on a project and have run
    into a snag and cant seem to find the answer, or even if what i
    need can be done.
    Question 1: how do I advance a slide with the correct entry
    of a text field without a button or keypress?
    Question 2: if this is not possible, how can i have a text
    entry box check for correct input using a custom button?
    Any help would be appreciated, Thanks.
    M. Anderson

    Hi M. Anderson
    The first question may be accomplished if (and only if) the
    last letter the user is supposed to type is unique among all the
    letters. For example, BOFFO would not work. O occurs twice. But
    LIFE would work, because E is unique. You could then configure the
    letter E to be the shortcut for the Text Entry Box.
    For the button, it's pretty easy. Click the Options tab and
    look at your choices. Make sure the "Button" option contains a
    check mark. After you dismiss the dialog, you end up with a rather
    generic looking button. But once you enable the button, you may
    then double-click it to edit its properties. You could choose an
    image, or you could make it invisible and position the invisible
    button over another image you placed on the slide as a simple image
    object.
    Hopefully this helps some... Rick

  • Keypress Events

    Hi, everybody, it is my first question to you all.
    Does anybody have any function that would capture keypress events, or
    any information that would be helpful in capturing them? For example,
    when a user presses the <down arrow> or F1 key. I am currently using
    the AfterValueChange event to capture keys that display.
    Thanks,
    Scott Watters
    Systems Analyst
    Carlson Wagonlit Travel - Minneapolis
    [email protected]

    Hi, Scott.
    Here's the information I found on trapping keystrokes - mostly R3 =
    specific, but that's OK for you. I pulled the following posts off my =
    mailing list archive:
    From: <[email protected]>
    Date: Fri, 4 Apr 1997 15:57:32 +0800
    Subject: Trapping Certain Keystrokes
    Hi All,
    I have read the manuals, and the online-documentation, but can not seem =
    to find anything about trapping keystrokes other than the Function keys.
    Our application specifically requires us to trap certain keystrokes, =
    such as the navigation keys etc.=20
    Does anybody know which event is raised when a key is pressed?
    Any insight will be appreciated.
    Regards Martin
    From: DEVEAUX Manuel <[email protected]>
    Date: Fri, 4 Apr 1997 11:43:11 +0200
    Subject: RE: Trapping Certain Keystrokes
    Hi all,
    Actually, I don't think you can trap keystrokes on a UserWindow but on =
    some WidGets (like DataFields), you can set to TRUE the 'Validate on =
    KeyStroke' option in the properties dialog .
    Thus, when the WidGet has the focus and the user send a keystroke, you =
    can trap this event with the 'AfterValueChange' event. If someone knows
    =
    how to trap keystrokes on a UserWindow, I am also interested !
    Thanks.
    * Manuel -
    Manuel Deveaux
    Fort=E9 Developer
    Mutuelle Pr=E9viade
    Nancy, FRANCE
    E-Mail : [email protected]
    From: Jean-Paul De Baets <[email protected]>
    Date: Fri, 04 Apr 1997 14:11:58 +0200
    Subject: RE: Trapping Certain Keystrokes -Reply
    This is an enhancement request we also posted several months ago. I =
    think it is announced for Fort=E9 release 3. But I don't know if we =
    will be able to trap ANY keystroke.
    Jean-Paul=20
    J.P. De Baets
    CAP GEMINI Belgium
    [email protected]
    From: Kerry Bellerose <[email protected]>
    Date: Fri, 04 Apr 1997 13:28:14 +0100
    Subject: Re: Trapping Certain Keystrokes
    Hi Manuel and Martin,
    Unfortunately, for Forte V2.0, Manuel is correct. But Forte has added a
    =
    feature that allows you to trap any keystroke in Forte R3, which is =
    currently in beta.
    If you are a beta site, look in the Forte Release 3 Beta Features manual
    =
    page 169, the window class SetAsFunctionKey method.
    If you are not a beta site and want this functionality in R2,=20
    you would need to do some tricks with menus or data fields, as Manuel =
    indicated.
    Cheers,
    Kerry
    From: Lee Wei <[email protected]>
    Date: Mon, 7 Apr 97 09:06:23 PDT
    Subject: RE: Trapping Certain Keystrokes -Reply
    I think all of us want to know if we can indeed trap ANY keys.
    The answer is ALMOST, including escape, spacebar, enter, backspace, tab,
    =
    navigational (up,down,left,right,end,home), digits, alpha, numeric =
    keypads, insert, delete.
    But not keys such as left shift, right shift, left Alt, right Alt, left =
    Ctrl, and right Ctrl (Helpful for games...).
    Don't forget that we are talking about release 3.
    Lee Wei
    Hope this helps,
    Dariusz Rakowicz
    [email protected]
    From: owner-forte-users
    Sent: Friday, July 25, 1997 10:46 AM
    To: 'Forte Users Group'
    Subject: Keypress Events
    Hi, everybody, it is my first question to you all.
    Does anybody have any function that would capture keypress events, or
    any information that would be helpful in capturing them? For example,
    when a user presses the <down arrow> or F1 key. I am currently using
    the AfterValueChange event to capture keys that display.
    Thanks,
    Scott Watters
    Systems Analyst
    Carlson Wagonlit Travel - Minneapolis
    [email protected]

  • Can I create a keypress that relates to a counter?

    Hello, I am relatively new to flash and my lack of knowledge in actionscript is slowing me down. Help would be greatly appreciated
    I am making a game that utilizes a keypress to play a movie clip. It runs perfectly but I am trying to add to the script. After twenty key presses play a different movie.
    In case that doesn't make sense this is a little more in depth description, The game is a boxing game and when Key "0" is pressed a movie clip plays(showing the boxer punching) that part is fine. I am trying to have it to where after Key "0" is pressed 20 times, it will que a movie clip to kick in(the boxer that is being punched will fall down). I hope this makes sense.

    Hmm that definitly seems to be on the right track. I didn't see you attached a file at first. It is currently queued and I cannot download it. I am not sure if the file has expired or what. I'm new to the forum so maybe there is some way I go about downloading the file I dont know about so if that is the case please let me know
    If I could have opened the file maybe it would have made more sense but at this point I have a few questions.
    Does it matter where I put this script? I am using it on the main scene on frame 1 right now(is it suppose to be on the movieclip?)
    I adjusted the code to fit my needs by renaming the MC and adjusting the count, but it wont play the mc or display the Game over in the output menu.
    stop();
    var counter:Number = 0;
    var keyListener:Object = new Object();
    keyListener.onKeyDown = function() {
    var listen:Number = Key.getCode();
    if (listen == 96) {
    counter++;
    if (counter<=5) {
    blueko.play();
    } else {
    trace("GAME OVER");
    Key.addListener(keyListener);
    I think the stop doesn't make a difference it doesn't work with or without it(but I do need the stop to hold the current frame) Thank you so much for your help and sorry for my confusion

  • Capture system-wide keypresses in c/c++, what library to use?

    I want to be able to capture system-wide keypresses with a JAVA application in OSX. As this is not possible using pure java, I need to write a C/C++ app that does the listening, and combine that with my java app using JNI.
    But that is not my problem
    I was looking at this great tutorial:
    http://ubuntuforums.org/showthread.php?t=864566
    It does what I want, but for linux, and uses the X11 library's for the actual keypressdetection.
    As I don't know much about C/C++ for OSX specificly, my question is, what would be a good library for replacing X11 with (preferably something that everyone already has, like X11 in linux). I know I could use SDL or something for this, but isn't there anything a little closer to the system that everybody has by default?
    Thanks
    Reinout

    It would be best if you post this question on the Real Time forums since you are working with RT.
    Applications Engineer
    National Instruments

  • 2 part question - loading and key detection...

    Hi,
    I have an issue with a function. I have been developing my first AS3 application and everything was running smoothly until I added a second frame. I had this code on frame 1, which was working perfectly:
    function keyDetection() {
    stage.addEventListener(KeyboardEvent.KEY_DOWN, showRevisionWindow);
    function showRevisionWindow(keyEvent:KeyboardEvent) {
    var modifier:String="";
      var keyPressed:String="";
      keyPressed=keyEvent.keyCode.toString();  
    if(keyEvent.ctrlKey && keyEvent.keyCode == 192){
      if (revisionAuthorWindow.visible == false){
         revisionAuthorWindow.visible = true;
       revisionAuthorWindow.x = 256;
       revisionAuthorWindow.y = 192;
        }else{
         revisionAuthorWindow.x = -300;
           revisionAuthorWindow.y = -300;
           revisionAuthorWindow.visible = false;
    keyDetection();
    I moved the code to frame 2, added a loader function to frame 1, and now when I enter frame 2, I recieve this message:
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at SIMmersion_frontEnd_prototype_menu02_loadingTest_fla::MainTimeline/keyDetection()
    at SIMmersion_frontEnd_prototype_menu02_loadingTest_fla::MainTimeline/SIMmersion_frontEnd_pr ototype_menu02_loadingTest_fla::frame2()
    However, if I move this code back to frame 1, or comment out my loader function on frame 1 and go directly to frame 2, I will not receive the error.
    Here is the loader code I am currently using on frame 1, while the code above is currently on frame 2:
    stop();
    var loader : Loader = new Loader(); 
        var request : URLRequest = new URLRequest("myFile.swf"); 
        loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, updateProgress);
        loader.load(request);
    function updateProgress(event : ProgressEvent) : void
        var pI  = event.bytesLoaded/event.bytesTotal*100;
    trace ("pI = " + pI + "%");
    preLoader.pLoader.width = pI*5 ;
    var pI_int:int  = event.bytesLoaded/event.bytesTotal*100;
    preLoader.pIInt.text = "Loaded: " + pI_int + "%";
    if (pI_int==100){
      preLoader.visible = false;
      gotoAndStop(2);
    }else{
      preLoader.visible = true;
      gotoAndStop(1);
    If anyone could shed some light on why this happening, I would be very appreciative.
    Also, how do you use a URLRequest to reference 'itself'. Instead of using "myFile.swf", I want to reference the Flash file itself without having to indicate a name of the Flash file to load. is that possible?
        var request : URLRequest = new URLRequest("myFile.swf");
    something along the lines of:
        var request : URLRequest = new URLRequest(this);
    Thanks in advance; I know this is a long-winded question.
    Cheers,
    ~Chip

    No replies. Eric

  • Keypress in fullscreen?

    Hey
    I had an old version of air which loaded an swf that runs an as2 swf using as3
    The as2 swf included keypressing and regular as2 stuff.
    I just installed the new version of air and exported the AIR file again
    Keypresses don't seem to work
    any idea how to fix this?
    I thought about exporting to an older version of air but I have no idea how since the only option I have in CS5 is 2.0
    Also I was also wondering how do you disable escape un-fullscreening the AIR file using AS3
    Thank you

    I have found another question on how to disable esc button in fullscreen mode. Check this out.
    http://forums.adobe.com/message/2225685
    ~ K

  • Event Handling Question! Please help me!

    can a JTextField component generate a KeyEvent? Is it possible for the class used to create JTextField object implements KeyListener and fufilled a keyTyped or a keyPressed method created by a keyListener interface

    The best way to find answers to questions like these is to search the API. Near the top of this page is a drop down for APIs, or go here for 1.5 API http://java.sun.com/j2se/1.5.0/docs/api/
    In the API frame look for JTextField and see if it implements a method, or inherits a method that will add a KeyListener. If it does, then the answer to your question is yes.
    Depending on what you want to do, it might be better to use a custom Document instead of a KeyListener.

  • Blocking while waiting for a keypress

    In an APPLET, I need a way to do something like a blocking read for keyboard events. What I want is for the applet to do absolutely nothing while waiting for a keypress, and then resume doing its normal thing once a key has been pressed. Any suggestions?

    Yes, but I want it to do nothing while in its 'run()' function while in this loop. If I use KeyTyped, and store the key in some variable, then run has to busy-wait on that variable to change. I want a function that will suspend the execution until a key is pressed.
    I have three different cases in this applet where I need such an input, and as far as I can tell, the only way to do it with KeyTyped() is to put all of the program control logic in KeyTyped, and have a big ugly state machine within it. Basically, I want it to work like a read from a socket w/ an infinite timeout.
    This is for a game, and the flow of the program needs to be:
    PlayAgain = true
    While(PlayAgain){   
        Display Question 1 prompt
        Get KeyPress
        GameNotOver = true
        While( GameNotOver ) {
            Display Question 2 prompt
            Get KeyPress
            Get ComputerPlayer's Move
            Check for GameOver
        DisplayQuestion 3 prompt
        Get KeyPress
        Check for PlayAgain
    }Is there a different approach to this problem that I am missing?
    Edited by: jbm222 on Oct 9, 2007 4:40 AM

  • Simple KeyListener question

    I was wondering how to change the KeyPressed event to immediately start counting when a key is held down, as opposed to its second-long delay when the button is first pressed (for game purposes). For example, in this program I wrote, it will print out "up pressed" (when the up arrow is held) and then pause, before it will infinately print out "up pressed" until the key is released. I want to eliminate the pause.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Example extends JFrame implements KeyListener
    private JLabel square;
    private JPanel panel;
    private int squareX = 100, squareY = 50;
    public Example()
    super("Game");
    super.addKeyListener(this);
    super.setFocusable(true);
    //set your own image to make this work
    ImageIcon getSquare = new ImageIcon("C:\\Documents and Settings\\Phil\\My Documents\\My Pictures\\square.jpg");
    setDefaultLookAndFeelDecorated(true);
    FlowLayout layout = new FlowLayout(FlowLayout.LEFT);
    Container container = getContentPane();
    container.setLayout(layout);
    panel = new JPanel(null);
    panel.setPreferredSize(new Dimension(150, 105));
    panel.setBorder(BorderFactory.createTitledBorder("Move the square"));
    square = new JLabel(getSquare);
    square.setBounds(squareX, squareY, 10, 10);
    panel.add(square);
    container.add(panel);
    setSize(300, 150);
    setVisible(true);
    public void keyPressed(KeyEvent e)
    if (e.getKeyCode() == KeyEvent.VK_LEFT) {
    System.out.println("left pressed");
    moveLeft(); }
    if (e.getKeyCode() == KeyEvent.VK_UP) {
    System.out.println("up pressed");
    moveUp(); }
    if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
    System.out.println("right pressed");
    moveRight(); }
    if (e.getKeyCode() == KeyEvent.VK_DOWN) {
    System.out.println("down pressed");
    moveDown(); }
    public void keyReleased(KeyEvent e)
    if (e.getKeyCode() == KeyEvent.VK_LEFT)
    System.out.println("left released");
    if (e.getKeyCode() == KeyEvent.VK_UP)
    System.out.println("up released");
    if (e.getKeyCode() == KeyEvent.VK_RIGHT)
    System.out.println("right released");
    if (e.getKeyCode() == KeyEvent.VK_DOWN)
    System.out.println("down released");
    public void keyTyped(KeyEvent e){}
    private void moveLeft() {
    if (checkLeft())
    square.setLocation(squareX--, squareY); }
    private void moveUp() {
    if (checkUp())
    square.setLocation(squareX, squareY--); }
    private void moveRight() {
    if (checkRight())
    square.setLocation(squareX++, squareY); }
    private void moveDown() {
    if (checkDown())
    square.setLocation(squareX, squareY++); }
    private boolean checkLeft() {
    return (square.getBounds().x >= 0); }
    private boolean checkUp() {
    return (square.getBounds().y >= 0); }
    private boolean checkRight() {
    return (square.getBounds().width <= panel.getPreferredSize().width); }
    private boolean checkDown() {
    return (square.getBounds().x <= panel.getPreferredSize().height); }
    public static void main (String[] args)
    Example myExample = new Example();
    myExample.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    Swing related questions should be posted in the Swing forum.
    Use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags when posting code to the code is readable.
    [url http://java.sun.com/docs/books/tutorial/uiswing/misc/timer.html]How to Use Timers. You start a Timer when the key is pressed and stop the timer when the key is released. You can control the interval at which the Timer fires so its not dependent on the key repeat rate of the system.

  • Cloudscape question

    I want to use Cloudscape of J2EE1.3.1,so I set classpath=.;F:\j2sdkee1.3.1\lib\system\cloudscape.jar then I enter into directory of F:\j2sdkee1.3.1\lib\cloudscape, and start Cloudview like follow command:
    F:\j2sdkee1.3.1\lib\cloudscape>java -classpath cloudview.jar COM.cloudscape.tools.cview
    I found I can start Cloudview GUI,then I want to create a new database,so I choose File->New Database,then I name a new Name,and press OK button,but I got following errors:
    java.lang.ClassNotFoundException: COM.cloudscape.core.JDBCDriver
    at java.net.URLClassLoader$1.run(URLClassLoader.java:198)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:140)
    at c8e.eb.ab.setSelectedDatabase(Unknown Source)
    at c8e.dx.bs.connect(Unknown Source)
    at COM.cloudscape.ui.panel.NewDatabasePanel.newDatabase(Unknown Source)
    at COM.cloudscape.ui.panel.NewDatabasePanel.ok(Unknown Source)
    at COM.cloudscape.ui.panel.URLPanel.keyPressed(Unknown Source)
    at java.awt.Component.processKeyEvent(Component.java:5092)
    at javax.swing.JComponent.processKeyEvent(JComponent.java:2385)
    at java.awt.Component.processEvent(Component.java:4943)
    at java.awt.Container.processEvent(Container.java:1566)
    at java.awt.Component.dispatchEventImpl(Component.java:3639)
    at java.awt.Container.dispatchEventImpl(Container.java:1623)
    at java.awt.Component.dispatchEvent(Component.java:3480)
    at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1688)
    at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:593)
    at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:765)
    at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:698)
    at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:559)
    at java.awt.Component.dispatchEventImpl(Component.java:3509)
    at java.awt.Container.dispatchEventImpl(Container.java:1623)
    at java.awt.Window.dispatchEventImpl(Window.java:1590)
    at java.awt.Component.dispatchEvent(Component.java:3480)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)
    I know COM.cloudscape.core.JDBCDriver in the cloudscape.jar,and I have put it into classpath,why I still get above errors?
    How to run cloudview for creating a new database?
    Any idea will appreciated!
    Best regards,
    Edward

    This sounds like a configuration issue regarding cloudscape rather than a java question.
    I did a search on google which suggests the configuration is incorrect.
    http://www.google.com/search?q=java.lang.ClassNotFoundException+COM.cloudscape.core.JDBCDriver

  • Background picture to famous "ImageTest" applet - Is it supid Question?

    I would like to see what Pholser will say about this. :)
    Is this a dumest question or what ?
    Thanks in advance
    basisdba
    ------------------ Repeated----------------------------------------
    Hi to all,
    I am not sure if you could help on this one or not, but
    will be happy to see any responding on this :))
    This is the example that I have worked on:
    http://java.sun.com/applets/other/ImageTest/index.html
    I am trying to add a sold background to this, is this possible?
    Thanks in advance
    Regards,

    Hi Sam and all of you,
    Sorry for the delay I am very bussy daily as SAP adminstrator,
    if you know what I mean :)
    You both are right but with some minor corrections.
    You guys are all great after all...
    I attached ImageTest.java demo sample with this modification to the
    background only...I am trying to add extra code into it to allow
    NOT only BLUE/RED swap color but also some more colors, how can I do
    that? How can I add black, green, yellow and so on...(stupid nah :) )
    Why in the hell "Java Tech.." make the color defining so hard? :)
    Or it would be nice to have a 16 color table to choose from...
    Thanks again to all of you and I also rewarded your points based
    on the most recent "white house" logic! :)))))
    Regards,
    ------------------------------- Start of the code
    /*Modified only ImageTest.java Demo
    import java.lang.Math.*; // for Spray
    import java.awt.*; // note to self - imports CURSOR class
    import javax.swing.*; // for ui
    import java.awt.image.*; // for images
    import java.applet.*; // for sounds
    import java.awt.event.*; // for events
    import java.net.*; // URL
    import java.net.URL;
    import java.util.Vector;
    import java.awt.geom.*; // for Line2D
    import java.util.*; // used for the Vector in the flood fill method
    import java.util.StringTokenizer;
    public class ImageTest extends Applet {
    //Init
    public void init()
    // Image bg0 = applet.getImage(applet.getDocumentBase(),"images/bg0.gif");
    setLayout(new BorderLayout());
    add("Center", new ImagePanel(this));
    add("North", new ImageHelp());
    setVisible(true);
    public String getAppletInfo()
    return "A simple image manipulation tool.";
    class ImageHelp extends Panel {
    public ImageHelp() {
    setLayout(new GridLayout(6, 1)); //Grid 5 Row and 1 column
    //m
    // add(new Button("Move"));
    //m
    add(new Label("test",
    Label.CENTER));
    add(new Label("Image Move: < > ^ v, or with [L]eft/[R]ight/p/[D]own",
    Label.CENTER));
    add(new Label("Image Resize: +/-",
    Label.CENTER));
    add(new Label("Color Filter: T key",
    Label.CENTER));
    add(new Label("Change Alpha: (Shift)+/-",
    Label.CENTER));
    add(new Label("Rotate Image: (Shift)<> or (Shift)[L]eft/[R]ight",
    Label.CENTER));
    System.out.println("");
    class ImagePanel extends Panel
    Applet applet;
    public ImagePanel(Applet app) {
    applet = app;
    setLayout(new BorderLayout());
    Panel grid = new Panel();
    grid.setLayout(new GridLayout(1, 1)); //first(row), second (column)
    add("Center", grid);
         Image bg0 = applet.getImage(applet.getDocumentBase(),"images/bg0.gif");
         Image fg0 = applet.getImage(applet.getDocumentBase(),"images/ff001.gif");
         grid.add(new ImageCanvas(applet, fg0, bg0, 1.0));
         setBounds(0, 0, 20, 20);
    class ImageCanvas
    extends Canvas
    implements ImageObserver, KeyListener, MouseListener,
    MouseMotionListener, FocusListener {
    double hmult = 0;
    int xadd = 0;
    int yadd = 0;
    int xprev = 0;
    int yprev = 0;
    int imgw = -1;
    int imgh = -1;
    int xoff = 0;
    int yoff = 0;
    int scalew = -1;
    int scaleh = -1;
    boolean focus = false;
    boolean usefilter = false;
    static final int numalphas = 9;
    int alpha = numalphas - 1;
    static final int numrotations = 8;
    int rotation = 0;
    ImageFilter colorfilter;
    ImageFilter alphafilters[] = new ImageFilter[numalphas];
    RotateFilter rotfilters[] = new RotateFilter[numrotations];
    Image origimage;
    Image curimage, backimage;
    Applet applet;
         public BufferedImage currentImage, oldImage, tempImage, storedImage;
    Image bg0, bg1, bg2, bgImage;
         public URL URL_STRING;
    private int picNo = 0;
    public void init()
    try {
         bg0 = new ImageIcon(new URL(URL_STRING +"images/bg0.gif")).getImage();
         bg1 = new ImageIcon(new URL(URL_STRING +"images/bg1.gif")).getImage();
         catch (Exception exc)
         {//imgLoad = "Image failed to load";
    public ImageCanvas(Applet app, Image img,Image bg0,double mult) {
    applet = app;
    origimage = img;
    backimage = bg0;
    hmult = mult;
    pickImage();
    setBounds(0, 0, 100, 100);
    addMouseListener(this);
    addMouseMotionListener(this);
    addKeyListener(this);
    addFocusListener(this);
    //1.1 event handling
    public void focusGained(FocusEvent e) {
    focus = true;
    repaint();
    public void focusLost(FocusEvent e) {
    focus = false;
    repaint();
    public void keyPressed(KeyEvent e) {
    public void keyTyped(KeyEvent e) {
    char key = e.getKeyChar();
    switch(key)
    case 't':
    case 'T':
    usefilter = !usefilter;
    pickImage();
    repaint();
    e.consume();
    break;
    case '^':
    case '6':
    case 'u':
    case 'U':
    yadd -= 5;
    repaint();
    e.consume();
    break;
    case 'v':
    case 'V':
    case 'd':
    case 'D':
    yadd += 5;
    repaint();
    e.consume();
    break;
    case '>':
    case 'R':
    rotation--;
    if (rotation < 0) {
    rotation = numrotations - 1;
    pickImage();
    scalew = scaleh = -1;
    repaint();
    e.consume();
    break;
    case '.':
    case 'r':
    xadd += 5;
    repaint();
    e.consume();
    break;
    case '<':
    case 'L':
    rotation++;
    if (rotation >= numrotations) {
    rotation = 0;
    pickImage();
    scalew = scaleh = -1;
    repaint();
    e.consume();
    break;
    case ',':
    case 'l':
    xadd -= 5;
    repaint();
    e.consume();
    break;
    case '+':
    if (++alpha > numalphas - 1) {
    alpha = numalphas - 1;
    pickImage();
    repaint();
    e.consume();
    break;
    case '=':
    hmult *= 1.2;
    scalew = scaleh = -1;
    repaint();
    e.consume();
    break;
    case '-':
    hmult /= 1.2;
    scalew = scaleh = -1;
    repaint();
    e.consume();
    break;
    case '_':
    if (--alpha < 0) {
    alpha = 0;
    pickImage();
    repaint();
    e.consume();
    break;
    public void keyReleased(KeyEvent e) {
    public void mouseClicked(MouseEvent e) {
    public void mousePressed(MouseEvent e) {
    xprev = e.getX();
    yprev = e.getY();
    e.consume();
    public void mouseReleased(MouseEvent e) {
    e.consume();
    public void mouseEntered(MouseEvent e) {
    requestFocus();
    e.consume();
    public void mouseExited(MouseEvent e) {
    public void mouseDragged(MouseEvent e) {
    int x = e.getX();
    int y = e.getY();
    xadd += x - xprev;
    yadd += y - yprev;
    xprev = x;
    yprev = y;
    repaint();
    e.consume();
    public void mouseMoved(MouseEvent e) {
         //method selects a random image for the child to draw on or colour in
         public void backGroundImage(){
    public void paint(Graphics g) {
    g.drawImage(backimage, 0, 0, this);
    Rectangle r = getBounds();
    int hlines = r.height / 10;
    int vlines = r.width / 10;
    if (imgw < 0) {
    imgw = curimage.getWidth(this);
    imgh = curimage.getHeight(this);
    if (imgw < 0 || imgh < 0) {
    return;
    if (scalew < 0) {
    if (rotation == 0) {
    scalew = imgw;
    scaleh = imgh;
    } else {
    Rectangle rect = new Rectangle(0, 0, imgw, imgh);
    rotfilters[rotation].transformBBox(rect);
    xoff = rect.x;
    yoff = rect.y;
    scalew = rect.width;
    scaleh = rect.height;
    scalew = (int) (scalew * hmult);
    scaleh = (int) (scaleh * hmult);
    xoff = (imgw - scalew) / 2;
    yoff = (imgh - scaleh) / 2;
    if (imgw != scalew || imgh != scaleh) {
    g.drawImage(curimage, xadd + xoff, yadd + yoff,
    scalew, scaleh, this);
    } else {
    g.drawImage(curimage, xadd + xoff, yadd + yoff, this);
    static final long updateRate = 100;
    public synchronized boolean imageUpdate(Image img, Image bg0,int infoflags,
    int x, int y, int w, int h) {
    if (img != curimage) {
    return false;
    boolean ret = true;
    boolean dopaint = false;
    long updatetime = 0;
    if ((infoflags & WIDTH) != 0) {
    imgw = w;
    dopaint = true;
    if ((infoflags & HEIGHT) != 0) {
    imgh = h;
    dopaint = true;
    if ((infoflags & (FRAMEBITS | ALLBITS)) != 0) {
    dopaint = true;
    ret = false;
    } else if ((infoflags & SOMEBITS) != 0) {
    dopaint = true;
    updatetime = updateRate;
    if ((infoflags & ERROR) != 0) {
    ret = false;
    if (dopaint) {
    repaint(updatetime);
    return ret;
    public synchronized Image pickImage() {
    ImageProducer src = origimage.getSource();
    if (alpha != numalphas - 1) {
    ImageFilter imgf = alphafilters[alpha];
    if (imgf == null) {
    int alphaval = (alpha * 255) / (numalphas - 1);
    imgf = new AlphaFilter(alphaval);
    alphafilters[alpha] = imgf;
    src = new FilteredImageSource(src, imgf);
    if (rotation != 0) {
    RotateFilter imgf = rotfilters[rotation];
    if (imgf == null) {
    double angle = (2 * Math.PI * rotation) / numrotations;
    imgf = new RotateFilter(angle);
    rotfilters[rotation] = imgf;
    src = new FilteredImageSource(src, imgf);
    if (usefilter) {
    if (colorfilter == null) {
    colorfilter = new RedBlueSwapFilter();
    src = new FilteredImageSource(src, colorfilter);
    Image choice;
    if (src == origimage.getSource()) {
    choice = origimage;
    } else {
    choice = applet.createImage(src);
    if (curimage != choice) {
    if (curimage != null && curimage != origimage) {
    curimage.flush();
    curimage = choice;
    return choice;
    class RedBlueSwapFilter extends RGBImageFilter {
    public RedBlueSwapFilter() {
    canFilterIndexColorModel = true;
    public void setColorModel(ColorModel model) {
    if (model instanceof DirectColorModel) {
    DirectColorModel dcm = (DirectColorModel) model;
    int rm = dcm.getRedMask();
    int gm = dcm.getGreenMask();
    int bm = dcm.getBlueMask();
    int am = dcm.getAlphaMask();
    int bits = dcm.getPixelSize();
    dcm = new DirectColorModel(bits, bm, gm, rm, am);
    substituteColorModel(model, dcm);
    consumer.setColorModel(dcm);
    } else {
    super.setColorModel(model);
    public int filterRGB(int x, int y, int rgb)
    return ((rgb & 0xFF000000)) | ((rgb & 0xff00ff00)|((rgb & 0xff0000) >> 16)| ((rgb & 0xff) << 16)); //
    //return ((rgb & 0xff00ff00)|((rgb & 0xff0000) >> 16)| ((rgb & 0xff) << 16)); //
    class AlphaFilter extends RGBImageFilter {
    ColorModel origmodel;
    ColorModel newmodel;
    int alphaval;
    public AlphaFilter(int alpha) {
    alphaval = alpha;
    canFilterIndexColorModel = true;
    public int filterRGB(int x, int y, int rgb) {
    int alpha = (rgb >> 24) & 0xff;
    alpha = alpha * alphaval / 255;
    return ((rgb & 0x00ffffff) | (alpha << 24));
    //------------------------------- End of the code

  • Thread question

    How would i make a thread that just watched for pressedKey events. I'm new to programming and am trying to learn threads. So far from my understanding, threads do something until they're done, and don't sit there like event listeners.

    it seems to me as if everyone did understand your question perfectly well. there are event handlers that can do all you ask for: detect when a key is pressed, detect when it is released, detect when it is pressed (i.e. pressed and released).
    eg:
    private void jList1KeyPressed(java.awt.event.KeyEvent evt) {                                 
    String key = evt.getKeyText(evt.getKeyCode());
    //escape close
    if (key.equalsIgnoreCase("escape")){
    this.dispose();
    // home top of list
    if (key.equalsIgnoreCase("home")){
    jList1.setSelectedIndex(0);
    // enter
    if (key.equalsIgnoreCase("enter")){
    this.select();
    etc etc
    attach the listener to your component thus:
    jList1.addKeyListener(new java.awt.event.KeyAdapter() {
    public void keyPressed(java.awt.event.KeyEvent evt) {
    jList1KeyPressed(evt);
    });

  • Hibernate Question - Startup Key Sequences

    The macBook has a feature such that if it runs out of battery it saves an image of the RAM to HDD and goes into hibernation. We can see this in the System.log as [Aug 15 16:45:59 machine-name kernel[0]: hibernatewriteimage done(0)]
    Due to a separate fault my macBook is not then going into Hibernation, it runs until the power fails and of course switches off.
    So when I do the restart the macBook does not "see" the hibernate_image and simply reeboots.
    QUESTION; is there a keypress sequence [altctrlh, etc] to invoke the last/any hibernate disc image of the hdd?
    Thanks in advance for your thoughts.

    Try resetting your SMC.
    Resetting the System Management Controller >>
    -Bmer
    Mac Owners Support Group
    Join Us @ MacOSG.com
    iTunes: MacOSG Podcast
     An Apple User Group 

Maybe you are looking for