Is there anyone can help me?!!Plz...

hi,

i am doing a drawing tools program such kind like paint application..I had done several things such as draw a basic shape but still incomplete with certain features realated to it.The features that not complete yet such as:

1.Edit drawn shape fill color and line colors

2.Change line stye of the shape

3.Change dash style of the shape

4.Draw arrow in different ways/style

5.Draw shadow of the shape..

Can anyone help me in doing this?I really really appriciate anybody who can help me with this problem..I know there's somebody with out there could help me..

Anyway, this is part of my code..Plz check for me...

1.Painter.java

import java.awt.*;

import java.awt.event.*;

import java.util.*;

import java.io.*;

import javax.swing.*;

public class Painter extends JFrame

{

private CanvasPanel canvasPanel;

private ToolButtonPaneltoolButtonPanel;

private ColorButtonPanelcolorButtonPanel;

private Container mainContainer;

private String fileName;

JMenuBar mainBar;

public Painter()

{

super("Drawing Tools");

fileName = null;

mainBar = new JMenuBar();

setJMenuBar(mainBar);

/*-*/

canvasPanel= new CanvasPanel();

toolButtonPanel= new ToolButtonPanel(canvasPanel);

colorButtonPanel = new ColorButtonPanel(canvasPanel);

mainContainer = getContentPane();

mainContainer.add(toolButtonPanel,BorderLayout.NORTH);

mainContainer.add(canvasPanel,BorderLayout.CENTER);

mainContainer.add(colorButtonPanel,BorderLayout.SOUTH);

setSize(600,500);

this.setResizable(false);

setVisible(true);

addWindowListener (

new WindowAdapter ()

{

public void windowClosing (WindowEvent e)

{

System.exit(0);

}

public void windowDeiconified (WindowEvent e)

{

canvasPanel.repaint();

}

public void windowActivated (WindowEvent e)

{

canvasPanel.repaint();

}

}

);

}

/*-*/

public static void main(String args[])

{

Painter application = new Painter();

application.show();

application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

}

2.ToolButtonPanel.java

import java.awt.*;

import java.awt.event.*;

import java.util.*;

import javax.swing.*;

public class ToolButtonPanel extends JPanel

{

private JButton lineBtn,arrowBtn, squareBtn, ovalBtn, polygonBtn, roundRectBtn, freeHandBtn, LStyleBtn, dashBtn, AStyleBtn, shadeBtn, clearBtn;

private JCheckBox fillChk;

private CanvasPanel canvasPanel;

public ToolButtonPanel(CanvasPanel inCanvasPanel)

{

canvasPanel = inCanvasPanel;

/*-*/

lineBtn= new JButton("",new ImageIcon("lineBtn.gif"));

arrowBtn= new JButton("",new ImageIcon("lineBtn.gif"));

squareBtn= new JButton("",new ImageIcon("squareBtn.gif"));

roundRectBtn= new JButton("",new ImageIcon("roundRectBtn.gif"));

ovalBtn = new JButton("",new ImageIcon("ovalBtn.gif"));

polygonBtn= new JButton("",new ImageIcon("polygonBtn.gif"));

freeHandBtn= new JButton("",new ImageIcon("freeHandBtn.gif"));

LStyleBtn= new JButton("",new ImageIcon("undoBtn.gif"));

AStyleBtn= new JButton("",new ImageIcon("undoBtn.gif"));

dashBtn= new JButton("",new ImageIcon("redoBtn.gif"));

arrowBtn= new JButton("",new ImageIcon("redoBtn.gif"));

clearBtn= new JButton("",new ImageIcon("clearBtn.gif"));

lineBtn.addActionListener(new ToolButtonListener());

lineBtn.setToolTipText("Line");

arrowBtn.addActionListener(new ToolButtonListener());

arrowBtn.setToolTipText("Arrow");

squareBtn.addActionListener(new ToolButtonListener());

squareBtn.setToolTipText("Retangle");

roundRectBtn.addActionListener(new ToolButtonListener());

roundRectBtn.setToolTipText("Round Rectangle");

ovalBtn.addActionListener(new ToolButtonListener());

ovalBtn.setToolTipText("Oval");

polygonBtn.addActionListener(new ToolButtonListener());

polygonBtn.setToolTipText("Polygon");

freeHandBtn.addActionListener(new ToolButtonListener());

freeHandBtn.setToolTipText("Free Hand");

LStyleBtn.addActionListener(new ToolButtonListener());

LStyleBtn.setToolTipText("Line Style");

dashBtn.addActionListener(new ToolButtonListener());

dashBtn.setToolTipText("Dash Style");

AStyleBtn.addActionListener(new ToolButtonListener());

AStyleBtn.setToolTipText("Arrow Style");

shadeBtn.addActionListener(new ToolButtonListener());

shadeBtn.setToolTipText("Shadow");

clearBtn.addActionListener(new ToolButtonListener());

clearBtn.setToolTipText("Clear Canvas");

/*-*/

fillChk = new JCheckBox("Fill");

fillChk.addItemListener(

new ItemListener()

{

public void itemStateChanged(ItemEvent event)

{

if(fillChk.isSelected())

canvasPanel.setSolidMode(Boolean.TRUE);

else

canvasPanel.setSolidMode(Boolean.FALSE);

}

}

);

/*-*/

this.setLayout(new GridLayout(1,9)); // 8 Buttons & 1 CheckBox

this.add(lineBtn);

this.add(arrowBtn);

this.add(ovalBtn);

this.add(squareBtn);

this.add(roundRectBtn);

this.add(polygonBtn);

this.add(freeHandBtn);

this.add(LStyleBtn);

this.add(dashBtn);

this.add(AStyleBtn);

this.add(shadeBtn);

this.add(clearBtn);

this.add(fillChk);

}

/*-*/

private class ToolButtonListener implements ActionListener

{

public void actionPerformed(ActionEvent event)

{

if(canvasPanel.isExistPolygonBuffer()!= false)

{

canvasPanel.flushPolygonBuffer();

}

if(event.getSource() == lineBtn)

{

canvasPanel.setDrawMode(canvasPanel.LINE);

}

if(event.getSource() == arrowBtn)

{

canvasPanel.setDrawMode(canvasPanel.ARROW);

}

if(event.getSource() == squareBtn)

{

canvasPanel.setDrawMode(canvasPanel.SQUARE);

}

if(event.getSource() == ovalBtn)

{

canvasPanel.setDrawMode(canvasPanel.OVAL);

}

if(event.getSource() == polygonBtn)

{

canvasPanel.setDrawMode(canvasPanel.POLYGON);

}

if(event.getSource() == roundRectBtn)

{

canvasPanel.setDrawMode(canvasPanel.ROUND_RECT);

}

if(event.getSource() == freeHandBtn)

{

canvasPanel.setDrawMode(canvasPanel.FREE_HAND);

}

if(event.getSource() == LStyleBtn)

{

canvasPanel.setDrawMode(canvasPanel.LINE_STYLE);

}

if(event.getSource() == dashBtn)

{

canvasPanel.setDrawMode(canvasPanel.DASH_STYLE);

}

if(event.getSource() == AStyleBtn)

{

canvasPanel.setDrawMode(canvasPanel.ARROW_STYLE);

}

if(event.getSource() == shadeBtn)

{

canvasPanel.setDrawMode(canvasPanel.SHADOW);

}

if(event.getSource() == clearBtn)

{

canvasPanel.clearCanvas();

}

}

}

}

3.ColorButtonPanel.java

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.border.*;

public class ColorButtonPanel extends JPanel

{

private JPanel colorButtonPanel;

private JButton foreGroundColorBtn,backGroundColorBtn;

private JLabel foreGroundColorLbl,backGroundColorLbl,foreColorLbl,backColorLbl;

private Color foreColor, backColor;

private CanvasPanel canvasPanel;

public ColorButtonPanel(CanvasPanel inCanvasPanel)

{

canvasPanel = inCanvasPanel;

foreGroundColorLbl = new JLabel("");

foreGroundColorLbl.setOpaque(true);

foreGroundColorLbl.setBackground(canvasPanel.getForeGroundColor());

foreGroundColorLbl.setBorder(BorderFactory.createLineBorder(Color.BLACK));

backGroundColorLbl = new JLabel("");

backGroundColorLbl.setOpaque(true);

backGroundColorLbl.setBackground(canvasPanel.getBackGroundColor());

backGroundColorLbl.setBorder(BorderFactory.createLineBorder(Color.WHITE));

foreGroundColorBtn = new JButton("ForeGroundColor->");

foreGroundColorBtn.addActionListener(

new ActionListener()

{

public void actionPerformed(ActionEvent event)

{

setForeGroundColor();

}

}

);

backGroundColorBtn = new JButton("BackGroundColor->");

backGroundColorBtn.addActionListener(

new ActionListener()

{

public void actionPerformed(ActionEvent event)

{

setBackGroundColor();

}

}

);

this.setLayout(new GridLayout(1,4));

this.add(foreGroundColorBtn);

this.add(foreGroundColorLbl);

this.add(backGroundColorBtn);

this.add(backGroundColorLbl);

}

/*-*/

public void setForeGroundColor()

{

foreColor = JColorChooser.showDialog(null,"ForeGround Color",foreColor);

if(foreColor!=null)

{

foreGroundColorLbl.setBackground(foreColor);

canvasPanel.setForeGroundColor(foreColor);

}

}

/*-*/

public void setBackGroundColor()

{

backColor = JColorChooser.showDialog(null,"BackGround Color",backColor);

if(backColor!=null)

{

backGroundColorLbl.setBackground(backColor);

canvasPanel.setBackGroundColor(backColor);

}

}

}

and lasty..

4. CanvasPanel.java

import java.awt.*;

import java.awt.event.*;

import java.awt.image.*;

import java.util.*;

import java.io.*;

import javax.swing.*;

import javax.imageio.*;

public class CanvasPanel extends JPanel implements MouseListener,MouseMotionListener, Serializable

{

protected final static int LINE=1,ARROW=2,SQUARE=3,OVAL=4,POLYGON=5,ROUND_RECT=6,FREE_HAND=7,

LINE_STYLE=8,DASH_STYLE=9,ARROW_STYLE=10,SHADOW=11,

SOLID_SQUARE=22, SOLID_OVAL=33, SOLID_POLYGON=44,

SOLID_ROUND_RECT=55;

protected static Vector vLine,vArrow,vSquare,vOval,vPolygon,vRoundRect,vFreeHand,

vSolidSquare,vSolidOval,vSolidPolygon,vSolidRoundRect,vFile,

xPolygon, yPolygon;

private Color foreGroundColor, backGroundColor;

private int x1,y1,x2,y2,linex1,linex2,liney1,liney2, drawMode=0;

private boolean solidMode, polygonBuffer;

private File fileName;

public CanvasPanel()

{

vLine = new Vector();

vSquare = new Vector();

vOval= new Vector();

vPolygon= new Vector();

vRoundRect= new Vector();

vFreeHand= new Vector();

vSolidSquare= new Vector();

vSolidOval= new Vector();

vSolidPolygon= new Vector();

vSolidRoundRect= new Vector();

vFile= new Vector();

xPolygon= new Vector();

yPolygon= new Vector();

addMouseListener(this);

addMouseMotionListener(this);

solidMode = false;

polygonBuffer = false;

foreGroundColor = Color.BLACK;

backGroundColor = Color.WHITE;

setBackground(backGroundColor);

repaint();

}

/*-*/

public void mousePressed(MouseEvent event)

{

x1 = linex1 = linex2 = event.getX();

y1 = liney1 = liney2 = event.getY();

}

/*-*/

public void mouseClicked(MouseEvent event){}

public void mouseMoved(MouseEvent event){}

/*-*/

public void mouseReleased(MouseEvent event)

{

if (drawMode == LINE)

{

vLine.add(new Coordinate(x1,y1,event.getX(),event.getY(),foreGroundColor));

//undoStack.push(new StepInfo(LINE ,new Coordinate(x1,y1,event.getX(),event.getY(),foreGroundColor)));

}

if (drawMode == SQUARE)

{

if(solidMode)

{

if(x1 > event.getX() || y1 > event.getY())

{

vSolidSquare.add(new Coordinate(event.getX(),event.getY(),x1,y1,foreGroundColor));

// undoStack.push(new StepInfo(SOLID_SQUARE, new Coordinate(event.getX(),event.getY(),x1,y1,foreGroundColor)));

}

else

{

vSolidSquare.add(new Coordinate(x1,y1,event.getX(),event.getY(),foreGroundColor));

//undoStack.push(new StepInfo(SOLID_SQUARE, new Coordinate(x1,y1,event.getX(),event.getY(),foreGroundColor)));

}

}

else

{

if(x1 > event.getX() || y1 > event.getY())

{

vSquare.add(new Coordinate(event.getX(),event.getY(),x1,y1,foreGroundColor));

//undoStack.push(new StepInfo(SQUARE, new Coordinate(event.getX(),event.getY(),x1,y1,foreGroundColor)));

}

else

{

vSquare.add(new Coordinate(x1,y1,event.getX(),event.getY(),foreGroundColor));

//undoStack.push(new StepInfo(SQUARE, new Coordinate(x1,y1,event.getX(),event.getY(),foreGroundColor)));

}

}

}

if (drawMode == this.OVAL)

{

if(solidMode)

{

if(x1 > event.getX() || y1 > event.getY())

{

vSolidOval.add(new Coordinate(event.getX(),event.getY(),x1,y1,foreGroundColor));

//undoStack.push(new StepInfo(SOLID_OVAL, new Coordinate(event.getX(),event.getY(),x1,y1,foreGroundColor)));

}

else

{

vSolidOval.add(new Coordinate(x1,y1,event.getX(),event.getY(),foreGroundColor));

//undoStack.push(new StepInfo(SOLID_OVAL, new Coordinate(x1,y1,event.getX(),event.getY(),foreGroundColor)));

}

}

else

{

if(x1 > event.getX() || y1 > event.getY())

{

vOval.add(new Coordinate(event.getX(),event.getY(),x1,y1,foreGroundColor));

//undoStack.push(new StepInfo(OVAL, new Coordinate(event.getX(),event.getY(),x1,y1,foreGroundColor)));

}

else

{

vOval.add(new Coordinate(x1,y1,event.getX(),event.getY(),foreGroundColor));

//undoStack.push(new StepInfo(OVAL, new Coordinate(x1,y1,event.getX(),event.getY(),foreGroundColor)));

}

}

}

if (drawMode == this.POLYGON || drawMode == this.SOLID_POLYGON)

{

xPolygon.add(new Integer(event.getX()));

yPolygon.add(new Integer(event.getY()));

polygonBuffer = true;

repaint();

}

if (drawMode == this.ROUND_RECT)

{

if(solidMode)

{

if(x1 > event.getX() || y1 > event.getY())

{

vSolidRoundRect.add(new Coordinate(event.getX(),event.getY(),x1,y1,foreGroundColor));

//undoStack.push(new StepInfo(SOLID_ROUND_RECT, new Coordinate(event.getX(),event.getY(),x1,y1,foreGroundColor)));

}

else

{

vSolidRoundRect.add(new Coordinate(x1,y1,event.getX(),event.getY(),foreGroundColor));

//undoStack.push(new StepInfo(SOLID_ROUND_RECT, new Coordinate(x1,y1,event.getX(),event.getY(),foreGroundColor)));

}

}

else

{

if(x1 > event.getX() || y1 > event.getY())

{

vRoundRect.add(new Coordinate(event.getX(),event.getY(),x1,y1,foreGroundColor));

//undoStack.push(new StepInfo(ROUND_RECT, new Coordinate(event.getX(),event.getY(),x1,y1,foreGroundColor)));

}

else

{

vRoundRect.add(new Coordinate(x1,y1,event.getX(),event.getY(),foreGroundColor));

//undoStack.push(new StepInfo(ROUND_RECT, new Coordinate(x1,y1,event.getX(),event.getY(),foreGroundColor)));

}

}

}

x1=linex1=x2=linex2=0;

y1=liney1=y2=liney2=0;

}

/*-*/

public void mouseEntered(MouseEvent event)

{

setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));

}

