I want an array of letters based on the desired quantity to be displayed in a text field each time the button is pressed, example: desired quantity: 3, selected letter "A", therefore the layout would be something like this: AAA. After that I want to add another letter with another amount of repeat value, example: letter "D" number of repeats "4", so if the text field contains: AAA it will add letter "D" four times without delete the previous content; AAADDDD.
With the following code, it is possible to add any letter with any repeat value, but when another letter is added, all the old letters are replaced with the new ones.
public void add()
{
int tam = Integer.parseInt(tLength.getText());
String val = (String) procList.getSelectedItem();
String line = (String) procList.getSelectedItem();
for(int i = 0; i < tam - 1; i++)
{
line += val;
}
t1.setText(line);
}
The val
variable is a list where the letters can be choose and the tam
variable is the number of repetitions.
Any suggestion is good.
but when another letter is added, all the old letters are replaced with the new ones.
t1.setText(line);
The setText(...)
method will replace the existing text. You want to append the text.
One way to do this is to use:
t1.setText(t1.getText() + line);