Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (542)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (604)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Java Game APIs & Engines / Java 2D / Need Help with This Animation Code on: 2004-10-15 16:44:34
Hey Guys,

When I run the following code.  The animation does not seem to work right.  When the button is clicked the circle moves from point a to b, but does not show the movement in between. If I remove the action listener code and button and run the for loop in the go procedure the animation is smooth.

Any suggestions on how to fix this within the context of the code I've written?  I'm sure there are better ways to do this.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class SimpleAnimation implements ActionListener {

      int x=70;
      int y=70;
      MyDrawPanel drawPanel;
     
     

      public static void main (String [] args) {
           
            SimpleAnimation gui = new SimpleAnimation();
            gui.go ();
      }

      public void go () {
           
            JFrame frame = new JFrame("Tom's Animation Program");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            JButton button = new JButton("Click To Start The Show !");
            button.addActionListener (this);
            drawPanel = new MyDrawPanel();
            frame.getContentPane().add(BorderLayout.SOUTH,button);
            frame.getContentPane().add(drawPanel);
            frame.setSize(300,300);
            frame.setVisible(true);
      }
           
     
     

      public void actionPerformed (ActionEvent event){
     
            for (int i=0; i<130; i++) {
           
                  x++;
                  y++;
                  drawPanel.repaint ();
                  try{Thread.sleep(50);
                  }catch (Exception ex){}
            }
     
      }
      class MyDrawPanel extends JPanel{

            public void paintComponent (Graphics g){

                  g.setColor(Color.white);
                  g.fillRect(0,0,this.getWidth(),this.getHeight());

                  g.setColor(Color.green);
                  g.fillOval (x,y,40,40);
            }
      }
}
2  Game Development / Newbie & Debugging Questions / Re: Question about oop on: 2004-09-22 02:18:39
Don't forget about abstraction.  Break down your classes into subclasses.

Start with a monster class that contains variables and methods common to all monsters.  Then create more specific monster subclasses that can extend the functionalility of the more abstract monster class.

So you start with a monster class, then create specific classes like Rock Monster, Demon Monster, Vampire monster and so on.

Later on if you decide to add another monster to the game.  All you need to do is create a new class for that monster extending the original monster class and not destroying any functionality

This process can be used with all the classes you create.  

TMP72
Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Elsealabs (10 views)
2014-12-28 10:39:27

CopyableCougar4 (17 views)
2014-12-28 02:10:29

BurntPizza (21 views)
2014-12-27 22:38:51

Mr.CodeIt (14 views)
2014-12-27 04:03:04

TheDudeFromCI (19 views)
2014-12-27 02:14:49

Mr.CodeIt (26 views)
2014-12-23 03:34:11

rwatson462 (57 views)
2014-12-15 09:26:44

Mr.CodeIt (47 views)
2014-12-14 19:50:38

BurntPizza (94 views)
2014-12-09 22:41:13

BurntPizza (115 views)
2014-12-08 04:46:31
How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!