Results 1 to 1 of 1
  1. #1
    stephanie904 is offline Member
    Join Date
    Feb 2012
    Posts
    13
    Rep Power
    0

    Default find an item Joptionpane

    when it asks me in JOption to find an item, and than I type it in, but instead of displaying me the whole list of names I just want that item that I asked for to display...is there something wrong with my findFirst method or could you do it with JoptionPane..how could I do it ? thank you

    my code

    Java Code:
    import java.util.*;
    import java.util.LinkedList;
    import javax.swing.*;
    
    public class Main {
    	public static void main(String[] args) {
    		
    		SinglyLinkedList<String> names = new SinglyLinkedList<String>();
    		names.add("Fred");
    		names.add("Earl");
    		names.add("Dan");
    		names.add("Carl");
    		names.add("Ben");
    
    
          String strOption;
          int option = 0;
    
          do {
             strOption = JOptionPane.showInputDialog(" MENU \n1.Add an Item\n2. Delete an item\n3. Find an Item\n4. Display the list\n5. Exit ");
          try{
          option = Integer.parseInt(strOption);
    
          }catch(NumberFormatException ex){
             JOptionPane.showMessageDialog(null, "try again");
             option = 0;
    
         }
         switch(option){
           case 0:
               break;
               case 1:
               
               names.add(JOptionPane.showInputDialog(names));
    	        JOptionPane.showMessageDialog(null, "SinglyLinkedList:" + names);
                
               break;
          
               case 2:
               JOptionPane.showMessageDialog(null, "Remove an item");
               names.remove(JOptionPane.showInputDialog(names));
               JOptionPane.showMessageDialog(null, "SinglyLinkedList:" + names);
               break;
    
               case 3:
               JOptionPane.showMessageDialog(null, "Find an item");
               names.findFirst(JOptionPane.showInputDialog(names));
               JOptionPane.showMessageDialog(null, "SinglyLinkedList:" + names);
                
               break;
          
               case 4:
               JOptionPane.showMessageDialog(null, "Find an item");
               JOptionPane.showMessageDialog(null, "SinglyLinkedList:" + names);
               break;
    
    
               case 5:
               JOptionPane.showMessageDialog(null, "Exit");
               break;
               default:
        	   JOptionPane.showMessageDialog(null, "Option is not valid");
         }
    
    
        }while(option!=5);
    	}
    	
    }
    Last edited by stephanie904; 09-20-2012 at 06:28 PM.

Similar Threads

  1. Replies: 10
    Last Post: 09-04-2012, 09:12 AM
  2. How to add item on list
    By Aenohe in forum New To Java
    Replies: 4
    Last Post: 12-09-2011, 12:05 AM
  3. Get the item in JComboBox
    By MaxMonic in forum AWT / Swing
    Replies: 1
    Last Post: 01-24-2011, 10:48 AM
  4. Getting an item from an array
    By ile4 in forum New To Java
    Replies: 9
    Last Post: 01-13-2011, 04:42 PM
  5. Replies: 3
    Last Post: 05-01-2008, 09:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •