java - How to separate several inputs on a jtextfield -
i doing wage calculator calculate worker's salary according position boss, commission worker , such need take 5 inputs each textfield first name, lastly name, , salary. how seperate each inputs each textfields?
example : first name: boss, boss, boss, boss, boss lastly name: a, b, c, d, e salary: 1, 2, 3, 4, 5
output: boss earned 1 boss b earned 2 boss c earned 3 boss d earned 4 boss e earned 5
here's part of code, can print 1 input
public void actionperformed(actionevent e) { //boss if (e.getsource() == fldsalary) { string first = fldfirst.gettext(); string lastly = fldlast.gettext(); double salary = double.parsedouble(fldsalary.gettext()); boss boss = new boss(first,last,salary); employee = boss; output = employee.tostring() + " earned php" + precision2.format(employee.earnings()) + "\n \n" ; area.append(output); } }
use split function
string last= fldlast.gettext(); // last=" a, b, c, d, e"; string[] parts = last.split(", "); string part1 = parts[0]; // string part2 = parts[1]; // b string part3 = parts[2]; // c string part4 = parts[3]; // d string part5 = parts[4]; // e
same first
, salary
(salary should string, parse each 1 double)
java
No comments:
Post a Comment