java - Set JTextArea from a JTextField in a different class -
i have till application, takes prices , product name db , totals prices in jtextfield in gui. when click pay, im trying take totaled price , put in class in jtextarea within frame. can't seem work. i've been using settext() , gettext() try , make work , have wrote getter gets total. ive tried far in code below.
// method 1 of jbuttons on gui // adds total , sets in jtextfield called totaltf
americanosmall.addactionlistener( new actionlistener() { public void actionperformed(actionevent e) { try { string query = "select productname, price product productid = 24"; java.sql.preparedstatement pst = connection.preparestatement(query); resultset rs = pst.executequery(); // loop through resultset , transfer in model java.sql.resultsetmetadata rsmd = rs.getmetadata(); int colno = rsmd.getcolumncount(); while(rs.next()){ object[] objects = new object[colno]; for(int i=0;i<colno;i++){ objects[i]=rs.getobject(i+1); } defaulttablemodel model = (defaulttablemodel)table.getmodel(); model.addrow(objects); stock s = new stock(); // deduct stock db //s1.deductstock(24); total = total + s.getitemprice(24); totaltf.settext(string.valueof(total)); totaltf.settext(string.format("%.2f", total)); } tablemodel model = (defaulttablemodel)table.getmodel(); table.setmodel(model); } catch (exception e1) { e1.printstacktrace(); } } }); // calculate class im trying set total gui till class // im trying set total totaltextpane can work out change give customer based on amount of money tendered customer. package classes; import java.awt.*; import javax.swing.border.*; import javax.swing.text.caret; import java.awt.event.*; import javax.swing.*; public class calculate extends jframe { private jpanel contentpane; private double total; private double change; private double amounttendered; /** * launch application. */ public static void main(string[] args) { eventqueue.invokelater(new runnable() { public void run() { try { calculate frame = new calculate(); frame.setvisible(true); } catch (exception e) { e.printstacktrace(); } } }); } /** * create frame. */ public calculate() { settitle("payment"); setdefaultcloseoperation(jframe.exit_on_close); setbounds(100, 100, 450, 591); contentpane = new jpanel(); contentpane.setborder(new emptyborder(5, 5, 5, 5)); setcontentpane(contentpane); contentpane.setlayout(null); jlabel lbltotal = new jlabel("total"); lbltotal.sethorizontalalignment(swingconstants.center); lbltotal.setfont(new font("tahoma", font.plain, 15)); lbltotal.setbounds(26, 39, 141, 31); contentpane.add(lbltotal); jlabel lblamounttendered = new jlabel("amount tendered"); lblamounttendered.sethorizontalalignment(swingconstants.center); lblamounttendered.setfont(new font("tahoma", font.plain, 15)); lblamounttendered.setbounds(26, 111, 141, 31); contentpane.add(lblamounttendered); jlabel lblchange = new jlabel("change"); lblchange.sethorizontalalignment(swingconstants.center); lblchange.setfont(new font("tahoma", font.plain, 15)); lblchange.setbounds(26, 177, 141, 31); contentpane.add(lblchange); jtextpane totaltextpane = new jtextpane(); totaltextpane.setbounds(197, 39, 173, 45); contentpane.add(totaltextpane); jtextpane tenderedtextpane = new jtextpane(); tenderedtextpane.setbounds(197, 111, 173, 45); contentpane.add(tenderedtextpane); jtextpane changetextpane = new jtextpane(); changetextpane.setbounds(197, 177, 173, 45); contentpane.add(changetextpane); jpanel panel = new jpanel(); panel.setbounds(26, 233, 383, 308); contentpane.add(panel); panel.setlayout(null); jbutton jbt1 = new jbutton("1"); jbt1.setbounds(10, 11, 110, 51); panel.add(jbt1); jbutton jbt2 = new jbutton("2"); jbt2.setbounds(130, 11, 110, 51); panel.add(jbt2); jbutton jbt3 = new jbutton("3"); jbt3.setbounds(250, 11, 110, 51); panel.add(jbt3); jbutton jbt4 = new jbutton("4"); jbt4.setbounds(10, 73, 110, 51); panel.add(jbt4); jbutton jbt5 = new jbutton("5"); jbt5.setbounds(130, 73, 110, 51); panel.add(jbt5); jbutton jbt6 = new jbutton("6"); jbt6.setbounds(250, 73, 110, 51); panel.add(jbt6); jbutton jbt7 = new jbutton("7"); jbt7.setbounds(10, 135, 110, 51); panel.add(jbt7); jbutton jbt8 = new jbutton("8"); jbt8.setbounds(130, 135, 110, 51); panel.add(jbt8); jbutton jbt9 = new jbutton("9"); jbt9.setbounds(250, 135, 110, 51); panel.add(jbt9); jbutton jbtdel = new jbutton("del"); jbtdel.setfont(new font("tahoma", font.plain, 15)); jbtdel.setbounds(10, 197, 110, 51); panel.add(jbtdel); jbutton jbt0 = new jbutton("0"); jbt0.setbounds(130, 197, 110, 51); panel.add(jbt0); jbutton jbtpay = new jbutton("pay"); jbtpay.setfont(new font("tahoma", font.plain, 15)); jbtpay.setbounds(250, 197, 110, 51); panel.add(jbtpay); jbutton jbtdecpoint = new jbutton("."); jbtdecpoint.setbounds(130, 259, 110, 46); panel.add(jbtdecpoint); font font = new font("tahoma", font.plain, 20); tenderedtextpane.setfont(font); // listeners calculate gui tendered tp jbt1.addactionlistener( new actionlistener() { public void actionperformed(actionevent e) { if(e.getsource() == jbt1) { tenderedtextpane.settext(tenderedtextpane.gettext() + "1"); } } }); jbt2.addactionlistener( new actionlistener() { public void actionperformed(actionevent e) { if(e.getsource() == jbt2) { tenderedtextpane.settext(tenderedtextpane.gettext() + "2"); } } }); jbt3.addactionlistener( new actionlistener() { public void actionperformed(actionevent e) { if(e.getsource() == jbt3) { tenderedtextpane.settext(tenderedtextpane.gettext() + "3"); } } }); jbt4.addactionlistener( new actionlistener() { public void actionperformed(actionevent e) { if(e.getsource() == jbt4) { tenderedtextpane.settext(tenderedtextpane.gettext() + "4"); } } }); jbt5.addactionlistener( new actionlistener() { public void actionperformed(actionevent e) { if(e.getsource() == jbt5) { tenderedtextpane.settext(tenderedtextpane.gettext() + "5"); } } }); jbt6.addactionlistener( new actionlistener() { public void actionperformed(actionevent e) { if(e.getsource() == jbt6) { tenderedtextpane.settext(tenderedtextpane.gettext() + "6"); } } }); jbt7.addactionlistener( new actionlistener() { public void actionperformed(actionevent e) { if(e.getsource() == jbt7) { tenderedtextpane.settext(tenderedtextpane.gettext() + "7"); } } }); jbt8.addactionlistener( new actionlistener() { public void actionperformed(actionevent e) { if(e.getsource() == jbt8) { tenderedtextpane.settext(tenderedtextpane.gettext() + "8"); } } }); jbt9.addactionlistener( new actionlistener() { public void actionperformed(actionevent e) { if(e.getsource() == jbt9) { tenderedtextpane.settext(tenderedtextpane.gettext() + "9"); } } }); jbt0.addactionlistener( new actionlistener() { public void actionperformed(actionevent e) { if(e.getsource() == jbt0) { tenderedtextpane.settext(tenderedtextpane.gettext() + "0"); } } }); jbtdecpoint.addactionlistener( new actionlistener() { public void actionperformed(actionevent e) { if(e.getsource() == jbtdecpoint) { tenderedtextpane.settext(tenderedtextpane.gettext() + "."); } } }); jbtdel.addactionlistener( new actionlistener() { public void actionperformed(actionevent e) { if (e.getsource() == jbtdel) { tenderedtextpane.settext(""); } } }); // total till should in totaltextpane when frame opens // want take total gui class @ point , work out change. totaltextpane.settext(double.tostring(gettotal())); jbtpay.addactionlistener( new actionlistener() { public void actionperformed(actionevent e) { if(e.getsource() == jbtpay) { component frame = null; joptionpane.showmessagedialog(frame, "order complete!"); } } }); } }// end class
Comments
Post a Comment