Hy guys!
I need a little assist on this because I cant really figure it out what I'm doing wrong. I'm working on an envelope writing program. The program have 4 JTextField.
Name, City, Addres, Postal Code. I use keylistener on Name JTextField to recognize the Enter button, and add a new Name JTextField. (Basicly, it sets the 2nd Name JTextField Visible). So total you could have 4 Name JTextField and the others (city, address, postal code) total 7. Also has print jbutton, jtable for viewing already written envelopes waiting for printing so on. When I use g.drawString() I use a predefined x,y value which are changing dynamicly according to the Names field's text length measured by Font Metrics' StringWidth() method and calculating with the right side margin value.. whatever. My Main problem is here:
if (name.length() > address.length()) {
g.drawString(name,
(250 - nameCord_X) + 46, 214); //this is working
g.drawString(city, (250 - nameCord_X) + 46, 226);
g.drawString(address, (250 - nameCord_X) + 46, 238);
g.drawString(postal, (250 - nameCord_X + 46, 250);
} else {
if (address.length() > name.length()
&& name2.isEmpty())
{ // this is working
g.drawString(name, (250 - addressCord_X) + 46, 214);
g.drawString(city, (250 - addressCord_X) + 46, 226);
g.drawString(address, (250 - addressCord_X) + 46, 238);
g.drawString(postal, (250 - addressCord_X + 46, 250);
}
}
if (name2.length() > name.length()
&& name2.length() > address.length()
&& name2.isVisible())
{// this is working
g.drawString(name, (250 - name2Cord_X) + 46, 202);
g.drawString(name2, (250 - name2Cord_X) + 46, 214);
g.drawString(city, (250 - name2Cord_X) + 46, 226);
g.drawString(address, (250 - name2Cord_X) + 46, 238);
g.drawString(postal, (250 - name2Cord_X) + 46, 250);
}
//This is the part that doesnt working. it prints out 5 lines
// but the 2nd line is the same as first line,
// and the real 2nd line value is printed over.
// For example Name: Lion Name2:Lion (altough I typed for
// example horse into name2 field, and the program draw
// the horse string over the 2nd line which contains Lion.)
//Altough it prints out the all 5 row, it messing only with
//the second row :-/
if( (name.length() > name2.length()
&& name.length() > address.length()
&& name2.isVisible()))
{
g.drawString(name, (250 - nameCord_X) + 46, 202);
g.drawString(name2, (250 - nameCord_X) + 46, 214);
g.drawString(city, (250 - nameCord_X) + 46, 226);
g.drawString(address, (250 - nameCord_X) + 46, 238);
g.drawString(postal, (250 - nameCord_X) + 46, 250);
}