Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have this java assignment. I cannot figure out what it's missing. Nothing is printing to the JTextfield. Selections from the menu bar are suppose

I have this java assignment. I cannot figure out what it's missing. Nothing is printing to the JTextfield. Selections from the menu bar are suppose to appear there. Any help would be greatly appreciated. It's due 11/26 at midnight.

/* * JavaJuniorCollege.java * Ch 15 Exercise 10 * This GUI application uses menus to allow the user to access information * about different campuses, majors and activities offered. At least 2 options * for each menu */ package javajuniorcollege; import javax.swing.*; //Swing domponents import java.awt.*; //other GUI components import java.awt.event.*; //event listener

public class JavaJuniorCollege extends JFrame implements ActionListener, ItemListener{

//data fields and components //menu bar JMenuBar mainBar = new JMenuBar(); JMenu file = new JMenu("File"); JMenu campus = new JMenu("Campuses"); JMenu major = new JMenu("Major Fields of Study"); JMenu activities = new JMenu("Activities"); //Under File JMenuItem resetSelections = new JMenuItem("Reset Selections"); JMenuItem exit = new JMenuItem("Exit"); // under campur JRadioButtonMenuItem kent = new JRadioButtonMenuItem("Kent Campus"); JRadioButtonMenuItem trumbull = new JRadioButtonMenuItem("Trumbull Campus"); JRadioButtonMenuItem ashtabula = new JRadioButtonMenuItem("Astabula Campus"); //under major field of study JRadioButtonMenuItem cs = new JRadioButtonMenuItem("Computer Science"); JRadioButtonMenuItem ee = new JRadioButtonMenuItem("Electrical Engineering"); //under activities JCheckBoxMenuItem pilot = new JCheckBoxMenuItem("Pilot's License"); JCheckBoxMenuItem track = new JCheckBoxMenuItem("Cross Country"); ButtonGroup campusGroup = new ButtonGroup(); ButtonGroup majorGroup = new ButtonGroup(); // ButtonGroup activitiesGroup = new ButtonGroup(); boolean reset = false; JTextField totalPackage = new JTextField(40); String packageText = "Choices include: " ; //constructors public JavaJuniorCollege(){ super("Kent State University"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(new FlowLayout()); //add components campusGroup.add(kent); campusGroup.add(trumbull); campusGroup.add(ashtabula); majorGroup.add(cs); majorGroup.add(ee); // activitiesGroup.add(Pilot); // activitiesGroup.add(Track); setJMenuBar(mainBar); mainBar.add(file); mainBar.add(campus); mainBar.add(major); mainBar.add(activities); file.add(resetSelections); file.add(exit); campus.add(kent); campus.add(trumbull); campus.add(ashtabula); major.add(cs); major.add(ee); activities.add(pilot); activities.add(track);

resetSelections.addActionListener(this); exit.addActionListener(this); kent.addActionListener(this); trumbull.addActionListener(this); ashtabula.addActionListener(this); cs.addActionListener(this); ee.addActionListener(this); pilot.addActionListener(this); track.addActionListener(this); add(totalPackage); totalPackage.setFont(new Font("Arial", Font.ITALIC, 16)); } //listener public void actionPerformed(ActionEvent e){ Object source = e.getSource(); if(source == exit){ System.exit(0); } if(source == resetSelections){ boolean reset = true; kent.setSelected(false); trumbull.setSelected(false); ashtabula.setSelected(false); cs.setSelected(false); ee.setSelected(false); pilot.setSelected(false); track.setSelected(false); packageText = "Make selections for your college degree"; totalPackage.setText(packageText); reset = false; } } public void itemStateChanged(ItemEvent e){ Object source = e.getSource(); Container con = getContentPane(); int selected = e.getStateChange(); if(!reset){ packageText = "Total choices include: "; if(kent.isSelected()){ packageText += " " + kent.getText(); } else if(trumbull.isSelected()){ packageText += " " + trumbull.getText(); } else if(ashtabula.isSelected()){ packageText += " " + ashtabula.getText(); } if(cs.isSelected()){ packageText += " " + cs.getText(); } else if(ee.isSelected()){ packageText += " " + ee.getText(); } if(pilot.isSelected()){ packageText += " " + pilot.getText(); } else if(track.isSelected()){ packageText += " " + track.getText(); } totalPackage.setText(packageText); }} public static void main(String[] args) { // instantiate frame, set size, make visible JavaJuniorCollege frame = new JavaJuniorCollege(); frame.setSize(700, 500); frame.setVisible(true); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Murach's SQL Server 2012 For Developers

Authors: Bryan Syverson, Joel Murach, Mike Murach

1st Edition

1890774693, 9781890774691

More Books

Students also viewed these Databases questions

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago