Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need some help trying to get a comboBox to appear in a JOptionPane after I select a previous comboBox selection. I need select Update

I need some help trying to get a comboBox to appear in a JOptionPane after I select a previous comboBox selection. I need select "Update" from a comboBox and then click the "Proceed" button, upon hitting the button I would like for a JOptionPane to appear that has selections "A" - "F". My code is below, any help would be greatly appreciated.

import java.awt.*;

import java.awt.event.*;

import java.util.HashMap;

import javax.swing.*;

public class GUI extends JFrame implements ActionListener{

private HashMap map = new HashMap();

private JButton processRequest = new JButton("Process Request");

private JComboBox comboBox = new JComboBox();

private JComboBox comboBox2 = new JComboBox();

private JLabel label = new JLabel("Choose a request:");

private JLabel label1 = new JLabel("Id:");

private JLabel label2 = new JLabel("Name:");

private JLabel label3 = new JLabel("Major:");

private JTextField text1 = new JTextField("");

private JTextField text2 = new JTextField("");

private JTextField text3 = new JTextField("");

public GUI(){

setLayout(new GridLayout(0,2));

comboBox.addItem("Insert");

comboBox.addItem("Find");

comboBox.addItem("Update");

comboBox.addItem("Delete");

comboBox2.addItem("A");

comboBox2.addItem("B");

comboBox2.addItem("C");

comboBox2.addItem("D");

comboBox2.addItem("F");

add(label1);

add(text1);

add(label2);

add(text2);

add(label3);

add(text3);

add(label);

add(comboBox);

add(processRequest);

processRequest.addActionListener(this);

}

public void actionPerformed(ActionEvent e){

if(comboBox.getSelectedItem().equals("Insert")){

String str = text1.getText();

int sid = Integer.parseInt(str);

String sname = text2.getText();

String smajor = text3.getText();

text1.setText("");

text2.setText("");

text3.setText("");

Student student = new Student(sname, smajor);

if(map.containsKey(sid))

JOptionPane.showMessageDialog(null, sid + " is already inserted in the database.");

else

map.put(sid, student);

}

else if(comboBox.getSelectedItem().equals("Find")){

String str = text1.getText();

int sid = Integer.parseInt(str);

if(map.containsKey(sid)){

String result = "ID: " + sid + ", " + map.get(sid);

JOptionPane.showMessageDialog(null, result);

}

else

JOptionPane.showMessageDialog(null, sid + " is not found in the database.");

}

else if(comboBox.getSelectedItem().equals("Update")){

String str = JOptionPane.showInputDialog("Enter student ID:");

int sid = Integer.parseInt(str);

str = JOptionPane.showInputDialog("Enter the course grade:");

char grade = Character.toUpperCase(str.charAt(0));

str = JOptionPane.showInputDialog("Enter credit hours:");

double hours = Double.parseDouble(str);

if(map.containsKey(sid)){

map.get(sid).courseCompleted(grade, hours);

}

else

JOptionPane.showMessageDialog(null, sid + " is not found in the database.");

}

else if(comboBox.getSelectedItem().equals("Delete")){

String str = JOptionPane.showInputDialog("Enter student ID:");

int sid = Integer.parseInt(str);

if(map.containsKey(sid))

map.remove(sid);

else

JOptionPane.showMessageDialog(null, sid + "is not found in the database.");

}

else{

System.out.println();

}

}

public static void main(String [] args){

GUI frame = new GUI();

frame.setTitle("Project 4");

frame.setSize(400, 300);

frame.setVisible(true);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

}

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

Fundamentals Of Database Systems

Authors: Sham Navathe,Ramez Elmasri

5th Edition

B01FGJTE0Q, 978-0805317558

More Books

Students also viewed these Databases questions

Question

What are four activities that are exempt from the antitrust laws?

Answered: 1 week ago

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago