java - transfer drawn content from one jcomponent to onther -
i have java programme 2 textareas , button. want allow user write 1 1 textarea using touch pen or mouse , when he/she clicks button, drawn content should send textarea no 2.
so textarea user writing on, gave mousemotion listener paintcomponent method in it. when run application, have realized texarea method gettext()
, settext()
can't set or drawn content.
is there way can accomplish above task? have tried jpanel
doesn't have setcontent()
method.
i appreciate help.
this first textarea user writing on touchpen.
public class area1 extends jtextarea { int pointcount = 0; point[] points = new point[10000]; public area1() { addmousemotionlistener(new mousemotionadapter() { @override public void mousedragged(mouseevent event) { if (pointcount < points.length) { points[pointcount] = event.getpoint(); ++pointcount; repaint(); } } }); } @override public void paintcomponent(graphics g) { super.paintcomponent(g); (int = 0; < pointcount; i++) { g.filloval(points[i].x, points[i].y, 4, 4); } } }
this overall application textarea2 , button
public class handwriting extends jframe { private jtextarea area2; private jbutton b1; area1 area1; public handwriting() { box box = box.createhorizontalbox(); area1 = new area1(); area1.setrows(30); area1.setcolumns(30); area2 = new jtextarea(30, 30); b1 = new jbutton("copy"); b1.addactionlistener(new actionlistener() { @override public void actionperformed(actionevent event) { if (event.getsource() == b1) { area2.settext(area1.gettext()); } } }); box.add(area1); box.add(b1); box.add(area2); add(box); } public static void main(string[] args) { handwriting hand = new handwriting(); hand.setdefaultcloseoperation(jframe.exit_on_close); hand.setsize(500, 500); hand.setvisible(true); } }
one possible solution create 1 class inner class of other , way private instance fields can accessed
java swing user-interface
No comments:
Post a Comment