Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone walk me through why the remove button isn't working properly? It's suppose to remove the users input from the list (so if they

Can someone walk me through why the remove button isn't working properly? It's suppose to remove the users input from the list (so if they list was made from Lisa Simpson, Harry Potter, and Clary Fray and the user input Harry Potter the list would then become Lisa Simpson, Clary Fray) but it is only asking for the input (Please enter first name: and Please enter last name:) and not removing it. I'm using Java Netbeans

Output example:

First Name Last Name Priority

Kathryn Quirk 1

Tom S 2

Lisa Blackburn 3

and if I wanted to remove someone it should ask for there name (lets say Tom S)and output:

First Name Last Name Priority

Kathryn Quirk 1

Lisa Blackburn 2

/* * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license * Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template */ package air.canada; import java.io.File; import java.io.IOException; import java.util.ArrayList; import javax.swing.JOptionPane; /** * * @author sprince */ public class Waitlist extends javax.swing.JFrame { ArrayList nameList = new ArrayList(); File nameSave = new File("waitList.txt"); /** * Creates new form Waitlist */ public Waitlist() { initComponents(); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") //  private void initComponents() { titleLbl = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); outputArea = new javax.swing.JTextArea(); addBtn = new javax.swing.JButton(); removeBtn = new javax.swing.JButton(); exitBtn = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); titleLbl.setFont(new java.awt.Font("Arial", 0, 36)); // NOI18N titleLbl.setForeground(new java.awt.Color(255, 0, 51)); titleLbl.setText("Waitlist"); outputArea.setColumns(20); outputArea.setRows(5); jScrollPane1.setViewportView(outputArea); addBtn.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N addBtn.setForeground(new java.awt.Color(255, 0, 0)); addBtn.setText("ADD"); addBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { addBtnActionPerformed(evt); } }); removeBtn.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N removeBtn.setForeground(new java.awt.Color(255, 0, 0)); removeBtn.setText("REMOVE"); removeBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { removeBtnActionPerformed(evt); } }); exitBtn.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N exitBtn.setForeground(new java.awt.Color(255, 0, 0)); exitBtn.setText("EXIT"); exitBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { exitBtnActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1) .addComponent(exitBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addComponent(addBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(removeBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) .addContainerGap()) .addGroup(layout.createSequentialGroup() .addGap(135, 135, 135) .addComponent(titleLbl) .addContainerGap(136, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(7, 7, 7) .addComponent(titleLbl) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 355, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(removeBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(addBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(exitBtn) .addContainerGap()) ); pack(); }//  private void addBtnActionPerformed(java.awt.event.ActionEvent evt) { //Get Info String firstName = JOptionPane.showInputDialog(null, "Please enter your first name.", "Information Required", JOptionPane.INFORMATION_MESSAGE); if (firstName.isEmpty()) { }else{ String lastName = JOptionPane.showInputDialog(null, "Please enter your last name.", "Information Required", JOptionPane.INFORMATION_MESSAGE); if (lastName.isEmpty()) { }else{ ArrayList tempRow = new ArrayList(); // add info to array tempRow.add(firstName); tempRow.add(lastName); //add temp list to global nameList.add(tempRow); //output outputArea.append(" "+"Added Successfully!");} //print placeholders//clear previous outputArea.setText("First Name\tLast Name\t\tPriority "); //loop through each row//print colums for(int row = 0; row  tempRow = nameList.get(row); //print to area outputArea.append(" "+tempRow.get(0)+"\t"); outputArea.append(tempRow.get(1)+"\t"); outputArea.append("\t" + (row + 1) + "\t"); } } } private void exitBtnActionPerformed(java.awt.event.ActionEvent evt) { //exit program int result = JOptionPane.showConfirmDialog(null,"Would you like to exit the Waitlist?", "Exit?", JOptionPane.YES_NO_OPTION); if (result == JOptionPane.YES_OPTION) { //exit waitlist without closing the whole program dispose();} } private void removeBtnActionPerformed(java.awt.event.ActionEvent evt) { // if array is empty or index is out of bounds, removal is not possible if (nameList.isEmpty()){ JOptionPane.showMessageDialog(null,"No names to remove.", "Error", JOptionPane.ERROR_MESSAGE); } else{ //Get Info String firstName = JOptionPane.showInputDialog(null, "Please enter your first name.", "Information Required", JOptionPane.INFORMATION_MESSAGE); if (firstName.isEmpty()) { }else{ String lastName = JOptionPane.showInputDialog(null, "Please enter your last name.", "Information Required", JOptionPane.INFORMATION_MESSAGE); if (firstName.isEmpty()) { }else nameList.remove(firstName+" "+lastName); } } outputArea.setText("First Name\tLast Name\t\tPriority "); //loop through each row//print colums for(int row = 0; row  tempRow = nameList.get(row); //print to area outputArea.append(" "+tempRow.get(0)+"\t"); outputArea.append(tempRow.get(1)+"\t"); outputArea.append("\t" + (row + 1) + "\t"); } } public void checkFile(){ try{ if(nameSave.exists()==false){ nameSave.createNewFile(); } }catch(IOException e){ JOptionPane.showMessageDialog(rootPane, "File not found"); e.printStackTrace(); } } /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ // /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(Waitlist.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(Waitlist.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(Waitlist.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(Waitlist.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } // /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Waitlist().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton addBtn; private javax.swing.JButton exitBtn; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTextArea outputArea; private javax.swing.JButton removeBtn; private javax.swing.JLabel titleLbl; // End of variables declaration } 

Step by Step Solution

3.40 Rating (156 Votes )

There are 3 Steps involved in it

Step: 1

Based on the code provided it seems that the remove button is not functioning properly because there ... 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

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions