Probleme de héritage en java
jamal1986
Messages postés
3
Date d'inscription
Statut
Membre
Dernière intervention
-
jamal1986 -
jamal1986 -
Bonjour,
j'ai un petit problème d'héritage en java : voila je vous explique;
j'ai crée un class ball.java
import java.awt.*;
import java.util.Random;
public class Ball
{
public float pos;
private BallPath ballPath;
private Color color;
public Random R;
public Ball(BallPath ballPath, float pos, Color color)
{
this.ballPath = ballPath;
this.pos = pos;
this.color = color;
}
public void paint(Graphics g)
{
Point p = ballPath.getPathPoint(pos);
g.setColor(color);
g.fillOval(p.x-DEF.BALL_RADIUS/2, p.y-DEF.BALL_RADIUS/2, DEF.BALL_RADIUS+1,DEF.BALL_RADIUS+1);
g.setColor(Color.yellow);
g.drawOval(p.x-DEF.BALL_RADIUS/2, p.y-DEF.BALL_RADIUS/2, DEF.BALL_RADIUS,DEF.BALL_RADIUS);
}
}
ensuite j'ai crée un class qui hérite de set class Ballspécial
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
public class Ballspecial extends Ball{
public float pos;
private BallPath ballPath;
private Color color;
public Ballspecial(BallPath ballPath,float pos,Color color)
{
super(ballPath, pos, color);
this.ballPath = ballPath;
this.pos = pos;
this.color = color;
}
public void paint(Graphics g)
{
Point p = ballPath.getPathPoint(pos);
g.setColor(color);
g.fillOval(p.x-DEF.BALL_RADIUS/2, p.y-DEF.BALL_RADIUS/2, DEF.BALL_RADIUS+1,DEF.BALL_RADIUS+1);
g.setColor(Color.red);
g.drawOval(p.x-DEF.BALL_RADIUS/2, p.y-DEF.BALL_RADIUS/2, DEF.BALL_RADIUS,DEF.BALL_RADIUS);
}
}
j'ai réussi d'afficher les ball dans une chaine de ball défini sous forme de string mai pas la ball spécial
j'ai fai des instructions de ce genre
balls = new ArrayList<Ball>();
ballspecial=new ArrayList<Ballspecial>();
Merci en avance de votre aide
j'ai un petit problème d'héritage en java : voila je vous explique;
j'ai crée un class ball.java
import java.awt.*;
import java.util.Random;
public class Ball
{
public float pos;
private BallPath ballPath;
private Color color;
public Random R;
public Ball(BallPath ballPath, float pos, Color color)
{
this.ballPath = ballPath;
this.pos = pos;
this.color = color;
}
public void paint(Graphics g)
{
Point p = ballPath.getPathPoint(pos);
g.setColor(color);
g.fillOval(p.x-DEF.BALL_RADIUS/2, p.y-DEF.BALL_RADIUS/2, DEF.BALL_RADIUS+1,DEF.BALL_RADIUS+1);
g.setColor(Color.yellow);
g.drawOval(p.x-DEF.BALL_RADIUS/2, p.y-DEF.BALL_RADIUS/2, DEF.BALL_RADIUS,DEF.BALL_RADIUS);
}
}
ensuite j'ai crée un class qui hérite de set class Ballspécial
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
public class Ballspecial extends Ball{
public float pos;
private BallPath ballPath;
private Color color;
public Ballspecial(BallPath ballPath,float pos,Color color)
{
super(ballPath, pos, color);
this.ballPath = ballPath;
this.pos = pos;
this.color = color;
}
public void paint(Graphics g)
{
Point p = ballPath.getPathPoint(pos);
g.setColor(color);
g.fillOval(p.x-DEF.BALL_RADIUS/2, p.y-DEF.BALL_RADIUS/2, DEF.BALL_RADIUS+1,DEF.BALL_RADIUS+1);
g.setColor(Color.red);
g.drawOval(p.x-DEF.BALL_RADIUS/2, p.y-DEF.BALL_RADIUS/2, DEF.BALL_RADIUS,DEF.BALL_RADIUS);
}
}
j'ai réussi d'afficher les ball dans une chaine de ball défini sous forme de string mai pas la ball spécial
j'ai fai des instructions de ce genre
balls = new ArrayList<Ball>();
ballspecial=new ArrayList<Ballspecial>();
Merci en avance de votre aide
A voir également:
- Probleme de héritage en java
- Waptrick java football - Télécharger - Jeux vidéo
- Jeux java itel - Télécharger - Jeux vidéo
- Eclipse java - Télécharger - Langages
- Java apk - Télécharger - Langages
- Waptrick java voiture - Télécharger - Jeux vidéo
j'ai déclaré les variables ballPath et color comme protected dans la class mere..
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
public class Ballspecial extends Ball{
public Ballspecial(BallPath ballPath,float pos,Color color)
{
super(ballPath, pos, color);
}
public void paint(Graphics g)
{
Point p = ballPath.getPathPoint(pos);
g.setColor(color);
g.fillOval(p.x-DEF.BALL_RADIUS/2, p.y-DEF.BALL_RADIUS/2, DEF.BALL_RADIUS+1,DEF.BALL_RADIUS+1);
g.setColor(Color.red);
g.drawOval(p.x-DEF.BALL_RADIUS/2, p.y-DEF.BALL_RADIUS/2, DEF.BALL_RADIUS,DEF.BALL_RADIUS);
}
}
mai j'ai encore un petit souci sur comment tester l'égalité de trois ball adjacents, je sai qu'il faut appeler la méthode equal mai je sai pas comment jouer sur le corps des instructions...
Merci vivement de votre aide