Thursday, 15 July 2010

java - Creating a line graph with user input -



java - Creating a line graph with user input -

so having problem starting create line graph takes in values given user. have code have far (currently computes rate of growth part of assignment). need take values user inputs (bv1, ev_1, ev_2, ev_3, ev_4, , ev_5...), , utilize them plot points on line graph has amount of money on y-axis, , year on x-axis. labels of graph supposed utilize html formatting in java labels axes. know supposed utilize stuff superpaint g, , @override, not sure start (some illustration code help). help appreciated assignment due tomorrow!

import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.awt.basicstroke; import java.awt.color; import java.awt.dimension; import java.awt.graphics; import java.awt.graphics2d; import java.awt.point; import java.awt.renderinghints; import java.awt.stroke; import java.util.arraylist; import java.util.list; public class rate_graph1 extends japplet implements actionlistener { double e, b, n; jlabel ratetitle, firstbv, ev1, ev2, ev3, ev4, ev5, returnrate; jtextfield bv1, ev_1, ev_2, ev_3, ev_4, ev_5, usersrate; jbutton calc; public void settop() { ratetitle = new jlabel("calculate homecoming rate!", jlabel.center); add(ratetitle, borderlayout.north); } public void setmiddle() { firstbv = new jlabel("enter origin value:"); bv1 = new jtextfield("", 15); ev1 = new jlabel("enter value after first year:"); ev_1 = new jtextfield("", 15); ev2 = new jlabel("enter value after sec year:"); ev_2 = new jtextfield("", 15); ev3 = new jlabel("enter value after 3rd year:"); ev_3 = new jtextfield("", 15); ev4 = new jlabel("enter value after 4th year:"); ev_4 = new jtextfield("", 15); ev5 = new jlabel("enter value after fifth, , final year:"); ev_5 = new jtextfield("", 15); jpanel pane1 = new jpanel(new flowlayout()); pane1.add(firstbv); pane1.add(bv1); pane1.add(ev1); pane1.add(ev_1); pane1.add(ev2); pane1.add(ev_2); pane1.add(ev3); pane1.add(ev_3); pane1.add(ev4); pane1.add(ev_4); pane1.add(ev5); pane1.add(ev_5); jpanel mainpane = new jpanel(new gridlayout(3, 1)); mainpane.add(pane1); add(mainpane, borderlayout.center); } public void setbottom() { returnrate = new jlabel("your homecoming rate is:"); usersrate = new jtextfield("", 15); calc = new jbutton("calculate rate!"); calc.addactionlistener(this); jpanel pane4 = new jpanel(new flowlayout()); pane4.add(returnrate); pane4.add(usersrate); pane4.add(calc); add(pane4, borderlayout.south); } public void init() { setlayout(new borderlayout()); settop(); setmiddle(); setbottom(); } public void actionperformed(actionevent event) { if (event.getsource() == calc){ e = double.parsedouble(ev_5.gettext()); b = double.parsedouble(bv1.gettext()); double rate = math.pow(e / b, 1.0 / 5.0) - 1; usersrate.settext(+ rate * 100 + "%"); } } }

java methods graph line bluej

No comments:

Post a Comment