Code:
package com.mycompany.project.client;
import java.util.ArrayList;
/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class ImageViewer implements EntryPoint {
public void onModuleLoad() {
final RootPanel rootPanel = RootPanel.get();
Button button = new Button("New button");
button.setText("OK");
rootPanel.add(button, 291, 55);
final ListBox comboBox = new ListBox();
comboBox.addItem("1");
comboBox.addItem("2");
comboBox.addItem("3");
comboBox.addItem("4");
comboBox.addItem("5");
comboBox.addItem("6");
comboBox.addItem("7");
comboBox.addItem("8");
comboBox.addItem("9");
comboBox.addItem("10");
comboBox.addItem("11");
comboBox.addItem("12");
rootPanel.add(comboBox, 233, 55);
Label lblWieVielTextboxen = new Label("Wie viel TextBoxen erzeugen?");
rootPanel.add(lblWieVielTextboxen, 35, 55);
Button button_1 = new Button("Liste übergeben");
button_1.setText("Liste ausgeben");
rootPanel.add(button_1, 550, 200);
final Label label = new Label("New label");
rootPanel.add(label, 550, 246);
final HashMap<String,String> liste=new HashMap <String,String>();
button.addClickListener(new ClickListener(){
public void onClick(Widget sender){
int i=comboBox.getSelectedIndex()+1;
int zahl1=1;
int zahl2=1;
int counter=0;
int k=1;
while(counter<i){
Label key=new Label("Key");
rootPanel.add(key,90,130+zahl1);
Label val=new Label("Value "+k);
rootPanel.add(val,290,130+zahl2);
final TextBox box1=new TextBox();
TextBox box2=new TextBox();
rootPanel.add(box2,250,150+zahl2);
rootPanel.add(box1,50,150+zahl1);
liste.put(box1.getText(),box2.getText());
zahl1=zahl1+50;
zahl2=zahl2+50;
k++;
counter++;
}
}
});
button_1.addClickListener(new ClickListener(){
public void onClick(Widget sender){
for(Map.Entry e : liste.entrySet()){
System.out.println(e.getKey()+" = "+e.getValue());
}
}
});
}
}
Hallo Leute ich hab ein kleines Problem, ich hoffe Ihr könnt mir weiterhelfen.
Ich muss eine Webseite in Java entwickeln. Ich benutze hier das GWT.
Mein Problem, ich muss durch eine ListBox Abfrage eine variable Anzahl an TextBoxen erstellen. Das gelingt auch ganz gut. Jetzt muss ich aber den Inhalt der TextBoxen in einer HashMap speichern. Bei der Ausgabe der HashMap wird aber nichts angezeigt. Anscheinend speichert er den Inhalt nicht. Ich hoffe Ihr könnt mir hier weiterhelfen. Bin schon am verzweifeln....