/*-*/

public void mouseExited(MouseEvent event)

{

setCursor(new Cursor(Cursor.DEFAULT_CURSOR));

}

/*-*/

public void mouseDragged(MouseEvent event)

{

x2 = event.getX();

y2 = event.getY();

if (drawMode == this.FREE_HAND)

{

linex1 = linex2;

liney1 = liney2;

linex2 = x2;

liney2 = y2;

vFreeHand.add(new Coordinate(linex1,liney1,linex2,liney2,foreGroundColor));

}

repaint();

}

/*-*/

public void paintComponent(Graphics g)

{

super.paintComponent(g);

redrawVectorBuffer(g);

g.setColor(foreGroundColor);

if (drawMode == LINE)

{

g.drawLine(x1,y1,x2,y2);

}

if (drawMode == OVAL)

{

if(solidMode)

{

if(x1 > x2 || y1 > y2)

g.fillOval(x2,y2,x1-x2,y1-y2);

else

g.fillOval(x1,y1,x2-x1,y2-y1);

}

else

{

if(x1 > x2 || y1 > y2)

g.drawOval (x2,y2,x1-x2,y1-y2);

else

g.drawOval (x1,y1,x2-x1,y2-y1);

}

}

if (drawMode == ROUND_RECT)

{

if(solidMode)

{

if(x1 > x2 || y1 > y2)

g.fillRoundRect(x2,y2,x1-x2,y1-y2,25,25);

else

g.fillRoundRect(x1,y1,x2-x1,y2-y1,25,25);

}

else

{

if(x1 > x2 || y1 > y2)

g.drawRoundRect(x2,y2,x1-x2,y1-y2,25,25);

else

g.drawRoundRect(x1,y1,x2-x1,y2-y1,25,25);

}

}

if (drawMode == SQUARE)

{

if(solidMode)

{

if(x1 > x2 || y1 > y2)

g.fillRect (x2,y2,x1-x2,y1-y2);

else

g.fillRect (x1,y1,x2-x1,y2-y1);

}

else

{

if(x1 > x2 || y1 > y2)

g.drawRect (x2,y2,x1-x2,y1-y2);

else

g.drawRect (x1,y1,x2-x1,y2-y1);

}

}

if (drawMode == POLYGON || drawMode == SOLID_POLYGON)

{

int xPos[] = new int[xPolygon.size()];

int yPos[] = new int[yPolygon.size()];

for(int count=0;count<xPos.length;count++)

{

xPos[count] = ((Integer)(xPolygon.elementAt(count))).intValue();

yPos[count] = ((Integer)(yPolygon.elementAt(count))).intValue();

}

g.drawPolyline(xPos,yPos,xPos.length);

polygonBuffer = true;

}

if (drawMode == FREE_HAND)

{

g.drawLine(linex1,liney1,linex2,liney2);

}

}

/*-*/

public void setDrawMode(int mode)

{

drawMode = mode;

}

public int getDrawMode()

{

return drawMode;

}

/*-*/

public void setSolidMode(Boolean inSolidMode)

{

solidMode = inSolidMode.booleanValue();

}

public Boolean getSolidMode()

{

return Boolean.valueOf(solidMode);

}

/*-*/

public void setForeGroundColor(Color inputColor)

{

foreGroundColor = inputColor;

}

public Color getForeGroundColor()

{

return foreGroundColor;

}

/*-*/

public void setBackGroundColor(Color inputColor)

{

backGroundColor = inputColor;

this.setBackground(backGroundColor);

}

public Color getBackGroundColor()

{

return backGroundColor;

}

/*-*/

public void clearCanvas()

{

vFreeHand.removeAllElements();

vLine.removeAllElements();

vOval.removeAllElements();

vPolygon.removeAllElements();

vRoundRect.removeAllElements();

vSolidOval.removeAllElements();

vSolidPolygon.removeAllElements();

vSolidRoundRect.removeAllElements();

vSolidSquare.removeAllElements();

vSquare.removeAllElements();

repaint();

}

/*-*/

public boolean isExistPolygonBuffer()

{

return polygonBuffer;

}

/*-*/

public void flushPolygonBuffer()

{

if(!solidMode)

{

vPolygon.add(new Coordinate(xPolygon, yPolygon, foreGroundColor));

}

else

{

vSolidPolygon.add(new Coordinate(xPolygon, yPolygon, foreGroundColor));

}

xPolygon.removeAllElements();

yPolygon.removeAllElements();

polygonBuffer = false;

repaint();

}

/*-*/

private class Coordinate implements Serializable

{

private int x1,y1,x2,y2;

private Color foreColor;

private Vector xPoly, yPoly;

public Coordinate (int inx1,int iny1,int inx2, int iny2, Color color)

{

x1 = inx1;

y1 = iny1;

x2 = inx2;

y2 = iny2;

foreColor = color;

}

public Coordinate(Vector inXPolygon, Vector inYPolygon, Color color)

{

xPoly = (Vector)inXPolygon.clone();

yPoly = (Vector)inYPolygon.clone();

foreColor = color;

}

public Color colour()

{

return foreColor;

}

public int getX1 ()

{

return x1;

}

public int getX2 ()

{

return x2;

}

public int getY1 ()

{

return y1;

}

public int getY2 ()

{

return y2;

}

public Vector getXPolygon()

{

return xPoly;

}

public Vector getYPolygon()

{

return yPoly;

}

}

/*-*/

private class StepInfo implements Serializable

{

private int stepType;

private Coordinate stepCoordinate;

public StepInfo(int inStepType, Coordinate inStepCoordinate)

{

stepType = inStepType;

stepCoordinate = inStepCoordinate;

}

public int getStepType()

{

return stepType;

}

public Coordinate getStepCoordinate()

{

return stepCoordinate;

}

}

/*-*/

private RenderedImage myCreateImage()

{

BufferedImage bufferedImage = new BufferedImage(600,390, BufferedImage.TYPE_INT_RGB);

Graphics g = bufferedImage.createGraphics();

redrawVectorBuffer(g);

g.dispose();

return bufferedImage;

}

/*-*/

private void redrawVectorBuffer(Graphics g)

{

for (int i=0;i<vFreeHand.size();i++){

g.setColor(((Coordinate)vFreeHand.elementAt(i)).colour());

g.drawLine(((Coordinate)vFreeHand.elementAt(i)).getX1(),((Coordinate)vFreeHand.elementAt(i)).getY1(),((Coordinate)vFreeHand.elementAt(i)).getX2(),((Coordinate)vFreeHand.elementAt(i)).getY2());

}

for (int i=0;i<vLine.size();i++){

g.setColor(((Coordinate)vLine.elementAt(i)).colour());

g.drawLine(((Coordinate)vLine.elementAt(i)).getX1(),((Coordinate)vLine.elementAt(i)).getY1(),((Coordinate)vLine.elementAt(i)).getX2(),((Coordinate)vLine.elementAt(i)).getY2());

}

for (int i=0;i<vOval.size();i++){

g.setColor(((Coordinate)vOval.elementAt(i)).colour());

g.drawOval(((Coordinate)vOval.elementAt(i)).getX1(),((Coordinate)vOval.elementAt(i)).getY1(),((Coordinate)vOval.elementAt(i)).getX2()-((Coordinate)vOval.elementAt(i)).getX1(),((Coordinate)vOval.elementAt(i)).getY2()-((Coordinate)vOval.elementAt(i)).getY1());

}

for (int i=0;i<vRoundRect.size();i++){

g.setColor(((Coordinate)vRoundRect.elementAt(i)).colour());

g.drawRoundRect(((Coordinate)vRoundRect.elementAt(i)).getX1(),((Coordinate)vRoundRect.elementAt(i)).getY1(),((Coordinate)vRoundRect.elementAt(i)).getX2()-((Coordinate)vRoundRect.elementAt(i)).getX1(),((Coordinate)vRoundRect.elementAt(i)).getY2()-((Coordinate)vRoundRect.elementAt(i)).getY1(),25,25);

}

for (int i=0;i<vSolidOval.size();i++){

g.setColor(((Coordinate)vSolidOval.elementAt(i)).colour());

g.fillOval(((Coordinate)vSolidOval.elementAt(i)).getX1(),((Coordinate)vSolidOval.elementAt(i)).getY1(),((Coordinate)vSolidOval.elementAt(i)).getX2()-((Coordinate)vSolidOval.elementAt(i)).getX1(),((Coordinate)vSolidOval.elementAt(i)).getY2()-((Coordinate)vSolidOval.elementAt(i)).getY1());

}

for (int i=0;i<vSolidRoundRect.size();i++){

g.setColor(((Coordinate)vSolidRoundRect.elementAt(i)).colour());

g.fillRoundRect(((Coordinate)vSolidRoundRect.elementAt(i)).getX1(),((Coordinate)vSolidRoundRect.elementAt(i)).getY1(),((Coordinate)vSolidRoundRect.elementAt(i)).getX2()-((Coordinate)vSolidRoundRect.elementAt(i)).getX1(),((Coordinate)vSolidRoundRect.elementAt(i)).getY2()-((Coordinate)vSolidRoundRect.elementAt(i)).getY1(),25,25);

}

for (int i=0;i<vSquare.size();i++){

g.setColor(((Coordinate)vSquare.elementAt(i)).colour());

g.drawRect(((Coordinate)vSquare.elementAt(i)).getX1(),((Coordinate)vSquare.elementAt(i)).getY1(),((Coordinate)vSquare.elementAt(i)).getX2()-((Coordinate)vSquare.elementAt(i)).getX1(),((Coordinate)vSquare.elementAt(i)).getY2()-((Coordinate)vSquare.elementAt(i)).getY1());

}

for (int i=0;i<vSolidSquare.size();i++){

g.setColor(((Coordinate)vSolidSquare.elementAt(i)).colour());

g.fillRect(((Coordinate)vSolidSquare.elementAt(i)).getX1(),((Coordinate)vSolidSquare.elementAt(i)).getY1(),((Coordinate)vSolidSquare.elementAt(i)).getX2()-((Coordinate)vSolidSquare.elementAt(i)).getX1(),((Coordinate)vSolidSquare.elementAt(i)).getY2()-((Coordinate)vSolidSquare.elementAt(i)).getY1());

}

for(int i=0;i<vPolygon.size();i++){

int xPos[] = new int[((Coordinate)vPolygon.elementAt(i)).getXPolygon().size()];

int yPos[] = new int[((Coordinate)vPolygon.elementAt(i)).getYPolygon().size()];

for(int count=0;count<xPos.length;count++)

{

xPos[count] = ((Integer)((Coordinate)vPolygon.elementAt(i)).getXPolygon().elementAt(count)).intValue();

yPos[count] = ((Integer)((Coordinate)vPolygon.elementAt(i)).getYPolygon().elementAt(count)).intValue();

}

g.setColor(((Coordinate)vPolygon.elementAt(i)).colour());

g.drawPolygon(xPos,yPos,xPos.length);

}

for(int i=0;i<vSolidPolygon.size();i++){

int xPos[] = new int[((Coordinate)vSolidPolygon.elementAt(i)).getXPolygon().size()];

int yPos[] = new int[((Coordinate)vSolidPolygon.elementAt(i)).getYPolygon().size()];

for(int count=0;count<xPos.length;count++)

{

xPos[count] = ((Integer)((Coordinate)vSolidPolygon.elementAt(i)).getXPolygon().elementAt(count)).intValue();

yPos[count] = ((Integer)((Coordinate)vSolidPolygon.elementAt(i)).getYPolygon().elementAt(count)).intValue();

}

g.setColor(((Coordinate)vSolidPolygon.elementAt(i)).colour());

g.fillPolygon(xPos,yPos,xPos.length);

}

}

}

Pls help me to complete this task..Thanx for all your support..I really appreciate all advice n helps..

thankx in advance.>

[26253 byte] By [cattie79a] at [2007-10-3 3:23:46]
# 1

Hi,

I'll be really surprised if anyone will do this for you. Try to put there precisely specified problem and the forum will try to solve this with you.

However a little advice. Try to search the Internet and I'm quite sure that you will find some apps like yours with sourcecode to look into.

L.P.

