Original Post
In my Computer Science I class we're working on creating our own Microsoft Paintesque program. We've studied inheritance, composition, basic graphics, mouse events, data types, and arrays. We're also not allowed to use any Swing code. Since I'm pretty hyped about this project, I wanted to get a head start and start off. I've ran into some problems, but this one has been sticking for quite some time. What I want to do, is create a class that I can call that will make a new Rectangle and draw it. What that will do is draw the rectangle where I want to in the color it's called. It will also create a abstract Rectangle behind it, an object, so that I can have interaction with the user clicking on that spot. Here are two related snipets of code: CiPaint.java UI.java When I just compile the FILE CiPaint.java I get this error: But when I compile the PROJECT or just the FILE UI.java I get these errors: CiPaint.java (Full) UI.java Thanks for all your help in advance. If you have any questions, feel free to ask, I should be able to reply within 5-10 minutes. [Edited by - Ueneth Echil on January 20, 2007 3:11:09 PM]
public void init(Graphics g)
{
UI.UI(g,"red",10,10);
/*red = new Rectangle(50,50,100,100);
green = new Rectangle(50,200,100,100);
blue = new Rectangle(50,350,100,100);*/
numColor = 0;
}
import java.awt.*;
public class UI
{
public static void UI(Graphics g, String strColor, int x, int y)
{
g.setcolor(Color.strColor);
Rectangle color = strColor;
color = new Rectangle(x,y,25,25);
}
}
CiPaint.java:15: UI(java.lang.String,int,int) in UI cannot be applied to (java.awt.Graphics,java.lang.String,int,int)
UI.UI(g,"red",10,10);
^
I.java:7: cannot find symbol
symbol : variable strColor
location: class java.awt.Color
g.setcolor(Color.strColor);
^
UI.java:9: incompatible types
found : java.lang.String
required: java.awt.Rectangle
Rectangle color = strColor;
^
// CiPaint
// Version 0.1
// Programmed and Designed by Paul Adamski
import java.awt.*;
import java.applet.*;
public class CiPaint extends Applet
{
//Rectangle red, green, blue, purple, black;
int numColor;
public void init(Graphics g)
{
UI.UI(g,"red",10,10);
/*red = new Rectangle(50,50,100,100);
green = new Rectangle(50,200,100,100);
blue = new Rectangle(50,350,100,100);*/
numColor = 0;
}
public void paint(Graphics g)
{
/* Draws the borders and UI
g.drawLine(200,0,200,600);
g.drawLine(1,1,800,1);
g.drawLine(800,1,800,600);
g.drawLine(800,600,1,600);
g.drawLine(1,600,1,1);
g.setColor(Color.red);
g.fillRect(10,10,25,25);
g.setColor(Color.green)
g.fillRect(10)*/
/*switch (numColor)
{
case 1:
g.setColor(Color.red);
g.drawString("Mouse clicked inside red", 200,75);
break;
case 2:
g.setColor(Color.green);
g.drawString("Mouse clicked inside green", 200,225);
break;
case 3:
g.setColor(Color.blue);
g.drawString("Mouse clicked inside blue", 200,375);
break;
case 4:
g.setColor(Color.black);
g.drawString("Mouse is clicked outside the colored squares", 50,20);
break;
}*/
}
public boolean mouseDown(Event e, int x, int y)
{
/*if(red.inside(x,y))
numColor = 1;
else if(green.inside(x,y))
numColor = 2;
else if(blue.inside(x,y))
numColor = 3;
else
numColor = 4;
repaint();*/
return true;
}
}
import java.awt.*;
public class UI
{
public static void UI(Graphics g, String strColor, int x, int y)
{
g.setcolor(Color.strColor);
Rectangle color = strColor;
color = new Rectangle(x,y,25,25);
}
}