Results 1 to 9 of 9
Thread: keybindings
- 04-03-2012, 02:48 PM #1
Member
- Join Date
- Apr 2012
- Posts
- 68
- Rep Power
- 0
- 04-03-2012, 02:53 PM #2
Re: keybindings
Recommended reading: Key Bindings « Java Tips Weblog
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 04-03-2012, 02:57 PM #3
Re: keybindings
Insufficient context. Command line? AWT? Swing? other GUI toolkit?
The question as posted doesn't even state that this is a Java program.
Recommended reading: How to ask questions the smart way
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 04-03-2012, 03:01 PM #4
Member
- Join Date
- Apr 2012
- Posts
- 68
- Rep Power
- 0
Re: keybindings
swing but anyway is fine
my code is below
import java.applet.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.awt.geom.*;
import java.util.concurrent.*;
public class Pong extends JApplet
{
public static final int WIDTH = 350;
public static final int HEIGHT = 300;
private PaintSurface canvas;
public void init()
{
this.setSize(WIDTH, HEIGHT);
canvas = new PaintSurface();
this.add(canvas, BorderLayout.CENTER);
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(3);
executor.scheduleAtFixedRate(new AnimationThread(this),
0L, 20L, TimeUnit.MILLISECONDS);
}
}
class AnimationThread implements Runnable
{
JApplet c;
public AnimationThread(JApplet c)
{
this.c = c;
}
public void run()
{
c.repaint();
}
}
class PaintSurface extends JComponent
{
int x_pos = 0;
int y_pos = 0;
int x_speed = 1;
int y_speed = 1;
int d = 20;
int width = Pong.WIDTH;
int height = Pong.HEIGHT;
public void paint(Graphics g)
{Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(
RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
if (x_pos < 0 )
{
x_speed = -x_speed;
}
if (x_pos > width - d)
{
x_speed = -x_speed;
}
if (y_pos < 0 )
{
y_speed = -y_speed;
}
x_pos += x_speed;
y_pos +=y_speed;
Shape ball = new Ellipse2D.Float(
x_pos, y_pos, d, d);
g2.setColor(Color.CYAN);
g2.fill(ball);
int d;
d = 8; //I want d to be controlled by g and h
Shape bally = new Rectangle.Float(d,250, 50, 8);
g2.setColor(Color.CYAN);
g2.fill(bally);
}}
- 04-03-2012, 03:34 PM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
Re: keybindings
Oh look.
Still no [code] tags [/code].Please do not ask for code as refusal often offends.
- 04-03-2012, 03:55 PM #6
Member
- Join Date
- Apr 2012
- Posts
- 68
- Rep Power
- 0
Re: keybindings
plz help
- 04-03-2012, 04:07 PM #7
Re: keybindings
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 04-03-2012, 04:09 PM #8
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
Re: keybindings
plz uz cd tgs.
Please do not ask for code as refusal often offends.
- 04-03-2012, 04:41 PM #9
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
KeyBindings Empty Key?
By Unome in forum Java AppletsReplies: 1Last Post: 10-24-2008, 07:28 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks