Schnuffix10
Cadet 2nd Year
- Registriert
- Okt. 2013
- Beiträge
- 24
Heyho!
ja wie im Titel, würd ich gerne mehrere Buttons per for loop erstellen.
Dazu hab ich zuvor ein String Array für die Bezeichnunegn erstellt.
ziel ist quasi ein Taschenrechner.
Allerdings erstellt er per for schleife nur den einen Button und wenn ich
mache, meckert er rum und es lässt sich wegen dem vor dem buttonsss nicht compilieren.
ja wie im Titel, würd ich gerne mehrere Buttons per for loop erstellen.
Dazu hab ich zuvor ein String Array für die Bezeichnunegn erstellt.
ziel ist quasi ein Taschenrechner.
Allerdings erstellt er per for schleife nur den einen Button und wenn ich
Code:
Button buttonsss[i] = new Button(shell,SWT.PUSH);
mache, meckert er rum und es lässt sich wegen dem vor dem buttonsss nicht compilieren.
Code:
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class haupt {
public static void main(String[] args) {
// TODO Auto-generated method stub
Display display = new Display();
Shell shell = new Shell(display);
shell.setSize(300, 350);
shell.setText("Taschenrechner");
String buttons [] = {" CLS ", " Bck ", "", " Close ", "7", "8", "9", "/", "4", "5",
"6", "*", "1", "2", "3", "-", "0", ".", "=", "+"};
Text text1 = new Text(shell, SWT.SINGLE);
text1.setBounds(35, 20, 200, 20);
for(int i = 0; i<buttons.length; i++) {
Button buttonsss = new Button(shell,SWT.PUSH);
buttonsss.setText(buttons[i]);
buttonsss.setBounds(30, 50, 35, 35);
}
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}