Results 1 to 1 of 1
  1. #1
    rdmapes is offline Member
    Join Date
    Apr 2009
    Posts
    1
    Rep Power
    0

    Default JOptionPane with a comboBox with data read from a text file

    Good Day All,
    I have been tinkering with a swing application. I am able to read from the file fine, but I am having an issue getting the Object array to work the way I would like. I have experimented with placement and different code, but kind of stuck. Below is the code, including all of the commented out pieces I have tried. I can make it work if it is in the Swing form, but that won't work for my app. The process will allow me to select X number of ports which then starts a loop and will call this process based on the number of ports I need to configure.
    Any insight would be greatly appreciated.

    My goal is to get a pop-up with a dropdown that allows me to select one of the many ports.

    Java Code:
    public static void serialLoopProcess(String serialDs1)
    	{
    		//clearFields();
    		
    		String subPort = ":1";
    		
    		//Prompt user for search data
    		//String serialSearch = JOptionPane.showInputDialog(null, "Please Select the Serial Port: ");
    		
    		// Here is where we open the file and construct the combobox.
    		// Opening the file to read in the records for serial cards.
    		BufferedReader br = null;
    		
    		try 
    	   	{
    			boolean found = false;
    		
    			// Reading in the file.
    			br = new BufferedReader(new FileReader("Cisco10K.txt"));
    			String serialPortline = null;
    	   	
    			//Used to create a starting point for the counter. Counting serialCards in 
    			// serialCard.txt file
    			//int lineCount = 0;
    	   		   	
    	   	
    			while ((serialPortline = br.readLine()) != null)
    			{
    				//Getting the total number of records in the file.
    				//lineCount++;
    				//Learned that + "" is needed as int cannot be used in setText needs to be set to String.
    				//String totalRecords = (lineCount + "");
    				
    				String[] serialCard = serialPortline.split(",");
    				// Println statement prints out a count of records in the text file serialCard.txt.
    				//System.out.println(totalRecords);
    				
    				//Convert to integer the search value & arrays members. 
    				//int searchValue = Integer.parseInt(search);
    				//int recordCount = Integer.parseInt(totalRecords);
    				//System.out.println(recordCount);
    				//String serialRecord = (String) line;
    				
    				for (int i=0; i<serialCard.length; i++)
    				{
    					// Test println messages.
    					//System.out.println(i);
    					//System.out.println(i);
    					for (int oc12=1; oc12<=12; oc12++)
    					{
    					// Builds a new variable that includes serialPort and serialCard.
    					//String routerPort = new String(serialPort + serialCard[i]);
    					// This loops 28 times, the number of DS1's on a T3.
    						for (int counter=1; counter<=28; counter++)
    						{
    							// Prints out the combined variables to check format.
    							//System.out.println(serialCard[i] + oc12 + "/" + counter + subPort);
    							String ciscoCard = Integer.toString(oc12);
    							String ciscoDS1 = Integer.toString(counter);
    							//String ciscoSerial = serialCard[i].concat(ciscoCard);
    							String ciscoSerial = new String(serialCard[i] + ciscoCard + "/" + ciscoDS1 + subPort);
    							//Object[] ciscoSerial = {new String(serialCard[i] + ciscoCard + "/" + ciscoDS1 + subPort)};
    							//serialCombo.addItem(serialCard[i] + oc12 + "/" + counter + subPort);
    							//serialCombo.addItem(ciscoSerial);
    							Object[] elementValues = {ciscoSerial};
    							//Object elementValue = JOptionPane.showInputDialog(null,"Choose the SerialPort", "Input",JOptionPane.INFORMATION_MESSAGE, null,elementValues, elementValues);
    							//Object ciscoSerialValue = JOptionPane.showInputDialog(null,"Choose the SerialPort", "Input",JOptionPane.INFORMATION_MESSAGE, null,ciscoSerial, ciscoSerial);
    
    							//return ciscoSerial[0];	
    														
    						}
    					 }
    					
    				} // END outter for loop for serialCard.
    
    				found = true;
    				
    			} //END While
    			
    	   		//Object ciscoSerialValue = JOptionPane.showInputDialog(null,"Choose the SerialPort", "Input",JOptionPane.INFORMATION_MESSAGE, null,ciscoSerial, ciscoSerial);
    
    			
    			if (found == false)
    	   		{
    		   		JOptionPane.showMessageDialog(null, "Your search produced no results. Search Again", "No results found", JOptionPane.INFORMATION_MESSAGE);
    	   		} //END if
    		}
    	   	
    	   	catch (FileNotFoundException ex)
    	    {
    	    	ex.printStackTrace();
    	    } //END 1st catch
    	   	catch (IOException e) 
    	   	{
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    	   	finally
    	    {
    	    	try
    	    	{
    	    		if (br != null)
    	    			br.close();
    	    			
    	    	} //END try
    	    	catch (IOException ex) 
    	        {
    	        	ex.printStackTrace();
    	        } //END 3rd catch
    	      } //END finally
    	   		
    	   		//return ciscoSerial;
    	   		//return elementValues;
    	   		//Object[] elementValues = {ciscoSerial};
    	   		//Object elementValue = JOptionPane.showInputDialog(null,"Choose the SerialPort", "Input",JOptionPane.INFORMATION_MESSAGE, null,elementValues, elementValues);
    	   		//serialCombo.addActionListener(this);
    	   		//serialCombo.setToolTipText("Click to select 10K serial ports.");
    
    	}

    Thanks,
    Ron

    Moderator Edit: Code tags added
    Last edited by Fubarable; 11-21-2010 at 06:17 PM. Reason: Moderator Edit: code tags added

Similar Threads

  1. Read Text File
    By Blackberrylerner in forum New To Java
    Replies: 6
    Last Post: 08-14-2010, 12:09 PM
  2. Replies: 3
    Last Post: 06-08-2010, 09:10 PM
  3. JOptionpane Data to a new file
    By javaisntcoffee123 in forum Advanced Java
    Replies: 1
    Last Post: 04-15-2010, 06:21 PM
  4. Replies: 40
    Last Post: 07-04-2008, 09:41 AM
  5. How to read a text file from a Java Archive File
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-08-2008, 10:13 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
  •