I have written the following which is a series of 4 files: Alien.class,
Mutant.class, RovingAlien.class, each inheriting from the last. I am unsure
how to go about the next bit - do I post the code for each of the 4 files or
attach them and the class files as part of the message, so i will post the
code - Again your help is so appreciated:
---------------------------------------------------
Alien.java
import java.awt.*;
public class Alien
{ private int x,y;
Alien()
{ x=0;
y=0;
}
Alien (int xstart, int ystart)
{ x=xstart;
y=ystart;
}
void draw (Graphics g)
{ g.setColor (Color.blue);
g.fillOval (x, y, 10, 10);
g.fillOval (x+30, y, 10, 10);
g.fillOval (x, y+30, 40, 20);
g.drawLine (x+5, y+10, x+5, y+35);
g.drawLine (x+35, y+10, x+35, y+35);
}
void draw (Graphics g, Color colour)
{ g.setColor (colour);
draw (g);
}
void x(int x)
{ this.x = x;
}
void y(int y)
{ this.y = y;
}
int x()
{ return (x) ;
}
int y()
{ return (y) ;
}
}
---------------------------------------------------------
Mutant.java
import java.awt.*;
import java.applet.*;
import Alien;
public class Mutant extends Alien
{
Color foreGround = Color.red;
Mutant ()
{
super ();
}
Mutant (int x, int y)
{
super (x, y);
}
Mutant (int x, int y, Color colour)
{
super (x, y);
foreGround = colour;
}
void drawMutant (Graphics g)
{
draw(g);
eye (g);
}
void drawMutant (Graphics g, Color colour)
{
draw (g, colour);
eye (g) ;
}
void drawDelMutant (Graphics g, Color colour)
{
draw (g, colour);
}
private void eye (Graphics g)
{
g.setColor (Color.white);
g.fillOval (x()+5, y()+30, 30, 20);
g.setColor (Color.black);
g.fillOval (x()+15, y()+35, 10, 10);
}
}
---------------------------------------------------------
Rover.java
import java.awt.*;
import java.applet.*;
import Mutant;
public class Rover extends Mutant
{
Color foreGround = Color.blue;
Color backGround = Color.black;
private int newx = x(), newy = y();
int incx = 3, incy = 3;
int x = x(), y = y();
private boolean deleteMe = false;
Rover (Color backGround)
{
super ();
this.foreGround = foreGround;
this.backGround = backGround;
}
Rover(int x, int y, Color foreGround, Color backGround)
{
super (x,y) ;
this.foreGround = foreGround;
this.backGround = backGround;
}
void up()
{
newy = newy - incy;
}
void down()
{
newy = newy + incy;
}
void left()
{
newx = newx - incx;
}
void right()
{
newx = newx + incx;
}
void newposition(int x, int y)
{
newx = x;
newy = y;
}
void drawMove(Graphics g)
{
draw(g, backGround);
if (deleteMe == false)
{
this.x(newx);
this.y(newy);
drawMutant (g, foreGround) ;
}
if (deleteMe == true)
{
drawDelMutant (g, backGround) ;
}
}
void delete()
{
deleteMe = true;
}
void undelete()
{
deleteMe = false;
}
}
---------------------------------------------------------
Space.java
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import Rover;
public class Space extends Applet
{ Color backGround = Color.black;
Color foreGround = Color.red;
Color eyecolour = Color.white;
Rover rovingl = new Rover(backGround);
Rover roving2 = new Rover(300, 300, foreGround, backGround);
int x,y;
public void init()
{ setSize (500, 500);
setBackground (backGround);
setForeground (foreGround);
addKeyListener (new RovingKeyActions ());
addMouseListener (new RovingMouseActions ());
}
public class RovingKeyActions implements KeyListener
{ public void keyPressed (KeyEvent e)
{ int key = e.getKeyCode();
if (key == KeyEvent.VK_RIGHT)
{ rovingl.right();
repaint();
}
else if (key == KeyEvent.VK_UP)
{ rovingl.up();
repaint();
}
else if (key == KeyEvent.VK_LEFT)
{ rovingl.left();
repaint();
}
else if (key == KeyEvent.VK_DOWN)
{ rovingl.down();
repaint();
}
}
public void keyReleased (KeyEvent e)
{ }
public void keyTyped (KeyEvent e)
{ }
}
public class RovingMouseActions implements MouseListener
{ public void mouseClicked (MouseEvent evt)
{ int getX, getY;
roving2.newposition(x,y);
{ x = evt.getX();
y = evt.getY();
}
roving2.delete();
int clickCount = evt.getClickCount();
if ( clickCount == 1 )
{ roving2.undelete();
roving2.newposition(x,y);
{ x = evt.getX();
y = evt.getY();
repaint();
}
}
if ( clickCount == 2 )
{ roving2.delete();
repaint();
}
}
public void mouseEntered (MouseEvent evt)
{ }
public void mouseExited (MouseEvent evt)
{ }
public void mousePressed (MouseEvent evt)
{ }
public void mouseReleased (MouseEvent evt)
{ }
}
public void paint (Graphics g)
{ rovingl.drawMove(g);
roving2.drawMove(g);
}
}
Many thanks
Wes O'Brien
1. That's three files, not four. But in any case you have made no effort to
isolate a problem, or post the minimum code required to demonstrate a
specific problem.
2. Programming newsgroups do not work this way. Don't post your entire
program and ask for generic "help." Programming by newsgroup makes you a
virtual programmer, not a real one.
You are able to describe symptoms in your program whose cause you cannot
possibly imagine. You can type computer code, and you can compile computer
code, and you can certainly list computer code, but you are not making an
effort to *understand* computer code.
If you post a specific, short code example that shows a problem, and if you
say what the problem is and how it differs from your intention (neither is
true here), you are asking someone to help you write your program.
If instead you post the entire program without bothering to say clearly what
the problem is, you are asking someone else to write your program for you.
That is "virtual programming" -- you are not really involved. Speaking
hypothetically, all you would have to do is post the results provided by the
last person who tried to help, and ask for help again. A robot could do
that.
Here is what you should do to show that you are personally involved in your
own program:
1. Clearly identify problems. Find cases in which you wanted x but got y.
2. Whittle the code down to a maximum of twenty lines that shows the result
y for your desired x.
3. Post the code, explaining that you got y instead of x. Be sure to say
what x and y are and how they differ.
And why is this better? Because if you actually examined your code in
sufficient detail to isolate a problem in 20 or fewer lines, you would also
discover what the problem is.
To paraphrase Truman Capote, typing is not programming. A programmer is not
someone who types source code. A programmer is someone who understands
source code.
--
Paul Lutus
www.arachnoid.com
--
/-- Joona Palaste (pal...@cc.helsinki.fi) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"We sorcerers don't like to eat our words, so to say."
- Sparrowhawk