currently making painting program in java mouse click. photoshop or painting application in microsoft. know easy paint square shape, setting boundaries x , y axis. how can make method of painting complicated shape countries in map of africa mouse click? there way set boundaries this? can give me hint? thank you! map of africa example
painting possible java graphics
. try following simple code.
public class paintcanves extends jpanel { private int oldx; private int oldy; public paintcanves() { draw(); } private void draw() { addmouselistener(new mouseadapter() { @override public void mousepressed(mouseevent e) { oldx = e.getx(); oldy = e.gety(); } }); addmousemotionlistener(new mousemotionadapter() { @override public void mousedragged(mouseevent e) { getgraphics().drawline(oldx, oldy, e.getx(), e.gety()); oldx = e.getx(); oldy = e.gety(); } }); } public static void main(string[] args) { jframe frame = new jframe(); frame.setcontentpane(new paintcanves()); frame.setdefaultcloseoperation(jframe.exit_on_close); frame.setsize(500, 500); frame.setvisible(true); } }
this testing result.
note:
it clears drawn data when calling repaint()
panel. it's need keep painting points safe using technique such adding painting points collection
or something.
Comments
Post a Comment