I have a list of choise. All i want to do, is when i click on a element - to show the string of that element. Suppose i click on "Pizza" element, then i should to get at console (with System.out.println()) the word -Pizza.
Any ideas or example will be very good!
import java.awt.*;
import java.awt.event.*;
class Fereastra extends Frame implements ItemListener{
private Label label;
private List colors;
public Fereastra(String titlu){
super(titlu);
this.addWindowListener(new WindowAdapter (){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
setLayout(new GridLayout(2,1));
label = new Label("Alegeti culoarea");
label.setBackground(Color.red);
colors = new List(3);
colors.add("Rosu");
colors.add("Verde");
colors.add("Albastru");
colors.select(3);
add(label);
add(colors);
setSize(200,200);
colors.addItemListener(this);
}
public void itemStateChanged(ItemEvent e){
switch(colors.getSelectedIndex()){
for(i=0; i<colors.getSize(); i++)
System.out.println(colors[i]); //When i click on element, should to print the String of element
}
}
}
public class TestList{
public static void main(String args[]){
Fereastra f = new Fereastra("Choice");
f.show();
}
}