I am making a map over the highest mountains in europe and want to create a for loop that makes the actions for the buttons for me.
I am currently stuck at this code:
String Text = "btn" + i;
Text.addSelectionListener(new SelectionAdapter()
I want to add:
btn1.addSelectionListener(new SelectionAdapter()
btn2.addSelectionListener(new SelectionAdapter()
btn3.addSelectionListener(new SelectionAdapter()
btn4.....
when running the for loop. Does anyone know how to do this?
for(final int i=1; i< country.length; i++){
String Text = "btn" + i;
Text.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
txtCountry= new Text(shell, SWT.BORDER);
txtCountry.setText("Country: " + country[i]);
txtCountry.setBounds(22, 112, 204, 30);
formToolkit.adapt(txtCountry, true, true);
txtHighestMountain = new Text(shell, SWT.BORDER);
txtHighestMountain.setText("Highest Mountain: " + highestPoint[i]);
txtHighestMountain.setBounds(22, 148, 204, 30);
formToolkit.adapt(txtHighestMountain, true, true);
txtMeters = new Text(shell, SWT.BORDER);
txtMeters.setText("Meters above sea level: " + MAMSL[i]);
txtMeters.setBounds(22, 184, 204, 30);
formToolkit.adapt(txtMeters, true, true);
}
}