SUP FORUM. I'm working on a paint program for a school project. Atm I have working buttons to set three colors and three sizes. There will be more but those are there just for testing purposes. I'm currently working on how to add more tools other than this "draw" tool. I don't have any knowledge on how to use JPanel or buttons etc. Tell me what you think! Note : The Expo class is a class that was given to simplify graphic methods. The methods do the same as the normal java graphics functions would as the names imply. I included it as a text file. Code: import java.applet.Applet; import java.awt.*; public class FinalProject extends java.applet.Applet { Rectangle red, green, blue, size1, size2, size3, brushTool, squareTool, circleTool, clear; boolean singleClick; boolean firstPaint; String Tool; String Color; String Size; int numColor; int size = 10; int tool; int xCoord; int yCoord; int xCoord2; int yCoord2; public void init() { firstPaint = true; } public void paint(Graphics g) { erase(g,0,0,3000,105); erase(g,0,0,80,3000); //Erases Interface each Paint. drawInterface(g); //Draws the Interface. switch(numColor) { case 1: Expo.setColor(g,Expo.red); Color = "red"; break; case 2: Expo.setColor(g,Expo.green); Color = "green"; break; case 3: Expo.setColor(g,Expo.blue); Color = "blue"; break; } switch(size) { case 1: size = 10; Size = "10"; break; case 2: size = 15; Size = "15"; break; case 3: size = 30; Size = "30"; break; } switch(tool) { case 1: if(xCoord2 >= 110 && yCoord2 >= 140) { Expo.fillCircle(g,xCoord2,yCoord2,size); Tool = "Brush"; break; } case 2: if(xCoord >= 110 && yCoord >= 140 && xCoord2 >= 110 && yCoord2 >= 140) { Expo.fillRectangle(g,xCoord,yCoord,xCoord2,yCoord2); Tool = "Square"; break; } case 3: if(xCoord >= 110 && yCoord >= 140 && xCoord2 >= 110 && yCoord2 >= 140) { Expo.fillCircle(g,xCoord,yCoord,xCoord2-xCoord); Tool = "Circle"; break; } } //Expo.fillCircle(g,xCoord2,yCoord2,size); } public void drawInterface(Graphics g) { red = new Rectangle(25,50,75,100); blue = new Rectangle(175,50,225,100); green = new Rectangle(100,50,150,100); size1 = new Rectangle(250,50,260,60); size2 = new Rectangle(280,50,300,70); size3 = new Rectangle(330,50,360,80); brushTool = new Rectangle(25,150,75,200); squareTool = new Rectangle(25,225,75,275); circleTool = new Rectangle(25,300,75,350); clear = new Rectangle(25,375,75,425); Expo.setColor(g,Expo.red); Expo.fillRectangle(g,25,50,75,100); Expo.setColor(g,Expo.green); Expo.fillRectangle(g,100,50,150,100); Expo.setColor(g,Expo.blue); Expo.fillRectangle(g,175,50,225,100); Expo.setColor(g,Expo.black); Expo.fillRectangle(g,250,50,260,60); Expo.fillRectangle(g,280,50,300,70); Expo.fillRectangle(g,330,50,360,80); Expo.drawLine(g,80,105,3000,105); Expo.drawLine(g,80,105,80,3000); Expo.drawRectangle(g,25,150,75,200); Expo.drawString(g,"Brush",35,180); Expo.drawRectangle(g,25,225,75,275); Expo.drawString(g,"Square",30,255); Expo.drawRectangle(g,25,300,75,350); Expo.drawString(g,"Circle",35,330); Expo.drawRectangle(g,25,375,75,425); Expo.drawString(g,"Clear",35,405); Expo.drawString(g,"Color = " + Color,25,25); Expo.drawString(g,"Size = " + Size, 250,25); } public void erase(Graphics g, int x, int y, int x2, int y2) { Expo.setColor(g,Expo.white); Expo.fillRectangle(g,x,y,x2,y2); } public boolean mouseDown(Event e, int x, int y) { xCoord = x; yCoord = y; if(red.inside(x,y)) { numColor = 1; Color = "red"; } if(green.inside(x,y)) { numColor = 2; Color = "green"; } if(blue.inside(x,y)) { numColor = 3; Color = "blue"; } if(size1.inside(x,y)) { size = 1; } if(size2.inside(x,y)) { size = 2; } if(size3.inside(x,y)) { size = 3; } if(brushTool.inside(x,y)) { tool = 1; } if(squareTool.inside(x,y)) { tool = 2; } if(circleTool.inside(x,y)) { tool = 3; } return true; } public boolean mouseDrag(Event e, int x, int y) { xCoord2 = x; yCoord2 = y; repaint(); return true; } public void update(Graphics g) { paint(g); } }
Thanks, didn't know about the site. Ill try searching for something similar to mine that doesn't use JPanel.
I mean you're asking for feedback but on what I've just spent the last 8 weeks working on a Java project and animated a bunch of JPanels but I really don't know what you want said about this stop liking my posts thank you
I was asking how to implement different tools by using the buttons I made with the buttons made in the paint applet. But I fixed it by using another switch case.