RPBLEA
11-09-2004, 05:00 PM
Okay I'm stumped, I can't figure out how to draw Lines? When I click on one of the poylgons I want to get the Color Of the POlygon, Then I want to be able to draw a line with that Color on the Canvas. I've been stuck for 3 days, Can't figure it out, ANy Help appreciated, thank you.
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.awt.Color;
public class polygon extends Canvas implements MouseListener {
private int [] s = {25,50,75};
private int [] t = {50,25,50};
private int [] ss = {100, 125, 150};
private int [] tt = {50, 25, 50};
private int [] sss = {175, 200, 225};
private int [] ttt = {50, 25, 50};
private Polygon p = new Polygon(s,t,3);
private Polygon q = new Polygon(ss,tt,3);
private Polygon r = new Polygon(sss,ttt,3);
private Button save = new Button();
private Button open = new Button();
private int x;
private int y;
private int oldx;
private int oldy;
private Color c;
public static void main(String [] args) {
polygon polygon = new polygon();
}
public polygon() {
Frame theframe = new Frame();
theframe.setSize(500, 500);
theframe.add(this,BorderLayout.CENTER);
theframe.setVisible(true);
addMouseListener(this);
}
public void drawLine(Graphics g, Color c){
g.drawLine(oldx, oldy,10,10);
}
public void paint (Graphics g) {
g.setColor(Color.blue);
g.fillPolygon(p);
g.setColor(Color.RED);
g.fillPolygon(q);
g.setColor(Color.GREEN);
g.fillPolygon(r);
drawLine(g,c);
}
public void mousePressed(MouseEvent e){
x = e.getX();
y = e.getY();
oldx = x;
oldy = y;
}
public void mouseReleased(MouseEvent e){
x = e.getX();
y = e.getY();
}
public void mouseClicked(MouseEvent e) {
if (p.contains(e.getX(),e.getY())) {
c = Color.blue;
repaint();
}
if (q.contains(e.getX(),e.getY())){
c = Color.red;
repaint();
}
if (r.contains(e.getX(),e.getY())){
c = Color.green;
repaint();
}
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
}
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.awt.Color;
public class polygon extends Canvas implements MouseListener {
private int [] s = {25,50,75};
private int [] t = {50,25,50};
private int [] ss = {100, 125, 150};
private int [] tt = {50, 25, 50};
private int [] sss = {175, 200, 225};
private int [] ttt = {50, 25, 50};
private Polygon p = new Polygon(s,t,3);
private Polygon q = new Polygon(ss,tt,3);
private Polygon r = new Polygon(sss,ttt,3);
private Button save = new Button();
private Button open = new Button();
private int x;
private int y;
private int oldx;
private int oldy;
private Color c;
public static void main(String [] args) {
polygon polygon = new polygon();
}
public polygon() {
Frame theframe = new Frame();
theframe.setSize(500, 500);
theframe.add(this,BorderLayout.CENTER);
theframe.setVisible(true);
addMouseListener(this);
}
public void drawLine(Graphics g, Color c){
g.drawLine(oldx, oldy,10,10);
}
public void paint (Graphics g) {
g.setColor(Color.blue);
g.fillPolygon(p);
g.setColor(Color.RED);
g.fillPolygon(q);
g.setColor(Color.GREEN);
g.fillPolygon(r);
drawLine(g,c);
}
public void mousePressed(MouseEvent e){
x = e.getX();
y = e.getY();
oldx = x;
oldy = y;
}
public void mouseReleased(MouseEvent e){
x = e.getX();
y = e.getY();
}
public void mouseClicked(MouseEvent e) {
if (p.contains(e.getX(),e.getY())) {
c = Color.blue;
repaint();
}
if (q.contains(e.getX(),e.getY())){
c = Color.red;
repaint();
}
if (r.contains(e.getX(),e.getY())){
c = Color.green;
repaint();
}
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
}