CODE IN VISUAL BASIC AND SHOW RESULT PLEASE The university has the following Dor
ID: 3775829 • Letter: C
Question
CODE IN VISUAL BASIC AND SHOW RESULT PLEASE
The university has the following Dormitories:
Siegel Hall $1,500 per semester
Papp Hall $1,500 per semester
Coles Hall $1,200 per semester
University Hall $1,800 per semester
The university also offers the following meal plans:
7 meals per week $560 per semester
14 meals per week $1,095 per semester
Unlimited meals $1,800 per semester
Create an application with three forms. The startup holds the totals charges and the name of the student.
You will have a dormitories form and and a meal plan form. Implement a menu that allows the user to open the dorms and the meal forms. When the user selects a dormitory and a meal, the application should show the total charges and selections for the semester on the startup form. Use a listbox to hold the items selected and labels to hold the totals. On the other forms use a listbox to select the dorms and meal plans.
Design guidelines: In addition to what is stated use a menu, add color to the form and a title, cancel and accept buttons, set tab order.
Explanation / Answer
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class DormAndMealPlanCalc extends JFrame
{
private JPanel dormPanel;
private JPanel selectedDormPanel;
private JComboBox DormBox;
private JLabel label;
private JTextField selectedDorm;
private String[] dorm = {"Allen Hall: $1,500 per semester","Pike Hall: $1,100 per" +
"semester","Fathering Hall: 1,200 per semester","Universty Suites: $1,800"};
public void ComboBoxWindow1()
{
**super("Dorm plan");** wrong placement?
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
buildDormPanel();
**buildSelectedDormPanel;** Variable error
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("You selected: ");
selectedDorm = new JTextField(10);
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 void main(String[] args)
{
**new ComboBoxWindow2();**
}
}
private JPanel mealPanel;
private JPanel selectedMealPanel;
private JComboBox MealBox;
private JLabel label1;
private JTextField selectedMeal;
private JButton calcbutton;
private String[] Meal = {"7 meals per week: $560 per semester","14 meals per week:" +
"$1,095 per semester","Unlimited meals: $1,500 per semester"};
public void ComboBoxWindow()
{
**super("Meal plan");**
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
buildMealPanel();
**BuildselectedMealPanel;** variable problem
add(mealPanel,BorderLayout.CENTER);
add(selectedMealPanel, BorderLayout.SOUTH);
pack();
setVisible(true);
}
private void buildMealPanel()
{
mealPanel = new JPanel();
MealBox = new JComboBox(meal);
MealBox.addActionListener(new ComboBoxListener());
mealPanel.add(MealBox);
**calcbutton = new JButton("Calculate");** syntax/token error
}
calacbutton.addActionListener(new calcbuttonListener);
private void buildSelectedMealPanel()
{
selectedMealPanel = new JPanel();
label = new JLabel("You selected: ");
selectedMeal = new JTextField(10);
selectedMeal.setEditable(false);
selectedMealPanel.add(label);
selectedMealPanel.add(selectedDorm);
}
private class ComboBoxListener1 implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String str;
String selection = (String) DormBox.getSelectedItem();
selectedDorm.setText(selection);
**JOptionPane.showMessageDialog('Total is' + dorm + meal);** argument error
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.