I created a combo box for the selection of a dorm....

I need to create another combo box for the selection of a meal plan...

Should I write that in another class, or can I add it to this class?

I need to display the total of the costs of both at the same time..

I appreciate any help...

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class Main extends JFrame
private JPanel dormPanel;
private JPanel selectedDormPanel;
private JComboBox dormBox;
private JLabel label;
private JTextField selectedDorm;

private String[] dorm = { "Allen Hall: $1500/semester", "Pike Hall: $1600/semester", "Farthing Hall: $1200/semester", "University Suites: $1800/semester"};

public Main()
super("Dorm Selection");


setLayout(new BorderLayout());


add(dormPanel, BorderLayout.CENTER);
add(selectedDormPanel, BorderLayout.SOUTH);



private void buildDormPanel()
dormPanel = new JPanel();
dormBox = new JComboBox(dorm);

dormBox.addActionListener(new ComboBoxListener());


private void buildSelectedDormPanel()
selectedDormPanel = new JPanel();

label = new JLabel("Dorm: ");
selectedDorm = new JTextField (25);


private class ComboBoxListener implements ActionListener

public void actionPerformed(ActionEvent e)
String selection = (String) dormBox.getSelectedItem();

public static void main(String[] args)
new Main();


Edited 3 Years Ago by happygeek: fixed formatting

would be a crappy programming language if you couldn't fit two combo boxes into one frame, wouldn't you think?

You can create another object of JComboBox in same way you created 'dormBox'.


Edited 3 Years Ago by Nick Evan: Fixed formatting

This article has been dead for over six months. Start a new discussion instead.