gambit77
asked on
swing applet and jcombobox
How would you start awing applet that has jcombo box with at least 10 choices
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
==========================
import java.applet.Applet;
import java.awt.event.ActionEvent
import java.awt.event.ActionListe
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
public class ComboBoxApplet extends Applet {
private JComboBox fComboBox;
public void init() {
// create Combobox
fComboBox = new JComboBox();
// add items
fComboBox.addItem("Item 1");
fComboBox.addItem("Item 2");
fComboBox.addItem("Item 3");
fComboBox.addItem("Item 4");
fComboBox.addItem("Item 5");
fComboBox.addItem("Item 6");
fComboBox.addItem("Item 7");
fComboBox.addItem("Item 8");
fComboBox.addItem("Item 9");
fComboBox.addItem("Item 10");
fComboBox.addItem("Item 11");
// make the combobox "large" so all items are displayed without
// scrolling
fComboBox.setMaximumRowCou
// add a listener to handle the selection
fComboBox.addActionListene
public void actionPerformed(ActionEven
onComboboxSelected();
}
});
// add the combobox to the applet
add(fComboBox);
}
protected void onComboboxSelected() {
// Refer to the currently selected item either by index (<0 when nothing
// is selected) ...
int index = fComboBox.getSelectedIndex
// or by the item (may be null) ...
Object selection = fComboBox.getSelectedItem(
// Do anything you want when an item is selected.
// (e.g. display a dialog)
JOptionPane.showMessageDia
+ selection + ")");
}
}
==========================