Key triggeres animation

So I'm working on my first java based game to work on my basic gui skills. I'm want it so that when the up key is pushed a shot is fired (just a circle). I'm not sure how to approach it though, whether to use graphics2d to create a fillarc and make it visible when the button is pushed, or have it created when the up key is pushed. But the problem I find with the latter is that I would have to make an inner class in the paintcomponent and it needs to be in the default constructer. So i was wondering if anyone could help me with this problem?

Okay so I figured a way to do a key triggered animation. I used space instead of up and had it change a boolean shot to true(when pressed) and while shot is true, the x and y coordinates of the shot (beginning at the end of the gun) are either incremented or decremented and added to the x and y of the fillarc() method in order to animate the shot in a certain direction, but now when I press space the game freezes completely. I can't figure it out, can anyone tell me why this is happening?
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
public class Book_Game extends JFrame{
    Home_Base home = new Home_Base();
    public Book_Game(){
        add(home);
        home.setFocusable(true);
    public static void main(String[] args){
        Book_Game frame = new Book_Game();
        frame.setSize(600, 500);
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    class Home_Base extends JPanel{
        //Gun & Base -> values obtained through print out of getHeight() and getWidth() methods
       private int BaseH = (int)(464*.85);
       private int radius = (int)(464/8);
       private int GunY = 464;
       private int GunXcenter = (int)(584/2);
       private int GunX = GunXcenter - radius;
       private int GunYlength = GunY - 100;
       private int GunXlength = 584 + (int)(radius*1.6);
       private int angle = 0;
       //Random Object for a random integer
       Random r = new Random();
      //Enemy fire coordinates in random positions above Base's gun
       private int EnemyFireX = r.nextInt(584);
       private int EnemyFireY = r.nextInt(GunY - 150);
       private boolean shot = false;
       private int shotX = 0;
       private int shotY = 0;
       //Gun angle X & Y for shot direction
       private int GangleX = 0;
       private int GangleY = 0;
       public Home_Base(){
            javax.swing.Timer timer = new javax.swing.Timer(500, new TimerListener());
            timer.start();
            addKeyListener(new KeyAdapter(){
                    public void keyPressed(KeyEvent e){
                        switch(e.getKeyCode()){
                            case KeyEvent.VK_RIGHT : angle += 5; break;
                            case KeyEvent.VK_LEFT  : angle -= 5; break;
                            case KeyEvent.VK_SPACE : shot = true;
                        repaint(GunXcenter - 100, GunY - 100, 200, 200);
        protected void paintComponent(Graphics g){
            super.paintComponent(g); // clear the screen
            Graphics2D g2 = (Graphics2D)g;
            //Gun Base
            g2.fillArc(GunX, GunY - radius, radius * 2, radius * 2, 0, 180);
            //Buildings
            g2.fillRect(0, BaseH, radius/2, GunY - BaseH);
            //Fire
            int EnemyFire = (int)(Math.min(getWidth(), getHeight()) * 0.04);
            //Fill in the Enemies Fire
            if((EnemyFireY+(2*EnemyFire))<BaseH){
                EnemyFireY += 10;
            }else if((EnemyFireY+(2*EnemyFire))>=BaseH){
                EnemyFireX = r.nextInt(584);
                EnemyFireY = r.nextInt(GunY - 150);
            g2.fillArc(EnemyFireX, EnemyFireY, 2*EnemyFire, 2*EnemyFire, 0, 360);
            //shot
            //x & y locations of the tip of the gun
            int EndofGunXcenter = GunXcenter - (EnemyFire/2);
            int EndofGunYcenter = GunYlength - (EnemyFire/2);
            while(shot != false){
                GangleY -= angle;
                if(angle < 0){
                    GangleX -= angle;
                }else
                if(angle > 0){
                    GangleX += angle;
                g2.fillArc(EndofGunXcenter + GangleX , EndofGunYcenter + GangleY, EnemyFire, EnemyFire, 0, 360);
            //gun
            AffineTransform af = new AffineTransform();
            af.translate(GunXcenter, getSize().height );
            af.rotate(Math.toRadians(angle));
            g2.transform(af);
            g2.drawLine(0, 0, 0,  -100 );
            class TimerListener implements ActionListener{
                public void actionPerformed(ActionEvent e){
                    repaint();
}

Similar Messages

  • Key triggers in forms

    How at add key triggers in Forms.For example : When users click function key "F2" then it should save the record.
    Thanks
    Saritha

    hi,
    there are two ways to do it,
    one is to re-map function keys using oracle terminal,
    other is to use triggers that are already associated to the operations that
    are performed by pressing these keys e.g.
    F1 ---> Help
    F9 ---> List of values
    F4 ---> Duplicate record
    you can use these triggers to redefine the function/operation of keys
    by their associated triggers, like if you want 'F4' to save the data,
    you will write 'COMMIT_FORM' or any code you want, on trigger
    KEY-DUPLICATE-RECORD which is fired while 'F4' key is pressed,
    since this trigger is associated with 'Duplicate record' event.
    once you write the code on this trigger at form level, it will perform
    the required operation on activation.
    regards,
    aamir.

  • Function keys Triggers

    Guyz,
    Kindly correct me the function keys associated with triggers in oracle forms 6i.
    F1= (Display properties of an Item ID)
    F2= ?
    F3= ? (KEY_CLRFRM OR KEY_CRLREC) ?
    F4= ?
    F5= (KEY-MENU)
    F6= ?
    F7= (KEY-ENTQRY)
    F8= (KEY-EXEQRY)
    F9= ?
    F0= (KEY COMMIT)Regards
    Moazam

    I think this is help you..
    Ctrl+E          Edit
    Ctrl+F1          Show Keys
    Ctrl+H          Help
    Ctrl+L          Down
    Ctrl+P          Up
    Ctrl+PageDown          Next Block
    Ctrl+PageUp          Previous Block
    Ctrl+Q          Exit
    Down          Down
    F10          Commit
    F2          List Tab Pages
    F3          Duplicate Item
    F4          Duplicate Record
    F5          Block Menu
    F6          Insert Record
    F7          Enter Query
    F8          Execute Query
    F9          List of Values
    PageDown          Scroll Down
    PageUp          Scroll Up
    Shift+Ctrl+PageD          Next Set of Records
    Shift+Down          Next Record
    Shift+F1          Display Error
    Shift+F2          Count Query
    Shift+F3          Next Primary Key
    Shift+F4          Clear Record
    Shift+F5          Clear Block
    Shift+F6          Delete Record
    Shift+F7          Clear Form
    Shift+F8          Print
    Shift+Tab          Previous Field
    Shift+Up          Previous Record
    Tab          Next Field
    Up          Up

  • Layering animations when triggered

    I have a series of animations in my edge project where each one when triggered positions over the other animations. Im having an issue where the layering system is not allowing me dictate when an animation is triggered it always sits on the very top layer so it doesn't get obstructed by any other content in the project. Is it possible to add some code that works on the basis of z-index, so when ever an triggered animation is running it always is on the top layer so it doesn't get covered by the other animations when overlapping. Or is it a case of creating completely separate animation files? - please help.

    Welcome to the forums!
    You can set animations to start after another animation with a delay, so yes, can produce the effects you want. In the Build Inspector, such timings are accessed via the vaguely-named "More Options" button, which reveals the Build Order pane where such timings are specified.

  • Best practice for animating a presentation

    I have been asked to animate a 2 minute presentation with no
    user interaction where audio clips must synch up with events on
    screen with various image tweens and fading. I have done them in
    the past using keyframe animations, but I get into performance
    issues that I would like to resolve. I am aware that animating
    through actionscript along with a preloader will more than likely
    allevate my problems, but I am not sure the best way to go about
    doing this. I know how to animate symbols such as "this._x =
    this._x+5;" but I am not sure how to keep triggering other
    animations once one animation gets to a certain point, would I just
    use alot of IF statements. Or is it better and easier to use the
    tween class? along with animationVar.onMotionFinished = function()
    { play next animation}; and if so what is a good way to keep the
    audio in synch. Or is there a way to get the key frame animations
    to perform better on things like alpha fades on bitmap images.
    I realize this is a question that would have a lengthy answer
    if fully explained. Are there any good resources I could look at?

    Nothing better than packaging them and using Dropbox to share. I caution you
    on one thing as far as packaging:
    http://indesignsecrets.com/file-packaging-feature-can-cause-problems-in-dps-
    workflows.php

  • Key binding in Forms 6i

    Hi All,
    I have a problem with key binding. I have tried different permutations of changing the key binding using the Oracle Terminal on FMRUSW.RES FILE to no avail. I have edited the keys of windows-sqlforms normal and used USER DEFINED KEY 2, etc but when I try to generate the file it gives the error 'failed to find action for user defined key 2 for an entry in "normal" in sqlforms. I have even gone to the extent of merely changing the bindings of the old entries to see whether it would work. It would give no error when generating but in the application the triggers did not work. I have even changed the Product Actions by inserting the code in the actions column but without any success.
    What I really want is for example to execute the key triggers in the application e.g. F2 would fire the trigger 'execute query', F3 to fire trigger 'copy', etc.
    I will appreciate any help I can get. Please note that I have gone through the numerous materials on the subject but they have not solved the problem.
    Thanks.
    Tunde

    Hi,
    I coded the key mapping as follows:
    I created a menu item. To call the code, you have to give a name for an accelerator key in the property palette for the menu item e.g. "start_menu".
    Let's say, to invoke the menu item, you have to press "Ctrl+E". So you have to set the key mapping in your *.res-file like this:
    69 : 2 : "Ctrl+E"           : 85 : "start_menu"
    Explaination:
    69: Code for "Ctrl+E"
    2: Java Modifier Number for "Control"
    85: Forms function number ("User Defined Key 3", look at the file I send to you !)
    I don't know, if that's the solution, because you wanted to map F1, F2...., but it shouldn't be a problem to switch my solution to F-keys. But perhaps, some of the Forms functions (e.g. F7 for Enter-Query-Mode) won't work then.
    Hope this helps.
    Regards,
    Markus

  • JDeveloper 10g Creating a new record with trigger sequence primary key

    Hi there, I'm sorry to post this incredibly simple question and I'm sure that someone must have answered this on this forum before but the searching of this site is incredible slow and painful and after 30 mins I can't find help.
    I am using a struts Data Action to create a new record in the database and then being forwarded to an edit page where I can enter the new details. Then when the details are entered I am clicking an update button and returning to a browse screen where I can either commit the change to the database or rollback. Sounds pretty simple but I am really struggling with trying to get the trigger of the number sequence to work properly.
    Ideally I would like to click the create new record button and then the primary key/triggered sequence number is already displayed on the empty form...
    ... but if this is too tricky or not possible then I would like the user to either not enter any value in the key field (which currently causes error - JBO-27014: Attribute PoNo in PO_SYS_MODULE.PoSystemView1 is required) OR the user enters a number and the trigger overwrites this number with the next in the sequence.
    I can enter a new record if I look in the manager console and see the next number in the sequence and then create the record using this number and then click commit twice, as the first time I get the error: JBO-25019: Entity row of key oracle.jbo.Key[154 ] not found in PoSystem. Or if I enter a value 5 times greater than the next in the sequence I have to click the commit button 5 extra times to get the sequence to match the input.
    I hope that this lengthy explanation fills you in on my problem, there must be a simple solution to this and I will be VERY grateful to anyone who can help me.
    Many thanks
    Ben Sayers (clearly a newbie)

    Hi,
    ADF Business Components handles this for you - unless yo prefer doing this manually. In the Entity Object, set the PK attribute's type to DBSequence. Then create a database sequence and use a database trigger to add the sequence value on insert
    Frank

  • Use of KEY-OTHERS trigger

    Hi,
    I have a form that has numerous triggers defined at the form level. The form has a block that appears in a dialog window. The block should only have a small subset of triggers that are defined at the form level. I went ahead and created the key triggers necessary at the block level; I also defined a key-others trigger defined as null on the block to disable all other key triggers defined at the form level???. However it's not working, key triggers at the form level are still firing. Is the key-others trigger suppose to suppress triggers at a lower level or do I have to specifically deactivate all the key triggers at the block level?
    Thanks for you help in advance

    Key-Others at the block level will only override a form-level Key-Others. It will not override any other form-level triggers.
    You must either override all the form-level triggers at the block level, or add code to the beginning of each form-level trigger such as:
    If :System.trigger_block = 'MY_SPECIAL_BLOCK' then
      Return;  -- exit if in the special block
    End if;

  • Function keys are not working?

    hi all
    i am using dv-10G(10-1...) can anyone guide me how we can use our desire keys in forms.
    example
    For commit form my function keys should be look like this.
    commit form-----F10
    Execute Query...........F11
    etc
    plz help me
    sarah

    Hi sarah,
    One way is to create the key triggers for your function keys.
    Another way is there is a keyboard mapping file usually found in <dev suite home>/forms folder.
    File name is fmrweb.res. It defines the mapping of various keys to the function it should perform.
    If you've migrated from 6i, best thing to do is take the backup of fmrweb.res file and save the fmrpcweb.res file as fmrweb.res file.
    fmrpcweb.res file is provided for the compatibility with 6i keyboard mappings.
    e.g a sample line in fmrweb.res is
    83   : 2 : "Ctrl+S"         : 36 : "Commit"Means, in 10g, ctlr_S is the same as commit (which is done through F10 in 6i).
    So, either you can copy the F10 entry from fmrpcweb.res to fmrweb.res or copy fmrpcweb.res as fmrweb.res, i suggested above.
    in fmrpcweb.res is:
    121  : 0 : "F10"            : 36 : "Commit"Hope you understand.
    Hope it helps.
    Please mark answer as helpful / correct, if it helps you
    Navnit

  • Login Screen, custom shortcut keys possible?

    I'd like to create a keyboard shortcut to "lock the screen" (login screen). I read through the helpfile and it's not clear this is possible.
    I'd like, for example to do Apple-L to get that to work.
    Is this possible?

    QuickEdit, thanks for the help! Sorry not to reply sooner -- was away for a bit and have only had a chance to play around.
    Based on your recommendation, I did some research on QuicKeys and also found another, similar program iKey (http://www.scriptsoftware.com/ikey/). I downloaded trial versions of both, and found iKey easier to manage. Plus it was cheaper ($30 versus 79.95). I was able to assign shortcut keys using modifiers (alt, cmd, ctl) and the keys that Apple won't let you assign via Keyboard preferences (home, end, forward delete, arrows). I even set up some customized menus or more complex actions (automate) with shortcut key triggers (e.g., creating a footer and inserting a file name and path in a word document with two keystrokes; opening itunes finding a radio station and begin streaming it live with two keystrokes). I'm sure that some of this can be done with automater or applescripts, but since I'm new to apple, I'm happy to start with this.
    iKey does have one annoying feature that I discovered -- you can set keyboard shortcuts to operate in different contexts (e.g., Finder front, Safari not running) but you cannot use the same keyboard shortcut to launch different actions in mutually exclusive contexts.
    By the way, I called Apple support about this question before I started playing with either of the programs. The person I talked to made a special call over to the OS X division and confirmed that forward delete cannot be assigned in user-defined keyboard shortcuts -- "yet." No one was clear if this capability might be developed in the future.
    Thanks again for your help!

  • Animating PNG causes them to lose transparency.

    Basically in AS 3.0 I have PNG's loaded in loader classes as
    children of Sprites on the stage.
    The PNG's look fine, but then I have certain actions
    triggering animations of the sprites (sliding from point a to point
    b using some math, repeated in a Timer).
    Everythign is fine initially even through the animation
    process, but when the Sprite reaches its destination, all
    transparency for the PNG is lost. The edges become very sharp, and
    in the case of having a 50% transparency over the whole image, the
    image becomes 100% alpha upon stopping its animation. Is there a
    known cause, workaround or fix for this?
    Thank you very much.
    Jack

    As a check, I tried replacing all Sprites on the stage with
    MovieClips, and the same behavior happened, so that rules out
    sprites as being the issue.
    Any help would be greatly appreciated.

  • Bottom regions of piano keys play after a short delay when pressed

    After I updated to iOS 7, when I play the piano, the lower most region of the piano keys don't play immediately. There is a short delay before the note is played. Moreover, the  'key press' animation is not visible although the note plays after some delay. This is a little annoying because while playing, the fingers can be at any region and the bottom part of the keys do not play properly. Also, GarageBand has become a little unresponsive, especially the pianos. This did not happen before the iOS update.

    I think I have the same issues there.  tried all the options from 3 finger up to controllcenter but no change the problem.
    https://discussions.apple.com/message/23666791#23666791
    hope that apple will recoqnize our problem and fix it.
    have the same problem with Logic Pro remote app.
    greetz

  • Replacing natural keys with surrogate keys

    Hi,
    We have database that is runnig with some old applications since many years. In the database, all the primary key are natural keys (composed with many columns). The applications are developped with mod pl/sql and oracle forms6i / designer6i.
    We are planning to develop a new system (replacing all the old applications), the database tables will ramain the same but we are thinking about replacing the natural keys with surrogate keys. Since we are planning to develop and migrate into the new system gradually (oracle forms applications will not be redeveloped first), my question is:
    - will the oracle forms applications still works?
    - what is the risk and precautions to take ?
    - is the decision to convert natural keys into surrogate a good one?
    All your comments and propositions are welcome.
    Thanks.

    Surrogate keys in general is a good idea. Many generators cannot handle multiple column PK's very well, or not at all. I believe, for instance, that Apex can handle 2 columns only.
    But, doing this on an existing datamodel can be a lot of work. You have to change your tables, of course, but also the foreign keys, triggers, constraints etc. A PK is protected from an update, but I guess you also want your old, natural PK, to be protected as well.
    Forms generates master-detail synchronization based on FK relations. If these change, you may have to change your Forms too. As long as you don't do anything in your existing form, my guess is that it will still work. The forms will maintain the FK relation between old table definitions. This works independently of the actual FK relation in the database. You can create triggers on the tables to actually populate the new PK and FK.
    For something like this: give it a try in a small test setup first. Than calculate the risk and impact.

  • PRA ACCOUNT KEY

    Dear all,
    Can anybody tell me when PRA account key triggered by the system?I mean in which scenarios PRA has been trigger?
    Thanks & Regards
    Dipayan Bose

    Hi,
    Check link for triggering of  key PRA
    PRD - PRA transaction Key
    Regards,
    Biju K

  • Access Keys

    Forms allow access keys for menu items and buttons using the alt key in a two tier client server environment.
    Can anyone tell me how Oracle handles this when forms are running on the web. The alt key combination will result in the menus for IE or Netscape to be activated.
    Also, how does oracle handle key-triggers that have been mapped to certain keys.

    Hi
    thanks for that info. In which case apart from the assiduous
    use of the alt
    tag what is the best way to ensure a site is appropriate for
    persons with
    dissabilities? Surely sight problems are covered by the
    Magnifying glass
    and tactile by the use of specialy designed input devices?
    thanks
    Ian
    "Thierry" <[email protected]> wrote in message
    news:gb77rb$orb$[email protected]..
    > "Ian Edwards"
    <[email protected]> wrote in message
    > news:gb66v2$jau$[email protected]..
    >> Hi
    >>
    >> can I have some views on Access keys as a client has
    asked if they should
    >> be included on a site rebuild?
    >>
    >> He has seen it used at
    http://www.glulamtimbersystems.co.uk/s/access.htm
    >> ( where they don't seem to work)
    >>
    >> Can this be implemeted in DW CS3 or 4 or is it a
    separate piece of code
    >
    > I think you should not bother as accesskeys create more
    problems than they
    > solve.
    > If you really need to implement then on a site, you may
    want to go this
    > route:
    >
    http://tjkdesign.com/articles/user_defined_accesskeys.asp
    >
    >
    > --
    > Thierry
    >
    http://www.TJKDesign.com/go/?0
    | Articles and Tutorials
    >
    >
    >
    http://divahtml.com/products/scripts_dreamweaver_extensions.php
    |
    > Extensions that keep your markup clean
    >
    http://www.fourlevel.com/ |
    CSS Menus, Gallery, Tab Panels, etc
    > --
    >

Maybe you are looking for