skyzer 0 Light Poster

My every figure has centre point with coordinates x, y
tips number
radius which shows tip range from centre point.
i have a drawingRule method which is for every shape i need to draw.

package business_logic;

import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;

@SuppressWarnings("serial")
public class Vector extends JPanel {
	public int x, y;
	
	/**
	 * 
	 * @param x
	 * @param y
	 */
	public Vector(int x, int y) {
		this.x = x;
		this.y = y;
	}
	/**
	 * Vector draws itself
	 */
	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		g.setColor(Color.RED);
		g.drawLine(Shape.startPoint.x, Shape.startPoint.y, 
				Shape.startPoint.x + x, Shape.startPoint.y + y);
	}
	
}
package business_logic;

import java.awt.Graphics;
import java.awt.Point;
import java.util.ArrayList;
import javax.swing.JPanel;

@SuppressWarnings("serial")
public abstract class Shape extends JPanel{
	public ArrayList<Vector> vector = new ArrayList<Vector>();
	public static Point startPoint = new Point(200,200); // starpoint by default
	public static int tipNumber = 5;
	public static int radius = 100;
	
	public abstract void drawingRule (int i);
		
	
	
	/**
	 * changes shape start point
	 * @param x
	 * @param y
	 */
	public void changeStartPoint (int x, int y) {
		startPoint.setLocation(x, y);
	}
	/**
	 * is final and has iteration over points collection
	 * @param g
	 */
	final void drawShape (Graphics g) {
		for (int i = 0; i < vector.size(); i++) {
			vector.get(i).paintComponent(g);
			drawingRule(i);
		}
	}
	public Shape() {
		//for (int i = 0; i<=tipNumber; i++) {
			vector.add(new Vector(-90,0));
			vector.add(new Vector(-90,60));
			vector.add(new Vector(60,60));
		//}
	}
}
package business_logic;

import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JLabel;

@SuppressWarnings("serial")
public class OrnamentShape extends Shape {
	public OrnamentShape() {
		add(new JLabel("Ornament"));
		setBackground(Color.BLUE);
	}
	@Override
	public void drawingRule(int i) {
		
	}
	protected void paintComponent(Graphics g){
		super.paintComponent(g);
		g.setColor( Color.BLACK);
		drawShape(g);
	}
}
package business_logic;

import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JLabel;

@SuppressWarnings("serial")
public class GridFigure extends Shape {
	public GridFigure() {
		add(new JLabel("Grid"));
		setBackground(Color.BLUE);
	}
	@Override
	public void drawingRule(int i) {

	}
	protected void paintComponent(Graphics g){
		super.paintComponent(g);
		g.setColor( Color.BLACK);
		drawShape(g);
	}

}
package business_logic;

import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JLabel;

@SuppressWarnings("serial")
public class StarFigure extends Shape {

	public StarFigure () {
		add(new JLabel("Star"));
		setBackground(Color.BLUE);
	}
	@Override
	public void drawingRule(int i) {
		startPoint.x=startPoint.x;
		startPoint.y=startPoint.y;	
	}
	/**
	 * Meetod mis lubab joonistda ekraanil 
	 */
	protected void paintComponent(Graphics g){
		super.paintComponent(g);
		g.setColor( Color.BLACK);
		drawShape(g);
	}

}
package gui;

import java.awt.*;

import javax.swing.*;

import business_logic.*;
import business_logic.Shape;

@SuppressWarnings("serial")
public class Application extends JApplet {

	/**
	 * @param
	 */
	public void init() {
		Shape i[] = new Shape[3];
		i[0] = new GridFigure();
		i[1] = new StarFigure();
		i[2] = new OrnamentShape();
		Container pane=getContentPane();
		pane.add(i[0], BorderLayout.WEST);
		pane.add(i[1], BorderLayout.CENTER);
		pane.add(i[2], BorderLayout.EAST);
		setSize(1200, 500);
		
	}

}

got some questions how to do it.
if i want to draw a star which angle between the lines must be same, dont care if its with 3 or 7 tips. how could it be done? maybe i should divide 360 by tips number then use radius and cosinus or sinus to get lines?
grid should be drawn like this: from first tip to second, from second to third... from last to first.
and the ornament is hardest. shown as third on attached picture

in the Shape constructor in for cycle i think i < tipNumber should be used
vector.add(new Vector(x,y)); which they could be?
thanks in advance, hoping to hear for some hints or ideas.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.