Results 1 to 13 of 13
  1. #1
    timalloy is offline Member
    Join Date
    Apr 2014
    Posts
    12
    Rep Power
    0

    Default Trying to get data from previous Assignment to be displayed in new one using a GUI

    Hello everyone,

    I am trying to get items to display that would display in a command prompt now into a GUI. I am freaking lost at the moment, probably because I've been staring at this code for over a week now. I have included all the files that are necessary to run the program as an attachment for your own testing purposes. Should I be using a TextField to display the data from the CSV files? How do I get the data to be displayed? How would I get it to be displayed based on the different files Staples (newSTPL.csv), Apple (newAPPL.csv), and Microsoft (newMSFT.csv)?

    Java Code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*; 
    
    /**
     * DataAnalyzer Class 
     * This class instantiates the methods from the ReadFiles Class and Calculations Class. 
     * @author Matthew Patten
     * @version April 23, 2014 
     **/
    
    @SuppressWarnings("serial")
    public class DataAnalyzerGUI extends JFrame{  
    	
    	private JPanel contentPanel = (JPanel)getContentPane();  
    	private JButton btnExit = new JButton("Exit");  
    	private JButton btnClose = new JButton ("Close File");  
    	private JButton btnStaples = new JButton("Staples");  
    	private JButton btnApple = new JButton("Apple");  
    	private JButton btnMicrosoft = new JButton("Microsoft");  
    	private JLabel lblWelcome = new JLabel("NASDAQ Data Viewer");  
    	private JLabel lblDetails = new JLabel("Please select a company");  
    	public JTextField dataOutput = new JTextField();  
    	private JButton btnHighClose = new JButton ("Highest Closing Value");  
    	private JButton btnLowClose = new JButton ("Lowest Closing Value"); 
    	private JButton btnHighOpen = new JButton ("Highest Opening Value"); 
    	private JButton btnLowOpen = new JButton ("Lowest Opening Value");  
    	private JButton btnTopTenHigh = new JButton ("Ten Highest Opening Values");  
    	private JButton btnTopTenLow = new JButton ("Ten Lowest Opening Values");  
    	private JButton difference = new JButton ("Difference from Open-Close");
    	public int fileType;
    	//Calculations aCalculations = new Calculations(); 
    	
    	private void add(Container con, Component widget, int left, int top, int width, int height){    
    		widget.setBounds(left, top, width, height);    
    		con.add(widget);
    		}     
    	
    	public void GUIsetup(){
    		
    		/*
    		 * Set dimensions and title to JFrame
    		 */
    		contentPanel.setLayout(null);    
    		setTitle("NASDAQ Data Viewer");    
    		setSize(1200, 600);    
    		setLocation(new Point (1,1));    
    		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);    
    		setVisible(true);
    		
    		/*
    		 * Add labels to JFrame
    		 */
    		add(contentPanel, lblWelcome, 60, 10, 1100, 60);    
    		lblWelcome.setFont(new Font("Helvetica", Font.BOLD, 48));         
    		add(contentPanel, lblDetails, 60, 100, 300, 20);    
    		lblDetails.setFont(new Font("Helvetica", Font.ITALIC, 16));
    		
    		/*
    		 * Add buttons to JFrame
    		 */
    		add(contentPanel, btnStaples, 150, 150, 150, 30);
    		add(contentPanel, btnApple, 150, 300, 150, 30);
    		add(contentPanel, btnMicrosoft, 150, 450, 150, 30);  
    		add(contentPanel, dataOutput, 650, 100, 500, 400);         
    		add(contentPanel, btnExit, 10, 500, 100, 30);
    		
    		/*
    		 * Set visibility to false for buttons required for calculations
    		 */
    		add(contentPanel, btnLowClose, 300, 150, 200, 30);    
    		btnLowClose.setVisible(false);          
    		add(contentPanel, btnLowOpen, 300, 200, 200, 30);    
    		btnLowOpen.setVisible(false);         
    		add(contentPanel, btnHighClose, 300, 250, 200, 30);    
    		btnHighClose.setVisible(false);          
    		add(contentPanel, btnHighOpen, 300, 300, 200, 30);    
    		btnHighOpen.setVisible(false);           
    		add(contentPanel, btnTopTenHigh, 300, 350, 200, 30);    
    		btnTopTenHigh.setVisible(false);         
    		add(contentPanel, btnTopTenLow, 300, 400, 200, 30);    
    		btnTopTenLow.setVisible(false);         
    		add(contentPanel, difference, 300, 450, 200, 30);    
    		difference.setVisible(false);         
    		add(contentPanel, btnClose, 300, 500, 200, 30);    
    		btnClose.setVisible(false);
    		
    		/*
    		 * Displays buttons for Staples calculations
    		 */
    		btnStaples.addActionListener(new ActionListener(){      
    			public void actionPerformed(ActionEvent e){        
    				fileType = 1;
    				lblDetails.setVisible(false);
    				btnStaples.setVisible(false);        
    				btnApple.setVisible(false);        
    				btnMicrosoft.setVisible(false);                 
    				btnLowClose.setVisible(true);        
    				btnLowOpen.setVisible(true);        
    				btnHighOpen.setVisible(true);        
    				btnHighClose.setVisible(true);        
    				btnTopTenHigh.setVisible(true);        
    				btnTopTenLow.setVisible(true);        
    				difference.setVisible(true);        
    				btnClose.setVisible(true);
    				}    
    			});         
    		
    		/*
    		 * Displays buttons for Apple calculations
    		 */
    		btnApple.addActionListener(new ActionListener(){      
    			public void actionPerformed(ActionEvent e){        
    				fileType = 2;
    				lblDetails.setVisible(false);
    				btnStaples.setVisible(false);        
    				btnApple.setVisible(false);        
    				btnMicrosoft.setVisible(false);                 
    				btnLowClose.setVisible(true);        
    				btnLowOpen.setVisible(true);        
    				btnHighOpen.setVisible(true);        
    				btnHighClose.setVisible(true);        
    				btnTopTenHigh.setVisible(true);        
    				btnTopTenLow.setVisible(true);        
    				difference.setVisible(true);        
    				btnClose.setVisible(true);
    				}    
    			});         
    		
    		/*
    		 * Displays buttons for Microsoft calculations
    		 */
    		btnMicrosoft.addActionListener(new ActionListener(){      
    			public void actionPerformed(ActionEvent e){        
    				fileType = 3;
    				lblDetails.setVisible(false);
    				btnStaples.setVisible(false);        
    				btnApple.setVisible(false);        
    				btnMicrosoft.setVisible(false);                 
    				btnLowClose.setVisible(true);        
    				btnLowOpen.setVisible(true);        
    				btnHighOpen.setVisible(true);        
    				btnHighClose.setVisible(true);        
    				btnTopTenHigh.setVisible(true);        
    				btnTopTenLow.setVisible(true);        
    				difference.setVisible(true);        
    				btnClose.setVisible(true);
    				}    
    			});                 
    		
    		/*
    		 * Closes current file that is open and returns to main screen
    		 */
    		btnClose.addActionListener(new ActionListener(){      
    			public void actionPerformed(ActionEvent e){ 
    				lblDetails.setVisible(true);
    				btnStaples.setVisible(true);        
    				btnApple.setVisible(true);        
    				btnMicrosoft.setVisible(true);                 
    				btnLowClose.setVisible(false);        
    				btnLowOpen.setVisible(false);        
    				btnHighOpen.setVisible(false);        
    				btnHighClose.setVisible(false);        
    				btnTopTenHigh.setVisible(false);        
    				btnTopTenLow.setVisible(false);        
    				difference.setVisible(false);        
    				btnClose.setVisible(false);      
    				}    
    			});         
    		
    		/*
    		 * Displays lowest closing calculation
    		 */
    		btnLowClose.addActionListener(new ActionListener(){      
    			public void actionPerformed(ActionEvent e){
    				dataOutput.setText("ugh");
    			}    
    		});         
    		
    		/*
    		 * Displays lowest opening calculation
    		 */
    		btnLowOpen.addActionListener(new ActionListener(){      
    			public void actionPerformed(ActionEvent e){        
    				dataOutput.setText("ugh");    
    				}    
    			});         
    		
    		/*
    		 * Displays highest opening calculation
    		 */
    		btnHighOpen.addActionListener(new ActionListener(){      
    			public void actionPerformed(ActionEvent e){        
    					dataOutput.setText("ugh");
    				}    
    			});         
    		
    		/*
    		 * Displays highest closing calculation
    		 */
    		btnHighClose.addActionListener(new ActionListener(){      
    			public void actionPerformed(ActionEvent e){        
    				dataOutput.setText("ugh");     
    				}    
    			});           
    		
    		/*
    		 * Displays Top Ten Highest opening calculations
    		 */
    		btnTopTenHigh.addActionListener(new ActionListener(){      
    			public void actionPerformed(ActionEvent e){        
    				dataOutput.setText("ugh");      
    				}    
    			});         
    		
    		/*
    		 * Displays Top Ten Lowest opening calculations
    		 */
    		btnTopTenLow.addActionListener(new ActionListener(){      
    			public void actionPerformed(ActionEvent e){        
    				dataOutput.setText("ugh");
    				}
    			});             
    		
    		/*
    		 * Displays the differences between opening and closing values
    		 */
    		difference.addActionListener(new ActionListener(){      
    			public void actionPerformed(ActionEvent e){        
    				dataOutput.setText("ugh");      
    				}    
    			});       
    		
    		/*
    		 * Closes the application
    		 */
    		btnExit.addActionListener(new ActionListener(){      
    			public void actionPerformed(ActionEvent e){        
    				System.exit(0);
    				}
    			});
    		}
    
    	public static void main (String[] args){
    		DataAnalyzerGUI aAnalyzer = new DataAnalyzerGUI();
    		aAnalyzer.GUIsetup();
    		
    		
    /*		Calculations daCalculations = new Calculations();
    		daCalculations.fileCheck();
    		daCalculations.createArray();
    		daCalculations.createDateArray();
    		daCalculations.createDataArray();
    		daCalculations.printArray();
    		daCalculations.performCalculations();*/
    		
    		}
    	}
    Java Code:
    import java.nio.file.*;
    
    import static java.nio.file.AccessMode.*;
    
    import java.io.IOException;
    import java.io.BufferedReader;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.util.StringTokenizer; 
    
    /**
     * ReadFiles Class * This class executes all of the methods called bt DataAnalyzer. 
     * @author Matthew Patten 
     * @version April 23, 2014 
     * 
     **/ 
    
    @SuppressWarnings("serial")
    public class ReadFiles extends DataAnalyzerGUI{  
    	public static int numRows;
    	public static int rowNum = 0;
    	public static int colNum = 0;
    	public static int newRowNum = 0;
    	public static int newColNum = 0;
    	public String [][] splsArray = new String [21][8];
    	public String filePath = ("C:\\temp\\newSPLS.csv");  
    	
    	//This method attempts to read a file to ensure that it is available to be used by the rest of the program.  
    	public void fileCheck(){    
    		if (fileType == 1){      
    			Path filePath = Paths.get("C:\\temp\\newSPLS.csv"); //Path to file
    			System.out.println("File Path: " + filePath.toString()); //Displays file path    
    			dataOutput.setText("Your file is being accessed. Please wait.");      
    			try{        
    				filePath.getFileSystem().provider().checkAccess(filePath, READ, EXECUTE);        
    				System.out.println("File can be read and executed");
    				}           
    			catch (IOException e){        
    				System.out.println ("File cannot be used for this application");
    				}
    			}    
    		else        
    			if(fileType == 2){      
    				Path filePath = Paths.get("C:\\temp\\newAPPL.csv");      
    				System.out.println("Path is " + filePath.toString());           
    				try{        
    					filePath.getFileSystem().provider().checkAccess(filePath, READ, EXECUTE);        
    					System.out.println("File can be read and executed");
    					}           
    				catch (IOException e){        
    					System.out.println ("File cannot be used for this application");
    					}
    				}    
    		else      
    			if (fileType == 3){      
    				Path filePath = Paths.get("C:\\temp\\newMSFT.csv");      
    				System.out.println("Path is " + filePath.toString());
    				try{        
    					filePath.getFileSystem().provider().checkAccess(filePath, READ, EXECUTE);        
    					System.out.println("File can be read and executed");
    					}           
    				catch (IOException e){
    					System.out.println ("File cannot be used for this application");
    					}
    				}
    		}  
    	
    	//Method to find total number of rows in file. 
    	public void findRows(){    
    		try{      
    			BufferedReader buffReader = new BufferedReader(new FileReader(filePath)); //Reads text from a character-input stream, reading of characters, arrays, and lines. 
    			while((filePath = buffReader.readLine()) != null) { //The readLine method returns null when there is nothing else to read.
    		        rowNum++;
    		        colNum = 0;
    				}    
    			buffReader.close();
    		}
    		catch (FileNotFoundException e) {
    			e.printStackTrace(); //Displays error if file can not be found.
    		}
    		catch (IOException e) {
    			System.out.println ("File cannot be used for this application."); //Displays error message.
    		}
    		System.out.println("Total Rows: " + (rowNum));
    	}     
    	
    	//This method converts the file into an array to be used by the rest of the program.  
    	@SuppressWarnings("resource")
    	public void convertFile(){    
    		String convertFilePath = ("\\Users\\Matt\\Desktop\\newSPLS.csv");
    		//The fields for the file are: Date, Open, High, Low, Close, Volume, Adj Close    
    		try{      
    			BufferedReader br = new BufferedReader(new FileReader(convertFilePath));      
    			StringTokenizer st = null;      
    			System.out.println("Your file is being converted. This may take several minutes.");       
    			while((convertFilePath = br.readLine()) != null){        
    				st = new StringTokenizer(convertFilePath, ",");         
    				while(st.hasMoreTokens()){          
    					splsArray[newRowNum][newColNum] = st.nextToken();
    					newColNum++;
    					}        
    				newRowNum++;        
    				newColNum = 0;
    				}
    			}
    		catch (FileNotFoundException e){      
    			System.out.println("Encountered critical error. Your file has not been converted");
    			}     
    		catch (IOException e){      
    			System.out.println("Encountered critical error. Your file has not been converted");
    			}    
    		catch (ArrayIndexOutOfBoundsException e){      
    			System.out.println ("Your file exceeds the available size limit.");
    			}
    		}     
    	
    	//This method prints out all of the data from the array  
    	public void createArray() {
    		  try {
    			  BufferedReader buffReader = new BufferedReader(new FileReader(filePath)); //Reads text from a character-input stream, reading of characters, arrays, and lines. 
    			  StringTokenizer st = null;
    			  System.out.println("\nConverting " + filePath + " into an Array:\n");
    			  
    			  while((filePath = buffReader.readLine()) != null) { //The readLine method returns null when there is nothing else to read.
    				  newRowNum++;
    				  st = new StringTokenizer(filePath, ",");
    				  
    				  while(st.hasMoreTokens()) {
    					  newColNum++;
    					  splsArray[newRowNum][newColNum] = st.nextToken();
    				  }
    				  newColNum = 0;
    				  }
    			  buffReader.close();
    			  }
    		  catch (FileNotFoundException e) {
    			  e.printStackTrace(); //Displays error if file can not be found.
    		  }
    		  catch (IOException e) {
    			  System.out.println ("File cannot be used for this application."); //Displays error message.
    		  }
    	}
    	
    	public void printArray() {
    		System.out.println("Date             Open    High    Low     Close   Volume          Adj Close"); //Prints column titles for Array
    		System.out.println("==========================================================================");
    		for(int i = 1; i < splsArray.length; i++) {
    			for(int j = 1; j < splsArray[i].length; j++) {
    				System.out.print(splsArray[i][j] + "\t "); //Prints row and column values from Array
    			}
    			System.out.println(); //Allows for the clean separation of rows
    		}
    	}
    }
    Java Code:
    import java.io.BufferedWriter;
    import java.io.FileWriter;
    import java.io.IOException;
    
    /**
     * 
     * This is the file that will perform calculations in analyzing the data in the previous assignment (Assignment 2) using
     * the files DataAnalyzer.java and ReadFiles.java.
     * @author Matthew Patten
     * @version April 20, 2014
     *
     */
    
    public class Calculations extends ReadFiles{
      public String []dateArray = new String [splsArray.length];
      public float [][]dataArray = new float[splsArray.length][8];
      public int highestOpenIndex = 0;
      public int highestCloseIndex = 0;
      public int lowestOpenIndex = 0;
      public int lowestCloseIndex = 0;
      public int []lowValue = new int[10];
      public int []highValue = new int[10];
      public float []differenceArray = new float[splsArray.length];
      public float difference;
      public float record;
      public String tempDate;
      public float tempOpen;
      public BufferedWriter writer;
      public String fileName = "splsDiff-Matthew-Patten";
     
      /*
       * Separates date the column from splsArray and moves it to dateArray.
       * 
       * @param createDateArray
       * @return The date column is separated from splsArray
       * @throws ArrayIndexOutOfBoundsException
       */
      public void createDateArray(){
        try{
          for (int i = 1; i < splsArray.length; i++){
            dateArray[i] = splsArray[i][1];
          }
        }
        catch (ArrayIndexOutOfBoundsException e){
        	e.printStackTrace();
        }
      }
       
      /*
       * Takes the rest of the data in splsArray and moves it to dataArray.
       * 
       * @param createDataArray
       * @return The rest of the data in splsArray is moved into dataArray
       * @throws ArrayIndexOutOfBoundsException
       */
      public void createDataArray(){
        try{
          for (int i = 0; i < splsArray.length; i++){
            for (int j = 2; j <= 7; j++){
              if (splsArray[i][j] != null){
                dataArray[i][j] = Float.parseFloat(splsArray[i][j]);
              }
              else{
                dataArray[i][j] = 0;
              }
            }
          }
        }  
        catch (ArrayIndexOutOfBoundsException e){
        	e.printStackTrace();
        }
      }
      
      /*
       * Prints the data in the array to show that the date column has been removed
       * from the rest of the data.
       * 
       * @param printNewArray
       * @return dataArray
       * @throws ArrayIndexOutOfBoundsException
       */
      public void printArray(){
    	  /*
           * Displays the headers for the list.
           */
    	  System.out.println("Open    High    Low     Close   Volume          Adj Close");
    		System.out.println("=========================================================");
    		/*
    	     * Displays the dataArray.
    	     */
    		try{
    	      for (int i = 1; i < splsArray.length; i++){
    	        for (int j = 2; j <= 7; j++){
    	          System.out.print (dataArray[i][j] + "\t");
    	        }
    	        System.out.println();
    	      }
    	    }
    	    catch (ArrayIndexOutOfBoundsException e){
    	    	e.printStackTrace();
    	    }
    	  }
      
      /*
       * This method calculates and displays the highest/closing values of the array and displays the results
       * either by the highest opening/closing value or the lowest opening/closing value. 
       * 
       * @param performCalculations
       * @return dateArray highestOpenIndex highestCloseIndex lowestOpenIndex lowestCloseIndex highValue lowValue differenceArray
       * @throws IOException
       */
      public void performCalculations(){
          for (int i = 0; i < dataArray.length; i++){
            if (dataArray[highestOpenIndex][2] <= dataArray[i][2]){
            	highestOpenIndex = i;
            }
            if (dataArray[highestCloseIndex][5] <= dataArray[i][5] || highestCloseIndex == 0){
              highestCloseIndex = i;
            }
          }
          /*
           * Displays highest opening and closing values from dataArray.
           */
          System.out.println ("\nHighest opening " + dateArray[highestOpenIndex] + ": "  + dataArray[highestOpenIndex][2]);
          System.out.println ("\nHighest closing " + dateArray[highestCloseIndex] + ": " + dataArray[highestCloseIndex][5]);
          
          /*
           * Calculates the lowest opening value.
           */
          for(int i = 0; i < dataArray.length; i++){
            if (dataArray[lowestOpenIndex][2] > dataArray[i][2] || dataArray[lowestOpenIndex][2] == 0){
                lowestOpenIndex = i;
              }
          }
          
          /*
           * Calculates the lowest closing value.
           */
          for(int i = 0; i < dataArray.length; i++){
            if (dataArray[lowestCloseIndex][5] > dataArray[i][5] || dataArray[lowestCloseIndex][5] == 0){
              lowestCloseIndex = i;
            }
          }
          
          /*
           * Displays lowest opening and closing values from dataArray.
           */
          System.out.println ("\nLowest opening " + dateArray[lowestOpenIndex] + ": " + dataArray[lowestOpenIndex][2]);
          System.out.println ("\nLowest closing " + dateArray[lowestCloseIndex] + ": " + dataArray[lowestCloseIndex][5]);
          
          /*
           * Displays the headers for the list.
           */
          System.out.println ("\nTop 10 dates with the highest closing:");
          System.out.println("Date         Closing");
          System.out.println("====================");
          
          /*
           * Calculates the 10 dates with the highest closing values ordered by highest to lowest by date.
           */
          for (int i = 0; i < dataArray.length ; i++){
        	  for(int j = 0; j < highValue.length; j++)
        	  if(dataArray[i][3] > dataArray[highValue[j]][3]){
        		  
        		  for(int k = highValue.length-1; k > j ; k--){
        			  highValue[k] = highValue[k-1];
        		  }
        		  highValue[j] = i;
        		  break;
        	  }
          }
          
          /*
           * Displays the top 10 dates with the highest closing values.
           */
          for (int i = 0; i < lowValue.length; i++){
            System.out.println (dateArray[highValue[i]] + " - " + dataArray[highValue[i]][3]);
          }
          
          /*
           * Displays the headers for the list.
           */
          System.out.println("\nTop 10 dates with the lowest closing:");
          System.out.println("Date         Closing");
          System.out.println("====================");
          
          /*
           * Calculates the 10 dates with the lowest closing values ordered by lowest to highest by date.
           */
          for (int i = 0; i < dataArray.length ; i++){
        	  for(int j = 0; j < lowValue.length; j++){
    	    	  if( lowValue[j] == 0){
    	    		  lowValue[j] = i;
    	    		  break;
    	    	  }
    	    	  if(dataArray[lowValue[j]][4] > dataArray[i][4]){
    	    		  for(int k = lowValue.length-1; k > j ; k--){
    	    			  lowValue[k] = lowValue[k-1];
    	    		  }
    	    		  lowValue[j] = i;
    	    		  break;
    	    	  }
        	  }
          }
          
          /*
           * Displays the top 10 dates with the lowest closing values.
           */
          for (int i = 0; i < lowValue.length; i++){
            System.out.println (dateArray[lowValue[i]] + " - " + dataArray[lowValue[i]][4]);
          }
          
          /*
           * Populates the differenceArray.
           */
          for (int i = 0; i < dataArray.length ; i++){
        	  differenceArray[i] = dataArray[i][2] - dataArray[i][5];  
          }
          
          /*
           * Creates a file with all of the data from the dateArray, dataArray, and the differenceArray.
           */
          System.out.print("\n");
    	  try(FileWriter writer = new FileWriter("C:\\temp\\" + fileName + ".txt")){
    		  writer.write("Date            Open    High    Low     Close   Volume          Adj Close       Difference");
    		  writer.write(System.getProperty( "line.separator" ));
    		  for (int i = 1; i < differenceArray.length; i++){
    			  writer.write(dateArray[i] + "\t" + dataArray[i][2] + "\t" + dataArray[i][3] + "\t" + dataArray[i][4] + "\t" 
    					  + dataArray[i][5] + "\t" + dataArray[i][6] + "\t" + dataArray[i][7] + "\t\t" + Float.toString(differenceArray[i]));
    			  writer.write("\r\n");
    			  writer.flush();
    		  }
    	  }
    		  catch (IOException e){
    	    	e.printStackTrace();
        }
      }
    }
    Attached Files Attached Files
    Last edited by timalloy; 04-26-2014 at 10:34 PM. Reason: Code Modifications

  2. #2
    timalloy is offline Member
    Join Date
    Apr 2014
    Posts
    12
    Rep Power
    0

    Default Re: Trying to get data from previous Assignment to be displayed in new one using a GU

    Ok basically I am confused because I am unable to bring in data from Calculations.java because I am already extending JFrame in DataAnalyzerGUI. If I wanted to display the Highest Opening values in a command prompt I would use this:

    Java Code:
    System.out.println ("\nHighest Opening: " + dataArray[highestOpenIndex][2]);
    How would I go about displaying the Highest Opening value from Calculations.java in the GUI and displaying it using the code below when a button is clicked:

    Java Code:
    dataOutput.setText();
    Last edited by timalloy; 04-26-2014 at 10:22 PM. Reason: Horrendous use of the English language

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Trying to get data from previous Assignment to be displayed in new one using a GU

    There is too much code for me. Maybe someone else will try it.
    If you don't understand my response, don't ignore it, ask a question.

  4. #4
    BinaryDigit09 is offline Member
    Join Date
    May 2012
    Posts
    18
    Rep Power
    0

    Default Re: Trying to get data from previous Assignment to be displayed in new one using a GU

    Just add a getter method in Calculations.java and call it from the GUI.
    Java Code:
    // Calculations.java:
    public int getDataArrayValue(int row, int col) {
     return dataArray[row, col];
    }
    
    // DataAnalyzerGUI.java:
    String text = daCalculations.getDataArrayValue(Calculations.highestOpenIndex, 2) + "";
    dataOutput.setText(text);
    Or you can add several specific methods, like getHighestOpenIndex() etc.

  5. #5
    timalloy is offline Member
    Join Date
    Apr 2014
    Posts
    12
    Rep Power
    0

    Default Re: Trying to get data from previous Assignment to be displayed in new one using a GU

    Quote Originally Posted by BinaryDigit09 View Post
    Just add a getter method in Calculations.java and call it from the GUI.
    Java Code:
    // Calculations.java:
    public int getDataArrayValue(int row, int col) {
     return dataArray[row, col];
    }
    
    // DataAnalyzerGUI.java:
    String text = daCalculations.getDataArrayValue(Calculations.highestOpenIndex, 2) + "";
    dataOutput.setText(text);
    Or you can add several specific methods, like getHighestOpenIndex() etc.
    I added
    Java Code:
    public int getDataArrayValue(int row, int col) {
    return dataArray[row, col];
    But it wanted me to change it to:
    Java Code:
    public int getDataArrayValue(int row, int col) {
    return (int) dataArray[row][col];
    And when I uncomment:
    Java Code:
    Calculations aCalculations = new Calculations();
    Red squiggly lines everywhere... Where have I gone wrong?

  6. #6
    BinaryDigit09 is offline Member
    Join Date
    May 2012
    Posts
    18
    Rep Power
    0

    Default Re: Trying to get data from previous Assignment to be displayed in new one using a GU

    My bad, I had it returning the wrong type.
    Java Code:
    // Calculations.java:
    public float getDataArrayValue(int row, int col) {
     return dataArray[row, col];
    }

  7. #7
    BinaryDigit09 is offline Member
    Join Date
    May 2012
    Posts
    18
    Rep Power
    0

    Default Re: Trying to get data from previous Assignment to be displayed in new one using a GU

    Also, your aCalculations object is not visible to the GUI, so the GUI can't update the button texts. So add another method to tell the GUI about aCalculations, then the GUI can update its buttons.

  8. #8
    timalloy is offline Member
    Join Date
    Apr 2014
    Posts
    12
    Rep Power
    0

    Default Re: Trying to get data from previous Assignment to be displayed in new one using a GU

    Quote Originally Posted by BinaryDigit09 View Post
    My bad, I had it returning the wrong type.
    Java Code:
    // Calculations.java:
    public float getDataArrayValue(int row, int col) {
     return dataArray[row, col];
    }
    Type mismatch: cannot convert from float[] to float

  9. #9
    timalloy is offline Member
    Join Date
    Apr 2014
    Posts
    12
    Rep Power
    0

    Default Re: Trying to get data from previous Assignment to be displayed in new one using a GU

    Quote Originally Posted by BinaryDigit09 View Post
    Also, your aCalculations object is not visible to the GUI, so the GUI can't update the button texts. So add another method to tell the GUI about aCalculations, then the GUI can update its buttons.
    Can you provide me an example?

  10. #10
    BinaryDigit09 is offline Member
    Join Date
    May 2012
    Posts
    18
    Rep Power
    0

    Default Re: Trying to get data from previous Assignment to be displayed in new one using a GU

    Quote Originally Posted by timalloy View Post
    Can you provide me an example?
    Something like this:
    Java Code:
    // DataAnalyzerGUI.java:
    public void setCalculations(Calculations calcs) {
     // update buttons here from calcs
    }
    
    public static void main (String[] args){
            DataAnalyzerGUI aAnalyzer = new DataAnalyzerGUI();
            aAnalyzer.GUIsetup();
             
            Calculations daCalculations = new Calculations();
            daCalculations.fileCheck();
            daCalculations.createArray();
            daCalculations.createDateArray();
            daCalculations.createDataArray();
            daCalculations.printArray();
            daCalculations.performCalculations();
    
            aAnalyzer.setCalculations(daCalculations); 
            }
    }

  11. #11
    timalloy is offline Member
    Join Date
    Apr 2014
    Posts
    12
    Rep Power
    0

    Default Re: Trying to get data from previous Assignment to be displayed in new one using a GU

    Quote Originally Posted by timalloy View Post
    Type mismatch: cannot convert from float[] to float
    This is still an issue for me.

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Trying to get data from previous Assignment to be displayed in new one using a GU

    Type mismatch: cannot convert from float[] to float
    Index into the float array to get a float.
    If you don't understand my response, don't ignore it, ask a question.

  13. #13
    BinaryDigit09 is offline Member
    Join Date
    May 2012
    Posts
    18
    Rep Power
    0

    Default Re: Trying to get data from previous Assignment to be displayed in new one using a GU

    Quote Originally Posted by timalloy View Post
    This is still an issue for me.
    Sorry, I gave you bad syntax.
    Java Code:
    // Calculations.java:
    public float getDataArrayValue(int row, int col) {
     return dataArray[row][col];
    }

Similar Threads

  1. Data Structure (Name Surfer Assignment)
    By ccie007 in forum New To Java
    Replies: 0
    Last Post: 03-30-2011, 04:37 PM
  2. Matrix Data Assignment
    By sehudson in forum New To Java
    Replies: 5
    Last Post: 03-01-2011, 07:45 AM
  3. Oracle/JSTL - All data not being retrieved/displayed
    By kev_thomas in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 10-09-2009, 11:26 AM
  4. Replies: 1
    Last Post: 09-15-2008, 08:21 PM
  5. help..on Next n Previous Button
    By norazanita in forum New To Java
    Replies: 0
    Last Post: 06-12-2008, 05:58 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
  •