java - Drawing program: Keep getting errors and I can't figure out why -
i having trouble figuring out wrong code can give me pointers? error message getting : error:(122, 74) java: incompatible types: java.awt.point cannot converted double error:(119, 74) java: incompatible types: java.awt.point cannot converted double error:(112, 23) java: cannot find symbol symbol: method draw(java.awt.graphics) location: variable drawcircle of type javafx.scene.shape.circle
import javafx.scene.shape.circle; import javax.swing.*; import java.awt.*; import java.awt.event.actionevent; import java.awt.event.actionlistener; import java.awt.event.mouseevent; import java.awt.event.mousemotionlistener; import java.util.arraylist; import java.util.iterator; /** * michael vanklompenberg * date: 11/5/2016. * cis 117 java programming 1 * description: */ public class drawingprogram { public static void main(string[] args) { drawingframe f = new drawingframe(); f.settitle("drawing program"); f.setsize(462, 312); f.setlocationrelativeto(null); f.setdefaultcloseoperation(jframe.exit_on_close); f.setvisible(true); } } class circle { private int size; private point point; private color color; public circle(int size, point point, color color) { this.size = size; this.point = point; this.color = color; } public int getsize() { return size; } public void setsize(int size) { this.size = size; } public point getpoint() { return point; } public void setpoint(point point) { this.point = point; } public color getcolor() { return color; } public void setcolor(color color) { this.color = color; } public void draw(graphics g){ g.setcolor(color); g.filloval(getpoint().x,getpoint().y, size,size); } } class drawingpanel extends jpanel implements mousemotionlistener { private int circlediameter; private color circlecolor; private circle drawingcircle; private arraylist<circle> circlearraylist = new arraylist<circle>(); public int getcirclediameter() { return circlediameter; } public void setcirclediameter(int circlediameter) { this.circlediameter = circlediameter; } public color getcirclecolor() { return circlecolor; } public void setcirclecolor(color circlecolor) { this.circlecolor = circlecolor; } public circle getdrawingcircle() { return drawingcircle; } public void setdrawingcircle(circle drawingcircle) { this.drawingcircle = drawingcircle; } public drawingpanel(int circlediameter, color circlecolor) { this.circlediameter = circlediameter; this.circlecolor = circlecolor; addmousemotionlistener(this); } public void paintcomponent(graphics g) { super.paintcomponent(g); iterator<circle> circleiterator = circlearraylist.iterator(); circle drawcircle; while(circleiterator.hasnext()) { drawcircle = (circle) circleiterator.next(); drawcircle.draw(g); } } @override public void mousedragged(mouseevent e) { if (e.ismetadown()) { circle newcircle = new circle(getcirclediameter(), e.getpoint(), this.getbackground()); circlearraylist.add(newcircle); }else { circle newcircle = new circle(getcirclediameter(), e.getpoint(), getcirclecolor()); circlearraylist.add(newcircle); } repaint(); } @override public void mousemoved(mouseevent e) { } } class drawingframe extends jframe implements actionlistener { private drawingpanel drawpanel; private final int small =4; private final int medium =8; private final int large =10; //main menu bar private jmenubar mainbar = new jmenubar(); private jmenu file = new jmenu("file"); private jmenu menusize = new jmenu("size"); private jmenu menucolor = new jmenu("color"); private jmenu = new jmenu("help"); //button groups color , size radio buttons private buttongroup size = new buttongroup(); private buttongroup color = new buttongroup(); //sub menu items private jmenuitem clear = new jmenuitem("clear"); private jmenuitem exit = new jmenuitem("exit"); // size radio buttons private jradiobuttonmenuitem small = new jradiobuttonmenuitem("small"); private jradiobuttonmenuitem medium = new jradiobuttonmenuitem("medium"); private jradiobuttonmenuitem large = new jradiobuttonmenuitem("large"); private jmenuitem = new jmenuitem("about"); //color radio buttons private jradiobuttonmenuitem red = new jradiobuttonmenuitem("red"); private jradiobuttonmenuitem blue = new jradiobuttonmenuitem("blue"); private jradiobuttonmenuitem green = new jradiobuttonmenuitem("green"); private jradiobuttonmenuitem yellow = new jradiobuttonmenuitem("yellow"); private jradiobuttonmenuitem orange = new jradiobuttonmenuitem("orange"); public drawingframe() { drawpanel = new drawingpanel(small,color.red); drawpanel.setbackground(color.white); //actionlistners menu items clicked on file.addactionlistener(this); menusize.addactionlistener(this); menucolor.addactionlistener(this); help.addactionlistener(this); //add buttons , menu items groups/location setjmenubar(mainbar); mainbar.add(file); mainbar.add(menusize); mainbar.add(menucolor); mainbar.add(help); file.add(clear); file.add(exit); size.add(small); size.add(medium); size.add(large); color.add(red); color.add(blue); color.add(green); color.add(yellow); color.add(orange); // add mnemonics file.setmnemonic('f'); menusize.setmnemonic('z'); menucolor.setmnemonic('o'); help.setmnemonic('h'); clear.setmnemonic('c'); exit.setmnemonic('x'); } @override public void actionperformed(actionevent e) { if(small.isselected()) drawpanel.setcirclediameter(small); if(medium.isselected()) drawpanel.setcirclediameter(medium); if(large.isselected()) drawpanel.setcirclediameter(large); if (red.isselected()) drawpanel.setcirclecolor(color.red); if (blue.isselected()) drawpanel.setcirclecolor(color.blue); if (green.isselected()) drawpanel.setcirclecolor(color.green); if (yellow.isselected()) drawpanel.setcirclecolor(color.yellow); if (orange.isselected()) drawpanel.setcirclecolor(color.orange); string arg = e.getactioncommand(); if (arg.equals("exit")) { system.exit(0); } if (arg.equals("clear")){ drawpanel = new drawingpanel(small,color.red); } if (arg.equals("about")) { joptionpane.showmessagedialog(null, "drawing program, version 1.0\n"+ "by michael vanklompenberg\nnovember 9, 2016"); } } }
circle has no constructor takes point. x y point before passing circle.
creating instance here
circle newcircle = new circle(getcirclediameter(), e.getpoint(), getcirclecolor());
but circle class has lowercase c.
Comments
Post a Comment