drawing shapes program using multiple classes, help me please //interesting
program hierarchy
3 packages and 8 classes
screen-screencoordinate
shapes-point,shape,shapespanel,shapestest
world-bounds,coordiante,coordinate
i am getting the jframe but somehow not getting points on to it.
the following is the source code of classes,
package screen;
public class ScreenCoordinate
{
private int m_x;
private int m_y;
public ScreenCoordinate(int x, int y)
{
this.m_x = x;
this.m_y = y;
}
public int getX()
{
return m_x;
}
public int getY()
{
return m_y;
}
public boolean equals(ScreenCoordinate coord)
{
return false;
}
public String toString()
{
String sc = "X"+getX()+" "+"Y"+getY();
return sc;
}
}
package shapes;
import java.awt.Color;
import java.awt.Graphics;
import world.Coordinate;
import world.CoordinateSystem;
public class Point extends Shape {
private static int WIDTH =10;
public Point(Coordinate postion){
}
public Point(Coordinate postion, Color g){
}
public Point(double x, double y, java.awt.Color color){
}
public Point(double x, double y){
this(new Coordinate(x,y));
}
public void draw(Graphics g, CoordinateSystem s) {
g.setColor(Color.black);
}
public boolean equals(Shape shape) {
// TODO Auto-generated method stub
return false;
}
}
package shapes;
import java.awt.Color;
import java.awt.Graphics;
import world.Bounds;
import world.Coordinate;
import world.CoordinateSystem;
public abstract class Shape {
private Bounds bounds;
private Color m_color;
private Coordinate m_position;
public abstract void draw(Graphics g, CoordinateSystem s);
public abstract boolean equals(Shape shape);
Bounds getBounds(){
return bounds;
}
Color getColor(){
return m_color;
}
Coordinate getPosition(){
return m_position;
}
void setColor(Color color){
this.m_color = color;
}
void setPosition(Coordinate position){
this.m_position = position;
}
}
package shapes;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
import world.Bounds;
import world.Coordinate;
import world.CoordinateSystem;
public class ShapesPanel extends JPanel
{
private CoordinateSystem m_coord;
private Shape[] m_shapes;
public ShapesPanel()
{
setOpaque(true);
setBackground(Color.white);
setPreferredSize(new java.awt.Dimension(500,500));
setSize(new java.awt.Dimension(500,500));
}
public ShapesPanel(Bounds bounds)
{
m_coord = new CoordinateSystem(bounds);
}
public ShapesPanel(Shape[] m_shapes)
{
super();
this.m_shapes = m_shapes;
}
public void add(Shape shape)
{
System.out.println("Hello we are here");
}
public void add(Shape[] shapes)
{
System.out.println("Hello we are here");
}
public void add(Coordinate[] m_coords)
{
System.out.println("hello");
}
public Shape getShapeAt(int index){
return m_shapes[index];
}
public int getShapeCount(){
return m_shapes.length;
}
public void paintComponent(java.awt.Graphics g)
{
super.paintComponent(g);
g.setColor(Color.black);
for (int i=0;i<m_shapes.length;i++)
{
Point pt = (Point)m_shapes;
g.fillOval(10,10,50,50);
//g.drawOval(10,10,10,10);
}
}
public void remove(Shape shape){
}
public void removeAll(){
}
public void setBounds(){
}
public void setBounds(Bounds bounds){
}
}
package shapes;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import world.Coordinate;
public class ShapesTest extends JFrame implements ActionListener
{
protected ShapesPanel canvas = new ShapesPanel(m_shapes);
public ShapesTest()
{
super("");
setSize(500,500);
setBackground(Color.yellow);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
setTitle("Shapes");
}
public void actionPerformed(ActionEvent e)
{
System.out.println("actionPerformed");
canvas.add(m_shapes);
canvas.add(m_coords);
}
private static Coordinate[] m_coords =
{
new Coordinate(1., 11.),
new Coordinate(2., 13.),
new Coordinate(3., 16.),
new Coordinate(4., 20.),
new Coordinate(5., 25.),
new Coordinate(6., 31.),
new Coordinate(7., 33.),
new Coordinate(8., 32.),
new Coordinate(9., 29.),
new Coordinate(10., 23.),
new Coordinate(11., 16.),
new Coordinate(12., 12.),
};
//protected ShapesPanel canvas = new ShapesPanel(m_shapes);
public static void main(String argv[])
{
new ShapesTest();
}
}
package world;
public class Bounds {
private Coordinate m_lowerleft;
private Coordinate m_upperRight;
private Coordinate center;
public Bounds (Coordinate lowerLeft, Coordinate upperRight){
this.m_lowerleft = lowerLeft;
this.m_upperRight = upperRight;
}
public Coordinate getLowerLeft(){
return m_lowerleft;
}
public Coordinate getUpperRight(){
return m_upperRight;
}
public Coordinate getCenter(){
return center;
}
public double getHeight(){
return 0.0;
}
public double getWidth(){
return 0.0;
}
public Bounds getCombinedBounds(Bounds bounds){
return bounds;
}
}
package world;
public class Coordinate {
private double m_x;
private double m_y;
public Coordinate(double x, double y){
this.m_x = x;
this.m_y = y;
}
public boolean equals(Coordinate coord){
return false;
}
public Bounds getCombinedBounds(Coordinate coord){
return new Bounds(this.min(coord),this.max(coord));
}
public double getX(){
return this.m_x;
}
public double getY(){
return this.m_y;
}
public Coordinate max(Coordinate coord){
return coord;
}
public Coordinate min(Coordinate coord){
return coord;
}
}
package world;
import screen.ScreenCoordinate;
public class CoordinateSystem {
private static final int INSETS=5;
private int m_xwidth;
private int m_yheight;
private Bounds m_bounds;
public CoordinateSystem(){}
public CoordinateSystem(Bounds bound){}
public void setBounds(Bounds bounds){
m_bounds = bounds;
}
public Bounds getBounds(){
return m_bounds;
}
public void setViewPortSize(int width, int height){
this.m_xwidth = width;
this.m_yheight = height;
}
public int worldXToScreen(double x){
Bounds bounds = getBounds();
double xlow = bounds.getLowerLeft().getX();
double xhigh = bounds.getUpperRight().getX();
int value = (int) Math.round( (m_xwidth - 2 * INSETS)
* (x - xlow) / (xhigh - xlow));
return (INSETS + value);
}
public int worldYToScreen(double y){
Bounds bounds = getBounds();
double ylow = bounds.getLowerLeft().getY();
double yhigh = bounds.getUpperRight().getY();
int value = (int) Math.round( (m_yheight - 2 * INSETS)
* (yhigh - y) / (yhigh - ylow));
return (INSETS + value);
}
public double screenXToWorld(int x){
Bounds bounds = getBounds();
double xlow = bounds.getLowerLeft().getX();
double xhigh = bounds.getUpperRight().getX();
x -= INSETS;
return ( (x * (double) (xhigh - xlow)) /
(double) (m_xwidth - 2 * INSETS)
) + xlow;
}
public double screenYToWorld(int y){
Bounds bounds = getBounds();
double ylow = bounds.getLowerLeft().getY();
double yhigh = bounds.getUpperRight().getY();
y -= INSETS;
return yhigh - ( (y * (double) (yhigh - ylow)) /
(double) (m_yheight - 2 * INSETS)
);
}
public Coordinate screenToWorld(ScreenCoordinate coordinate){
return new Coordinate(screenXToWorld(coordinate.getX()),screenYToWorld(coordinate.getY()));
}
public ScreenCoordinate worldToScreen(Coordinate coordinate){
return new ScreenCoordinate(worldXToScreen(coordinate.getX()),worldYToScreen(coordinate.getY()));
}
}
==================================================================
my output should plot the coordinates on the jframe...but i am only getting jframe..anybody help please>

