Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

A couple of big questions

0 views
Skip to first unread message

Wes O'Brien

unread,
Nov 4, 2001, 12:30:01 PM11/4/01
to
Im afraid it's alien boy back again - I have completed, largely due to your
help, my files. However I have two instances of an 'Alien' (just a series of
ovals and lines), which consists of some graphics in the first file
Alien.java, and an 'eye' which overlays the initial graphics from the second
file Mutant.java. The first must move with keypresses of up down left and
right, and the other must move to the position of a mouse click. Upon 2
mouse clicks in the same position it must disappear, reappearing on the next
click. When I make the first instance move there remains a sort of 'image'
which follows the original about 3 pixels behind it, and when the second
moves it also leaves the graphic from the first file in the last position,
and when it should disappear an instance does, but there remains an instance
which seems to follow it. It might make it clearer if I show you the class
file, its at www.f21.co.uk/java/Space.class . Not sure if you can download
this or see it in appletviewer perhaps.

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


Paul Lutus

unread,
Nov 4, 2001, 3:28:31 PM11/4/01
to
"Wes O'Brien" <m...@here.com> wrote in message
news:9s3u10$vum9n$1...@ID-110468.news.dfncis.de...

> Im afraid it's alien boy back again - I have completed, largely due to
your
> help, my files. However I have two instances of an 'Alien' (just a series
of
> ovals and lines), which consists of some graphics in the first file
> Alien.java, and an 'eye' which overlays the initial graphics from the
second
> file Mutant.java. The first must move with keypresses of up down left and
> right, and the other must move to the position of a mouse click. Upon 2
> mouse clicks in the same position it must disappear, reappearing on the
next
> click. When I make the first instance move there remains a sort of 'image'
> which follows the original about 3 pixels behind it, and when the second
> moves it also leaves the graphic from the first file in the last position,
> and when it should disappear an instance does, but there remains an
instance
> which seems to follow it. It might make it clearer if I show you the class
> file, its at www.f21.co.uk/java/Space.class . Not sure if you can download
> this or see it in appletviewer perhaps.
>
> I have written the following which is a series of 4 files: Alien.class,
> Mutant.class, RovingAlien.class, each inheriting from the last.

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 I Palaste

unread,
Nov 4, 2001, 3:51:04 PM11/4/01
to
Sorry to be off-topic, but I can't help noticing how fitting it is for
you to be dealing with space travel -type thingies when you share a
first name with Wesley Crusher and a last name with Miles O'Brien. =)

--
/-- 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

0 new messages