Question: I am getting this Error can you please fix my Java code. import java.awt.Dialog; import java.awt.Label; import java.awt.TextArea; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import

 I am getting this Error can you please fix my Java

I am getting this Error can you please fix my Java code.

import java.awt.Dialog;

import java.awt.Label;

import java.awt.TextArea;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.List;

import java.util.Map.Entry;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JPanel;

public class Fall_2017 { public TextArea courseInput; public Label textAreaLabel; public JButton addData; public Dialog confirmDialog; HashMap> students; public Fall_2017(){ courseInput = new TextArea(20, 40); textAreaLabel = new Label("Student's data:"); addData = new JButton("Add Data"); addData.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { confirmDialog.show(); } }); createGUI(); } public void createGUI(){ JFrame frame = new JFrame("Student's Data"); frame.setVisible(true); frame.setSize(500, 500); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); panel.add(textAreaLabel); panel.add(courseInput); panel.add(addData); frame.getContentPane().add(panel); initialiseConfirmDialog(frame); } private void initialiseConfirmDialog(JFrame frame) { confirmDialog = new Dialog(frame); JPanel panel = new JPanel(); panel.add(new Label("Do you want to add more students?")); JButton yesButton = new JButton("Yes"); JButton noButton = new JButton("No"); yesButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { confirmDialog.hide(); } }); noButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { confirmDialog.hide(); String text = courseInput.getText(); processCourse(text); courseInput.setText(""); } } ); panel.add(yesButton); panel.add(noButton); confirmDialog.add(panel); confirmDialog.setSize(200, 100); } private void processCourse(String text) { students = new HashMap(); for(String studentData:text.split(" ")){ String[] data = studentData.split(" "); if(students.containsKey(Integer.parseInt(data[0]))){ students.get(Integer.parseInt(data[0])).add(data[1]); }else{ ArrayList courses = new ArrayList(); courses.add(data[1]); students.put(Integer.parseInt(data[0]), courses); } } for(Entry> entry:students.entrySet()){ System.out.println(entry.getKey()); System.out.println(entry.getValue()); System.out.println(); } } public static void main(String[] args) { Fall_2017 gui = new Fall_2017(); }

}

Note: Fall_2e17.java uses or overrides a deprecated API Note: Recompile with -Xlint:deprecation for details

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!