hello
i am working on a simple panting project
that allow the user to select a shap from ComboBox
then draw it on the panel
but problem is when is choose any type of shapes and drawing it on panel
no shape appear on the panel ?!
here is my panel class
package painter;
import java.awt.Color;
import javax.swing.JPanel;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Shapes extends JPanel{
private MyLine [] lines=new MyLine[100];
private MyRectangle [] recs;
private MyOval [] ovals;
int ShapeType=0;
int LC=0;// conter for number of lines
int RC=0;// conter for number of rectable
int OC=0;// conter for number of ovals
int x1;
int y1;
int x2;
int y2;
Shapes() {
Color c=Color.BLUE;
this.setBackground(Color.WHITE);
this.setBounds(0,100, 300, 300);
MouseHandler handler=new MouseHandler();
this.addMouseListener(handler);
this.addMouseMotionListener(handler);
}
public int getShapeType() {
return ShapeType;
}
public void setShapeType(int ShapeType) {
this.ShapeType = ShapeType;
}
private class MouseHandler extends MouseAdapter implements MouseMotionListener {
@Override
public void mouseClicked(MouseEvent e) {
//throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void mousePressed(MouseEvent e) {
x1=e.getX();
y1=e.getX();
System.out.println(x1+" "+x2);
}
@Override
public void mouseReleased(MouseEvent e) {
x2=e.getX();
y2=e.getX();
lines[LC]=new MyLine(x1,y1,x2,y2);
LC++;
System.out.println(x1+" "+x2);
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mouseDragged(MouseEvent e){
}
}
@Override
public void paintComponent(Graphics g){
super.paintComponent(g);
g.setColor(Color.red);
if (ShapeType==0)
{
for(int i=0;i<LC;i++)
{
lines[i].draw(g);
}
}
if (ShapeType==1)
{
for(int i=0;i<LC;i++)
{
lines[i].draw(g);
}
}
if (ShapeType==1)
{
for(int i=0;i<LC;i++)
{
lines[i].draw(g);
}
}
}
}
Line Class ......
package painter;
import java.awt.Graphics;
import java.awt.Color;
public class MyLine extends MyShape{
MyLine(int x1,int y1 ,int x2,int y2){
this.x1=x1;
this.x2=x2;
this.y1=y1;
this.y2=y2;
this.c = c;
}
@Override
public void draw(Graphics g) {
g.setColor(Color.RED);
g.drawLine(500, 200, 300, 400);
}
}