lukika at 2007-7-14 21:16:23 > top of Java-index,Desktop,Core GUI APIs...
# 2
1) Use the "Code" formatting tags when posting code so the code is readable.2) Read the tutorial on [url http://java.sun.com/docs/books/tutorial/]2D Painting[/url] for more help.
camickra at 2007-7-14 21:16:23 > top of Java-index,Desktop,Core GUI APIs...
# 3
I've try a lot to search from internet but there's similar with my program..only can draw basic shape but cannot do anything with that shape..I hope anyone can help me to solve this probs..anyway,thanx for ur advice..i really appriciate it..tq
cattie79a at 2007-7-14 21:16:23 > top of Java-index,Desktop,Core GUI APIs...
# 4

hi,

i am doing a drawing tools program such kind like paint application..I had done several things such as draw a basic shape but still incomplete with certain features realated to it.The features that not complete yet such as:

1.Edit drawn shape fill color and line colors

2.Change line stye of the shape

3.Change dash style of the shape

4.Draw arrow in different ways/style

5.Draw shadow of the shape..

Can anyone help me in doing this?I really really appriciate anybody who can help me with this problem..I know there's somebody with out there could help me..

Anyway, this is part of my code..Plz check for me...

1.Painter.java

import java.awt.*;

import java.awt.event.*;

import java.util.*;

import java.io.*;

import javax.swing.*;

public class Painter extends JFrame

{

private CanvasPanel canvasPanel;

private ToolButtonPanel toolButtonPanel;

private ColorButtonPanel colorButtonPanel;

private Container mainContainer;

private String fileName;

JMenuBar mainBar;

public Painter()

{

super("Drawing Tools");

fileName = null;

mainBar = new JMenuBar();

setJMenuBar(mainBar);

/*-*/

canvasPanel = new CanvasPanel();

toolButtonPanel = new ToolButtonPanel(canvasPanel);

colorButtonPanel = new ColorButtonPanel(canvasPanel);

mainContainer = getContentPane();

mainContainer.add(toolButtonPanel,BorderLayout.NORTH);

mainContainer.add(canvasPanel,BorderLayout.CENTER);

mainContainer.add(colorButtonPanel,BorderLayout.SOUTH);

setSize(600,500);

this.setResizable(false);

setVisible(true);

addWindowListener (

new WindowAdapter ()

{

public void windowClosing (WindowEvent e)

{

System.exit(0);

}

public void windowDeiconified (WindowEvent e)

{

canvasPanel.repaint();

}

public void windowActivated (WindowEvent e)

{

canvasPanel.repaint();

}

}

);

}

/*-*/

public static void main(String args[])

{

Painter application = new Painter();

application.show();

application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

}

2.ToolButtonPanel.java

import java.awt.*;

import java.awt.event.*;

import java.util.*;

import javax.swing.*;

public class ToolButtonPanel extends JPanel

{

private JButton lineBtn,arrowBtn, squareBtn, ovalBtn, polygonBtn, roundRectBtn, freeHandBtn, LStyleBtn, dashBtn, AStyleBtn, shadeBtn, clearBtn;

private JCheckBox fillChk;

private CanvasPanel canvasPanel;

public ToolButtonPanel(CanvasPanel inCanvasPanel)

{

canvasPanel = inCanvasPanel;

/*-*/

lineBtn = new JButton("",new ImageIcon("lineBtn.gif"));

arrowBtn = new JButton("",new ImageIcon("lineBtn.gif"));

squareBtn = new JButton("",new ImageIcon("squareBtn.gif"));

roundRectBtn = new JButton("",new ImageIcon("roundRectBtn.gif"));

ovalBtn = new JButton("",new ImageIcon("ovalBtn.gif"));

polygonBtn = new JButton("",new ImageIcon("polygonBtn.gif"));

freeHandBtn = new JButton("",new ImageIcon("freeHandBtn.gif"));

LStyleBtn = new JButton("",new ImageIcon("undoBtn.gif"));

AStyleBtn = new JButton("",new ImageIcon("undoBtn.gif"));

dashBtn = new JButton("",new ImageIcon("redoBtn.gif"));

arrowBtn = new JButton("",new ImageIcon("redoBtn.gif"));

clearBtn = new JButton("",new ImageIcon("clearBtn.gif"));

lineBtn.addActionListener(new ToolButtonListener());

lineBtn.setToolTipText("Line");

arrowBtn.addActionListener(new ToolButtonListener());

arrowBtn.setToolTipText("Arrow");

squareBtn.addActionListener(new ToolButtonListener());

squareBtn.setToolTipText("Retangle");

roundRectBtn.addActionListener(new ToolButtonListener());

roundRectBtn.setToolTipText("Round Rectangle");

ovalBtn.addActionListener(new ToolButtonListener());

ovalBtn.setToolTipText("Oval");

polygonBtn.addActionListener(new ToolButtonListener());

polygonBtn.setToolTipText("Polygon");

freeHandBtn.addActionListener(new ToolButtonListener());

freeHandBtn.setToolTipText("Free Hand");

LStyleBtn.addActionListener(new ToolButtonListener());

LStyleBtn.setToolTipText("Line Style");

dashBtn.addActionListener(new ToolButtonListener());

dashBtn.setToolTipText("Dash Style");

AStyleBtn.addActionListener(new ToolButtonListener());

AStyleBtn.setToolTipText("Arrow Style");

shadeBtn.addActionListener(new ToolButtonListener());

shadeBtn.setToolTipText("Shadow");

clearBtn.addActionListener(new ToolButtonListener());

clearBtn.setToolTipText("Clear Canvas");

/*-*/

fillChk = new JCheckBox("Fill");

fillChk.addItemListener(

new ItemListener()

{

public void itemStateChanged(ItemEvent event)

{

if(fillChk.isSelected())

canvasPanel.setSolidMode(Boolean.TRUE);

else

canvasPanel.setSolidMode(Boolean.FALSE);

}

}

);

/*-*/

this.setLayout(new GridLayout(1,9)); // 8 Buttons & 1 CheckBox

this.add(lineBtn);

this.add(arrowBtn);

this.add(ovalBtn);

this.add(squareBtn);

this.add(roundRectBtn);

this.add(polygonBtn);

this.add(freeHandBtn);

this.add(LStyleBtn);

this.add(dashBtn);

this.add(AStyleBtn);

this.add(shadeBtn);

this.add(clearBtn);

this.add(fillChk);

}

/*-*/

private class ToolButtonListener implements ActionListener

{

public void actionPerformed(ActionEvent event)

{

if(canvasPanel.isExistPolygonBuffer()!= false)

{

canvasPanel.flushPolygonBuffer();

}

if(event.getSource() == lineBtn)

{

canvasPanel.setDrawMode(canvasPanel.LINE);

}

if(event.getSource() == arrowBtn)

{

canvasPanel.setDrawMode(canvasPanel.ARROW);

}

if(event.getSource() == squareBtn)

{

canvasPanel.setDrawMode(canvasPanel.SQUARE);

}

if(event.getSource() == ovalBtn)

{

canvasPanel.setDrawMode(canvasPanel.OVAL);

}

if(event.getSource() == polygonBtn)

{

canvasPanel.setDrawMode(canvasPanel.POLYGON);

}

if(event.getSource() == roundRectBtn)

{

canvasPanel.setDrawMode(canvasPanel.ROUND_RECT);

}

if(event.getSource() == freeHandBtn)

{

canvasPanel.setDrawMode(canvasPanel.FREE_HAND);

}

if(event.getSource() == LStyleBtn)

{

canvasPanel.setDrawMode(canvasPanel.LINE_STYLE);

}

if(event.getSource() == dashBtn)

{

canvasPanel.setDrawMode(canvasPanel.DASH_STYLE);

}

if(event.getSource() == AStyleBtn)

{

canvasPanel.setDrawMode(canvasPanel.ARROW_STYLE);

}

if(event.getSource() == shadeBtn)

{

canvasPanel.setDrawMode(canvasPanel.SHADOW);

}

if(event.getSource() == clearBtn)

{

canvasPanel.clearCanvas();

}

}

}

}

3.ColorButtonPanel.java

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.border.*;

public class ColorButtonPanel extends JPanel

{

private JPanel colorButtonPanel;

private JButton foreGroundColorBtn,backGroundColorBtn;

private JLabel foreGroundColorLbl,backGroundColorLbl,foreColorLbl,backColorLbl;

private Color foreColor, backColor;

private CanvasPanel canvasPanel;

public ColorButtonPanel(CanvasPanel inCanvasPanel)

{

canvasPanel = inCanvasPanel;

foreGroundColorLbl = new JLabel(" ");

foreGroundColorLbl.setOpaque(true);

foreGroundColorLbl.setBackground(canvasPanel.getForeGroundColor());

foreGroundColorLbl.setBorder(BorderFactory.createLineBorder(Color.BLACK));

backGroundColorLbl = new JLabel(" ");

backGroundColorLbl.setOpaque(true);

backGroundColorLbl.setBackground(canvasPanel.getBackGroundColor());

backGroundColorLbl.setBorder(BorderFactory.createLineBorder(Color.WHITE));

foreGroundColorBtn = new JButton("ForeGroundColor->");

foreGroundColorBtn.addActionListener(

new ActionListener()

{

public void actionPerformed(ActionEvent event)

{

setForeGroundColor();

}

}

);

backGroundColorBtn = new JButton("BackGroundColor->");

backGroundColorBtn.addActionListener(

new ActionListener()

{

public void actionPerformed(ActionEvent event)

{

setBackGroundColor();

}

}

);

this.setLayout(new GridLayout(1,4));

this.add(foreGroundColorBtn);

this.add(foreGroundColorLbl);

this.add(backGroundColorBtn);

this.add(backGroundColorLbl);

}

/*-*/

public void setForeGroundColor()

{

foreColor = JColorChooser.showDialog(null,"ForeGround Color",foreColor);

if(foreColor!=null)

{

foreGroundColorLbl.setBackground(foreColor);

canvasPanel.setForeGroundColor(foreColor);

}

}

/*-*/

public void setBackGroundColor()

{

backColor = JColorChooser.showDialog(null,"BackGround Color",backColor);

if(backColor!=null)

{

backGroundColorLbl.setBackground(backColor);

canvasPanel.setBackGroundColor(backColor);

}

}

}

and lasty..

4. CanvasPanel.java

import java.awt.*;

import java.awt.event.*;

import java.awt.image.*;

import java.util.*;

import java.io.*;

import javax.swing.*;

import javax.imageio.*;

public class CanvasPanel extends JPanel implements MouseListener,MouseMotionListener, Serializable

{

protected final static int LINE=1,ARROW=2,SQUARE=3,OVAL=4,POLYGON=5,ROUND_RECT=6,FREE_HAND=7,

LINE_STYLE=8,DASH_STYLE=9,ARROW_STYLE=10,SHADOW=11,

SOLID_SQUARE=22, SOLID_OVAL=33, SOLID_POLYGON=44,

SOLID_ROUND_RECT=55;

protected static Vector vLine,vArrow,vSquare,vOval,vPolygon,vRoundRect,vFreeHand,

vSolidSquare,vSolidOval,vSolidPolygon,vSolidRoundRect,vFile,

xPolygon, yPolygon;

private Color foreGroundColor, backGroundColor;

private int x1,y1,x2,y2,linex1,linex2,liney1,liney2, drawMode=0;

private boolean solidMode, polygonBuffer;

private File fileName;

public CanvasPanel()

{

vLine = new Vector();

vSquare = new Vector();

vOval = new Vector();

vPolygon = new Vector();

vRoundRect = new Vector();

vFreeHand = new Vector();

vSolidSquare = new Vector();

vSolidOval = new Vector();

vSolidPolygon = new Vector();

vSolidRoundRect = new Vector();

vFile = new Vector();

xPolygon = new Vector();

yPolygon = new Vector();

addMouseListener(this);

addMouseMotionListener(this);

solidMode = false;

polygonBuffer = false;

foreGroundColor = Color.BLACK;

backGroundColor = Color.WHITE;

setBackground(backGroundColor);

repaint();

}

/*-*/

public void mousePressed(MouseEvent event)

{

x1 = linex1 = linex2 = event.getX();

y1 = liney1 = liney2 = event.getY();

}

/*-*/

public void mouseClicked(MouseEvent event){}

public void mouseMoved(MouseEvent event){}

/*-*/

public void mouseReleased(MouseEvent event)

{

if (drawMode == LINE)

{

vLine.add(new Coordinate(x1,y1,event.getX(),event.getY(),foreGroundColor));

// undoStack.push(new StepInfo(LINE ,new Coordinate(x1,y1,event.getX(),event.getY(),foreGroundColor)));

}

if (drawMode == SQUARE)

{

if(solidMode)

{

if(x1 > event.getX() || y1 > event.getY())

{

vSolidSquare.add(new Coordinate(event.getX(),event.getY(),x1,y1,foreGroundColor));

// undoStack.push(new StepInfo(SOLID_SQUARE, new Coordinate(event.getX(),event.getY(),x1,y1,foreGroundColor)));

}

else

{

vSolidSquare.add(new Coordinate(x1,y1,event.getX(),event.getY(),foreGroundColor));

// undoStack.push(new StepInfo(SOLID_SQUARE, new Coordinate(x1,y1,event.getX(),event.getY(),foreGroundColor)));

}

}

else

{

if(x1 > event.getX() || y1 > event.getY())

{

vSquare.add(new Coordinate(event.getX(),event.getY(),x1,y1,foreGroundColor));

// undoStack.push(new StepInfo(SQUARE, new Coordinate(event.getX(),event.getY(),x1,y1,foreGroundColor)));

}

else

{

vSquare.add(new Coordinate(x1,y1,event.getX(),event.getY(),foreGroundColor));

// undoStack.push(new StepInfo(SQUARE, new Coordinate(x1,y1,event.getX(),event.getY(),foreGroundColor)));

}

}

}

if (drawMode == this.OVAL)

{

if(solidMode)

{

if(x1 > event.getX() || y1 > event.getY())

{

vSolidOval.add(new Coordinate(event.getX(),event.getY(),x1,y1,foreGroundColor));

// undoStack.push(new StepInfo(SOLID_OVAL, new Coordinate(event.getX(),event.getY(),x1,y1,foreGroundColor)));

}

else

{

vSolidOval.add(new Coordinate(x1,y1,event.getX(),event.getY(),foreGroundColor));

// undoStack.push(new StepInfo(SOLID_OVAL, new Coordinate(x1,y1,event.getX(),event.getY(),foreGroundColor)));

}

}

else

{

if(x1 > event.getX() || y1 > event.getY())

{

vOval.add(new Coordinate(event.getX(),event.getY(),x1,y1,foreGroundColor));

// undoStack.push(new StepInfo(OVAL, new Coordinate(event.getX(),event.getY(),x1,y1,foreGroundColor)));

}

else

{

vOval.add(new Coordinate(x1,y1,event.getX(),event.getY(),foreGroundColor));

// undoStack.push(new StepInfo(OVAL, new Coordinate(x1,y1,event.getX(),event.getY(),foreGroundColor)));

}

}

}

if (drawMode == this.POLYGON || drawMode == this.SOLID_POLYGON)

{

xPolygon.add(new Integer(event.getX()));

yPolygon.add(new Integer(event.getY()));

polygonBuffer = true;

repaint();

}

if (drawMode == this.ROUND_RECT)

{

if(solidMode)

{

if(x1 > event.getX() || y1 > event.getY())

{

vSolidRoundRect.add(new Coordinate(event.getX(),event.getY(),x1,y1,foreGroundColor));

// undoStack.push(new StepInfo(SOLID_ROUND_RECT, new Coordinate(event.getX(),event.getY(),x1,y1,foreGroundColor)));

}

else

{

vSolidRoundRect.add(new Coordinate(x1,y1,event.getX(),event.getY(),foreGroundColor));

// undoStack.push(new StepInfo(SOLID_ROUND_RECT, new Coordinate(x1,y1,event.getX(),event.getY(),foreGroundColor)));

}

}

else

{

if(x1 > event.getX() || y1 > event.getY())

{

vRoundRect.add(new Coordinate(event.getX(),event.getY(),x1,y1,foreGroundColor));

// undoStack.push(new StepInfo(ROUND_RECT, new Coordinate(event.getX(),event.getY(),x1,y1,foreGroundColor)));

}

else

{

vRoundRect.add(new Coordinate(x1,y1,event.getX(),event.getY(),foreGroundColor));

// undoStack.push(new StepInfo(ROUND_RECT, new Coordinate(x1,y1,event.getX(),event.getY(),foreGroundColor)));

}

}

}

x1=linex1=x2=linex2=0;

y1=liney1=y2=liney2=0;

}

/*-*/

public void mouseEntered(MouseEvent event)

{

setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));

}

/*-*/

public void mouseExited(MouseEvent event)

{

setCursor(new Cursor(Cursor.DEFAULT_CURSOR));

}

/*-*/

public void mouseDragged(MouseEvent event)

{

x2 = event.getX();

y2 = event.getY();

if (drawMode == this.FREE_HAND)

{

linex1 = linex2;

liney1 = liney2;

linex2 = x2;

liney2 = y2;

vFreeHand.add(new Coordinate(linex1,liney1,linex2,liney2,foreGroundColor));

}

repaint();

}

/*-*/

public void paintComponent(Graphics g)

{

super.paintComponent(g);

redrawVectorBuffer(g);

g.setColor(foreGroundColor);

if (drawMode == LINE)

{

g.drawLine(x1,y1,x2,y2);

}

if (drawMode == OVAL)

{

if(solidMode)

{

if(x1 > x2 || y1 > y2)

g.fillOval(x2,y2,x1-x2,y1-y2);

else

g.fillOval(x1,y1,x2-x1,y2-y1);

}

else

{

if(x1 > x2 || y1 > y2)

g.drawOval (x2,y2,x1-x2,y1-y2);

else

g.drawOval (x1,y1,x2-x1,y2-y1);

}

}

if (drawMode == ROUND_RECT)

{

if(solidMode)

{

if(x1 > x2 || y1 > y2)

g.fillRoundRect(x2,y2,x1-x2,y1-y2,25,25);

else

g.fillRoundRect(x1,y1,x2-x1,y2-y1,25,25);

}

else

{

if(x1 > x2 || y1 > y2)

g.drawRoundRect(x2,y2,x1-x2,y1-y2,25,25);

else

g.drawRoundRect(x1,y1,x2-x1,y2-y1,25,25);

}

}

if (drawMode == SQUARE)

{

if(solidMode)

{

if(x1 > x2 || y1 > y2)

g.fillRect (x2,y2,x1-x2,y1-y2);

else

g.fillRect (x1,y1,x2-x1,y2-y1);

}

else

{

if(x1 > x2 || y1 > y2)

g.drawRect (x2,y2,x1-x2,y1-y2);

else

g.drawRect (x1,y1,x2-x1,y2-y1);

}

}

if (drawMode == POLYGON || drawMode == SOLID_POLYGON)

{

int xPos[] = new int[xPolygon.size()];

int yPos[] = new int[yPolygon.size()];

for(int count=0;count<xPos.length;count++)

{

xPos[count] = ((Integer)(xPolygon.elementAt(count))).intValue();

yPos[count] = ((Integer)(yPolygon.elementAt(count))).intValue();

}

g.drawPolyline(xPos,yPos,xPos.length);

polygonBuffer = true;

}

if (drawMode == FREE_HAND)

{

g.drawLine(linex1,liney1,linex2,liney2);

}

}

/*-*/

public void setDrawMode(int mode)

{

drawMode = mode;

}

public int getDrawMode()

{

return drawMode;

}

/*-*/

public void setSolidMode(Boolean inSolidMode)

{

solidMode = inSolidMode.booleanValue();

}

public Boolean getSolidMode()

{

return Boolean.valueOf(solidMode);

}

/*-*/

public void setForeGroundColor(Color inputColor)

{

foreGroundColor = inputColor;

}

public Color getForeGroundColor()

{

return foreGroundColor;

}

/*-*/

public void setBackGroundColor(Color inputColor)

{

backGroundColor = inputColor;

this.setBackground(backGroundColor);

}

public Color getBackGroundColor()

{

return backGroundColor;

}

/*-*/

public void clearCanvas()

{

vFreeHand.removeAllElements();

vLine.removeAllElements();

vOval.removeAllElements();

vPolygon.removeAllElements();

vRoundRect.removeAllElements();

vSolidOval.removeAllElements();

vSolidPolygon.removeAllElements();

vSolidRoundRect.removeAllElements();

vSolidSquare.removeAllElements();

vSquare.removeAllElements();

repaint();

}

/*-*/

public boolean isExistPolygonBuffer()

{

return polygonBuffer;

}

/*-*/

public void flushPolygonBuffer()

{

if(!solidMode)

{

vPolygon.add(new Coordinate(xPolygon, yPolygon, foreGroundColor));

}

else

{

vSolidPolygon.add(new Coordinate(xPolygon, yPolygon, foreGroundColor));

}

xPolygon.removeAllElements();

yPolygon.removeAllElements();

polygonBuffer = false;

repaint();

}

/*-*/

private class Coordinate implements Serializable

{

private int x1,y1,x2,y2;

private Color foreColor;

private Vector xPoly, yPoly;

public Coordinate (int inx1,int iny1,int inx2, int iny2, Color color)

{

x1 = inx1;

y1 = iny1;

x2 = inx2;

y2 = iny2;

foreColor = color;

}

public Coordinate(Vector inXPolygon, Vector inYPolygon, Color color)

{

xPoly = (Vector)inXPolygon.clone();

yPoly = (Vector)inYPolygon.clone();

foreColor = color;

}

public Color colour()

{

return foreColor;

}

public int getX1 ()

{

return x1;

}

public int getX2 ()

{

return x2;

}

public int getY1 ()

{

return y1;

}

public int getY2 ()

{

return y2;

}

public Vector getXPolygon()

{

return xPoly;

}

public Vector getYPolygon()

{

return yPoly;

}

}

/*-*/

private class StepInfo implements Serializable

{

private int stepType;

private Coordinate stepCoordinate;

public StepInfo(int inStepType, Coordinate inStepCoordinate)

{

stepType = inStepType;

stepCoordinate = inStepCoordinate;

}

public int getStepType()

{

return stepType;

}

public Coordinate getStepCoordinate()

{

return stepCoordinate;

}

}

/*-*/

private RenderedImage myCreateImage()

{

BufferedImage bufferedImage = new BufferedImage(600,390, BufferedImage.TYPE_INT_RGB);

Graphics g = bufferedImage.createGraphics();

redrawVectorBuffer(g);

g.dispose();

return bufferedImage;

}

/*-*/

private void redrawVectorBuffer(Graphics g)

{

for (int i=0;i<vFreeHand.size();i++){

g.setColor(((Coordinate)vFreeHand.elementAt(i)).colour());

g.drawLine(((Coordinate)vFreeHand.elementAt(i)).getX1(),((Coordinate)vFreeHand.elementAt(i)).getY1(),((Coordinate)vFreeHand.elementAt(i)).getX2(),((Coordinate)vFreeHand.elementAt(i)).getY2());

}

for (int i=0;i<vLine.size();i++){

g.setColor(((Coordinate)vLine.elementAt(i)).colour());

g.drawLine(((Coordinate)vLine.elementAt(i)).getX1(),((Coordinate)vLine.elementAt(i)).getY1(),((Coordinate)vLine.elementAt(i)).getX2(),((Coordinate)vLine.elementAt(i)).getY2());

}

for (int i=0;i<vOval.size();i++){

g.setColor(((Coordinate)vOval.elementAt(i)).colour());

g.drawOval(((Coordinate)vOval.elementAt(i)).getX1(),((Coordinate)vOval.elementAt(i)).getY1(),((Coordinate)vOval.elementAt(i)).getX2()-((Coordinate)vOval.elementAt(i)).getX1(),((Coordinate)vOval.elementAt(i)).getY2()-((Coordinate)vOval.elementAt(i)).getY1());

}

for (int i=0;i<vRoundRect.size();i++){

g.setColor(((Coordinate)vRoundRect.elementAt(i)).colour());

g.drawRoundRect(((Coordinate)vRoundRect.elementAt(i)).getX1(),((Coordinate)vRoundRect.elementAt(i)).getY1(),((Coordinate)vRoundRect.elementAt(i)).getX2()-((Coordinate)vRoundRect.elementAt(i)).getX1(),((Coordinate)vRoundRect.elementAt(i)).getY2()-((Coordinate)vRoundRect.elementAt(i)).getY1(),25,25);

}

for (int i=0;i<vSolidOval.size();i++){

g.setColor(((Coordinate)vSolidOval.elementAt(i)).colour());

g.fillOval(((Coordinate)vSolidOval.elementAt(i)).getX1(),((Coordinate)vSolidOval.elementAt(i)).getY1(),((Coordinate)vSolidOval.elementAt(i)).getX2()-((Coordinate)vSolidOval.elementAt(i)).getX1(),((Coordinate)vSolidOval.elementAt(i)).getY2()-((Coordinate)vSolidOval.elementAt(i)).getY1());

}

for (int i=0;i<vSolidRoundRect.size();i++){

g.setColor(((Coordinate)vSolidRoundRect.elementAt(i)).colour());

g.fillRoundRect(((Coordinate)vSolidRoundRect.elementAt(i)).getX1(),((Coordinate)vSolidRoundRect.elementAt(i)).getY1(),((Coordinate)vSolidRoundRect.elementAt(i)).getX2()-((Coordinate)vSolidRoundRect.elementAt(i)).getX1(),((Coordinate)vSolidRoundRect.elementAt(i)).getY2()-((Coordinate)vSolidRoundRect.elementAt(i)).getY1(),25,25);

}

for (int i=0;i<vSquare.size();i++){

g.setColor(((Coordinate)vSquare.elementAt(i)).colour());

g.drawRect(((Coordinate)vSquare.elementAt(i)).getX1(),((Coordinate)vSquare.elementAt(i)).getY1(),((Coordinate)vSquare.elementAt(i)).getX2()-((Coordinate)vSquare.elementAt(i)).getX1(),((Coordinate)vSquare.elementAt(i)).getY2()-((Coordinate)vSquare.elementAt(i)).getY1());

}

for (int i=0;i<vSolidSquare.size();i++){

g.setColor(((Coordinate)vSolidSquare.elementAt(i)).colour());

g.fillRect(((Coordinate)vSolidSquare.elementAt(i)).getX1(),((Coordinate)vSolidSquare.elementAt(i)).getY1(),((Coordinate)vSolidSquare.elementAt(i)).getX2()-((Coordinate)vSolidSquare.elementAt(i)).getX1(),((Coordinate)vSolidSquare.elementAt(i)).getY2()-((Coordinate)vSolidSquare.elementAt(i)).getY1());

}

for(int i=0;i<vPolygon.size();i++){

int xPos[] = new int[((Coordinate)vPolygon.elementAt(i)).getXPolygon().size()];

int yPos[] = new int[((Coordinate)vPolygon.elementAt(i)).getYPolygon().size()];

for(int count=0;count<xPos.length;count++)

{

xPos[count] = ((Integer)((Coordinate)vPolygon.elementAt(i)).getXPolygon().elementAt(count)).intValue();

yPos[count] = ((Integer)((Coordinate)vPolygon.elementAt(i)).getYPolygon().elementAt(count)).intValue();

}

g.setColor(((Coordinate)vPolygon.elementAt(i)).colour());

g.drawPolygon(xPos,yPos,xPos.length);

}

for(int i=0;i<vSolidPolygon.size();i++){

int xPos[] = new int[((Coordinate)vSolidPolygon.elementAt(i)).getXPolygon().size()];

int yPos[] = new int[((Coordinate)vSolidPolygon.elementAt(i)).getYPolygon().size()];

for(int count=0;count<xPos.length;count++)

{

xPos[count] = ((Integer)((Coordinate)vSolidPolygon.elementAt(i)).getXPolygon().elementAt(count)).intValue();

yPos[count] = ((Integer)((Coordinate)vSolidPolygon.elementAt(i)).getYPolygon().elementAt(count)).intValue();

}

g.setColor(((Coordinate)vSolidPolygon.elementAt(i)).colour());

g.fillPolygon(xPos,yPos,xPos.length);

}

}

}

Pls help me to complete this task..Thanx for all your support..I really appreciate all advice n helps..

thankx in advance.>

cattie79a at 2007-7-14 21:16:23 > top of Java-index,Desktop,Core GUI APIs...
# 5

> Pls help me to complete this task..

write a program that does only this

1.Edit drawn shape fill color and line colors

if you have a problem with it, post the code and the specific problem you have.

when all OK do #2, then #3 etc

when each part is working, build it into the main program

Michael_Dunna at 2007-7-14 21:16:23 > top of Java-index,Desktop,Core GUI APIs...
# 6
Hi..Thanx 4 ur advice..I'll try to do so..I hope u can help me..Thanx ya..
cattie79a at 2007-7-14 21:16:23 > top of Java-index,Desktop,Core GUI APIs...