Hi, I am working on code to have a drop down menu from which you can pick items and add a button with that course. Unfortunetally, I can't get the button to display. And help is greatly appreciated.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ComboBoxFrame extends JFrame {
/***/ private static final long serialVersionUID = 1L;
private JComboBox b;
private String s;
private int x = 0;
private JButton g[] = new JButton[10];
private String courses[] =
{ "Advanced Functions", "Calculus", "Chemistry", "Physics" };
public ComboBoxFrame() {
super("Pick your courses!");
setLayout(new GridLayout(3, 3));
b = new JComboBox(courses);
b.addItemListener( new ItemListener() {
public void itemStateChanged(ItemEvent event) {
if(event.getStateChange() == ItemEvent.SELECTED) {
s = (String) b.getSelectedItem();
g[x] = new JButton(s);
add(g[x]);
//g[x].addActionListener(this);
x++;
} } } );
add(b);
}
/** public void actionPerformed(ActionEvent e) {
String s;
for(int x = 0; x < 10; x++) {
s = courses[x];
if(e.getSource() == s) remove(g[x]);
}
}*/
public static void main(String args[]) {
ComboBoxFrame comboBoxFrame = new ComboBoxFrame();
comboBoxFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
comboBoxFrame.setSize( 350, 150 );
comboBoxFrame.setVisible( true );
}
}