| | |
Combo Boxes
![]() |
•
•
Join Date: Sep 2008
Posts: 38
Reputation:
Solved Threads: 0
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");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
buildDormPanel();
buildSelectedDormPanel();
add(dormPanel, BorderLayout.CENTER);
add(selectedDormPanel, BorderLayout.SOUTH);
pack();
setVisible(true);
}
private void buildDormPanel()
{
dormPanel = new JPanel();
dormBox = new JComboBox(dorm);
dormBox.addActionListener(new ComboBoxListener());
dormPanel.add(dormBox);
}
private void buildSelectedDormPanel()
{
selectedDormPanel = new JPanel();
label = new JLabel("Dorm: ");
selectedDorm = new JTextField (25);
selectedDorm.setEditable(false);
selectedDormPanel.add(label);
selectedDormPanel.add(selectedDorm);
}
private class ComboBoxListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String selection = (String) dormBox.getSelectedItem();
selectedDorm.setText(selection);
}
}
public static void main(String[] args)
{
new Main();
}
}
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");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
buildDormPanel();
buildSelectedDormPanel();
add(dormPanel, BorderLayout.CENTER);
add(selectedDormPanel, BorderLayout.SOUTH);
pack();
setVisible(true);
}
private void buildDormPanel()
{
dormPanel = new JPanel();
dormBox = new JComboBox(dorm);
dormBox.addActionListener(new ComboBoxListener());
dormPanel.add(dormBox);
}
private void buildSelectedDormPanel()
{
selectedDormPanel = new JPanel();
label = new JLabel("Dorm: ");
selectedDorm = new JTextField (25);
selectedDorm.setEditable(false);
selectedDormPanel.add(label);
selectedDormPanel.add(selectedDorm);
}
private class ComboBoxListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String selection = (String) dormBox.getSelectedItem();
selectedDorm.setText(selection);
}
}
public static void main(String[] args)
{
new Main();
}
}
•
•
•
•
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");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
buildDormPanel();
buildSelectedDormPanel();
add(dormPanel, BorderLayout.CENTER);
add(selectedDormPanel, BorderLayout.SOUTH);
pack();
setVisible(true);
}
private void buildDormPanel()
{
dormPanel = new JPanel();
dormBox = new JComboBox(dorm);
dormBox.addActionListener(new ComboBoxListener());
dormPanel.add(dormBox);
}
private void buildSelectedDormPanel()
{
selectedDormPanel = new JPanel();
label = new JLabel("Dorm: ");
selectedDorm = new JTextField (25);
selectedDorm.setEditable(false);
selectedDormPanel.add(label);
selectedDormPanel.add(selectedDorm);
}
private class ComboBoxListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String selection = (String) dormBox.getSelectedItem();
selectedDorm.setText(selection);
}
}
public static void main(String[] args)
{
new Main();
}
}
Regards,
Puneet Kalra
www.PuneetK.com
Sun Certified Java Programmer
Admin of Pikk - Object Relational Mapping Framework
www.PuneetK.com
Sun Certified Java Programmer
Admin of Pikk - Object Relational Mapping Framework
![]() |
Similar Threads
- 2 Combo box relationships, How can I relate the two? (VB.NET)
- Making Master Detail Combo Boxes in Asp.net work without post back (ASP.NET)
- Combo Box (VB.NET)
- Multi column combo box (VB.NET)
- Combo lookup arrays in Visual basic.net 2005 (VB.NET)
- Combo box selection problem (VB.NET)
- Combo Box In Jsp+ Ajax Urgent Please Help Me (JSP)
- Perplexed: Combo Box Not Holding Data (C#)
- combo box help (VB.NET)
Other Threads in the Java Forum
- Previous Thread: Methods
- Next Thread: using @Override sign
| Thread Tools | Search this Thread |
android api applet application apps array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) card chat class classes client code collision columns component constructor database designadrawingapplicationusingjavajslider draw eclipse editor error errors eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress input integer intellij j2me java javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia linux list loop machine map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle parsing plazmic print problem program programming project recursion scanner screen server set sharepoint size smart sms smsspam sort sortedmaps sql string subclass support swing threads tree unlimited webservices windows





