Selecting elements of 2D array with GUI

Selecting elements of 2D array with GUI

Hello!

I am building a Java application with GUI (JFrame form) that is supposed to display all or selected elements of below 2D array (images attached):

Year
Season  2002    2003    2004    2005
Spring  150 163 147 138
Summer  100 89  88  87
Autumn  157 97  96  94
Winter  184 133 129 117

I figured out so far how to display all years and seasons, also the smallest or largest element or smallest or largest sum for each row or column. What I am struggling with is how to write a code to display selected elements only (there are 2 comboboxes: 1 for Year (All years, 2002, 2003, 2004, 2005) and 1 for Season (All seasons, Spring, Summer, Autumn, Winter). The user can select any combination (including all elements in a row or column) and this selection should be displayed in the textArea field (including Year and Season headings).

Here's some code I have so far:

  1. to display all data

    private void allYearsActionPerformed(java.awt.event.ActionEvent evt) {                                         
     displayRainfall.setText("");
    int[][] rainfall = {{150, 163, 147, 138}, {100, 89, 88, 87}, {157, 97, 96, 94}, {184, 133, 129, 117}};
        String[] seasons = {"Spring", "Summer", "Autumn", "Winter"};
        String[] years = {"2002", "2003", "2004", "2005"};
        int i = 0;
        int j = 0;
    
    
    
    String rain = "\n\t\t\t\n";
    rain = "\t\t2002\t2003\t2004\t2005\n\n";
    for (i = 0; i < 4; i++) {
        rain += "\t" + seasons[i];
        for (j = 0; j < 4; j++) {
            rain += "\t" + rainfall[i][j];
        }
        rain += "\n";
    }
    displayRainfall.setText(rain);
    
    }
  2. to display wettest year

    private void getWtYrActionPerformed(java.awt.event.ActionEvent evt) {
    displayWtYr.setText(""); int[][] rainfall = {{150, 163, 147, 138}, {100, 89, 88, 87}, {157, 97, 96, 94}, {184, 133, 129, 117}}; String[] seasons = {"Spring", "Summer", "Autumn", "Winter"}; String[] years = {"2002", "2003", "2004", "2005"}; int sum[] = new int[rainfall[0].length];

        for (int j = 0; j < rainfall[0].length; j++) {
            int total = 0;
            for (int i = 0; i < rainfall.length; i++) {
                total += rainfall[i][j];
                sum[j] = total;
            }
    
    
    
    }
    int yearWet = 000000;
    
    
    int j = 0;
    int wet= 0;
    for (j = 0; j &lt; rainfall[0].length; j++) {
        if (sum[j] &gt; yearWet) {
           yearWet = sum[j];
            wet = j;
        }
    }
    
    displayWtYr.setText("The wettest year was " + years[wet]+" "+ yearWet +"-"+ " mm of rainfall"); }

    Can you please give me some hints how start with the code for displaying elements of the array selected by user?

Many thanks in advance for your help!

Rafal

View Answers









Related Tutorials/Questions & Answers:
Selecting elements of 2D array with GUI
Selecting elements of 2D array with GUI  Hello! I am building... or selected elements of below 2D array (images attached): Year Season 2002 2003... how start with the code for displaying elements of the array selected by user
using 2D Array
using 2D Array  Write a JAVA program using 2D Array to auto-grade exams. For a class of N students, your program should read letter answers (A, B, C... the class average. Define the exam answer key as Final Array in your program
Advertisements
using 2D Array
using 2D Array  Write a JAVA program using 2D Array to auto-grade exams. For a class of N students, your program should read letter answers (A, B, C... the class average. Define the exam answer key as Final Array in your program
Storing the Color Image pixel values into 2d array
Storing the Color Image pixel values into 2d array  i want to store the color image pixel values into 2d array and agiain the array have to store into a text file using java... plz provide the code
ARRAY ELEMENTS - Java Interview Questions
ARRAY ELEMENTS  How To Find Out Missing Elements {1,2,3,4,5,to 100}?I Want Source Code
the array list contains similar type of elements or disimilar type of elements
the array list contains similar type of elements or disimilar type of elements  the array list contains similar type of elements or disimilar type of elements
Shift Array Elements in Java
Java Shift Array Elements This section illustrates you how to shift the array... to enter the array elements,  the direction of shifting (Right or Left... accordingly and displayed the array with shifted elements. Method that shift
JavaScript array get elements at random
JavaScript array get elements at random   ... elements randomly we have printed the array elements by the random index position.... In our HTML code we have created an array of ten elements and have stored ten
how to find inverse of n*n 2d array in java
how to find inverse of n*n 2d array in java  I reached upto code of printing the matrix as: Assume that matrix is square matrix where row=column code is: public class ReadContents{ public static void main(String args
Read text file to 2D array and sorting the second column
Read text file to 2D array and sorting the second column  we found that the student names with marks in a text file the marks decreases significantly. when exams conducted fast 4 times.The first column is the student name
Find sum of the squares of Array elements
Find sum of the squares of Array elements In this section, you will learn how to compute the sum of the squares of the array elements. For this, we have... initialized another array in order to store the square of these array elements
how to find subarray from given large 2d array of arbritary dimension
how to find subarray from given large 2d array of arbritary dimension  my code is: import java.lang.*; import java.io.*; import java.io.File; import... to print the subarray of any dimension from given array file. i have tried upto
Find in Array - Calculate Occurrences of Elements in Array
Find in Array - Calculate Occurrences of Elements in Array... to calculate occurrences of elements in an array. Occurrences means, the how many... you want to fix and then it takes some inputs for the elements of the array how
2d arrays
2d arrays  what is the code for multiplying the values in a 2d array and printing out their sum
JavaScript array slice
JavaScript array slice       JavaScript array class's slice() method returns the selected items or elements from the array according to the provided starting and ending index
code to display images using 2d array - Swing AWT
code to display images using 2d array  HI !! I have an image file in ascii/binary format (lines & pixels) in the form of a 2d-array. I would like to display this using java code. I am relatively new to coding
How can we know the count/number of elements of an array?
How can we know the count/number of elements of an array?  How can we know the count/number of elements of an array
array
array  take a 2d array and display all its elements in a matrix fome using only one for loop and ple explain the program in below
Multiply a range of array elements using Recursion
Multiply a range of array elements using Recursion In this section you will learn how to use recursion to multiply a range of array elements. For this we have.... The program will return the product of the array elements that are within the range
 ShortBuffer in java, Transfer the array's elements into short buffer.
 ShortBuffer in java, Transfer the array's elements into short buffer.  In this tutorial, we will see how to transfer the content of short array... a new short buffer.  ShortBuffer put(short [] array
how i can print the elements before a spicific value in array queue?
how i can print the elements before a spicific value in array queue?  how i can printall elements befor the spicific value and print this value also   Hi Friend, Try this: <html> <script> var arr=new Array
how to print the average of each column of 2d n*m array using java
how to print the average of each column of 2d n*m array using java  here is my code: import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public
Search an elements in the array
Search an elements in the array In this section we will discuss about how to check the availability of an element in the array. Array is a collection... of this program we are going to check the element in the array whether the elemnt
Find Array element from index using GUI
Find Array element from index using GUI In this tutorial, you will learn how to create an GUI application to find an array element from its index. For this, we have created an an array of 100 randomly chosen integers and allow
Java 2D
Java 2D  Hi, What is Java 2D? Thanks   Hi, Please see it at Java 2D API. Thanks
Array
Array  how can i use elements of an array in a circular form? that is if the searching of the element reach the last elements of the array, then it will start serching from the begining of the array
GUI
GUI  How to GUI in Net-beans ... ??   Please visit the following link: http://www.roseindia.net/java/java-tips/background/30java_tools/netbeans.shtml
C Array of String
C Array of String       In this section you will learn how to create an array of string in C. A String is an array of char objects. An array of string can be declared
GUI
GUI  Write a GUI application for the WebBuy Company that allows a user to compose the three parts of a complete email message: the â??To:â??, â??Subject:â?? and â??Message:â?? text. The â??To:â??, and â??Subject:â?? Text areas
Array
Array  How do i insert elements into an array up to a limit from...]; System.out.println("Enter Array Elements: "); for(int i=0;i<...("Your Array Elements are: "); for(int i=0;i<array.length;i
JavaScript array sort numerically
;    As in our previous example of sorting array elements alphabetically we have used the default sort method to sort array elements but here in this example of sorting array elements ( numeric elements ) we have created
Square Elements of Two Dimensional Array
Square Elements of Two Dimensional Array   ... the two dimensional array program and its square. This session provide you... array that contains integer type values. After this, we use two 'for' loop
Array
Array Elements: "); for(int i=0;i<array.length;i++){ array[i]=input.nextInt(); } System.out.println("Your Array Elements...Array  What if i will not declare the limit index of an array, how
java 2d arrays
java 2d arrays  Create a program that will: a) Create the array and populate it with the given values. 9, 8 2, 17 49, 4 13, 119 2, 19 11, 47...(String[] args) { int array_x[][]={ {9,8}, {2,17
JavaScript array splice
JavaScript array splice       One more useful method of JavaScript Array class is splice() method which removes elements from the array and as well as adds elements to the array
JQuery-Selecting class or ID
JQuery-Selecting class or ID  Hi Guys, I am new to JQuery. I am getting little trouble in selecting an item using class or ID in jQuery... of particular id. Given below code select the elements having particular class
array
array  wap to calculate reverse of 10 elements in an array?  ...); System.out.println("Enter 10 elements: "); for (int i=0;i<arr.length ;i...(); } System.out.print("Array is: "); for(int i=0;i<arr.length;i
array
accepts a pointer to integer which represents an array of integer.After that this method prints the entire of the array numbers to the monitor. include using std::cout; using std::endl; void printArray(int *array, int count
selecting entries
selecting entries  I have a textbox by the name country in the browser...and I have some entries of country in database like india, china, australia etc... As soon as I start to type "c" in the textbox , china should appear
JavaScript array join
;  We can put all the elements of an array into a string by using the method join() of JavaScript array object. These elements in the generated string.... In this example we have taken an array of three elements and we will be joining
JavaScript array sort alphabetically
;    We can sort the JavaScript array elements by using... be a function. Here in our example of sorting the array elements we have used simply the sort() method since by default it sorts array elements alphabetically
Changing 2D graph using slider.
Changing 2D graph using slider.  Code for changing a 2d graph with help of slider
C array sort example
C array sort example       In this section, you will learn how to sort an array in C. For sorting an array, we have used the qsort function. This function provides
array
("Array Elements are: "); for(int i=0;i<arr.length;i...array  how to getting values and storing values in array by using datainputstream?   Hi Friend, Try the following code:ADS_TO_REPLACE_1
C Dynamic Array
C Dynamic Array      ... of a dynamic array in C. The dynamic array is an array data structure which can be resized during runtime which means elements can be added and removed
PHP Array Count
PHP Array Count Function To count the elements of an array PHP provides count() function. It counts all elements of an array or properties of an object...   Return Value Returns the number of elements in array
PHP array count
The PHP array_count_values() function is used to count the elements in the array. It returns the number of counting with values in associative array form. In returned array, key is the array's values and values are the number
in_array
in_array  in_array in php
is _array()
is _array()  is_array() in php   Hi Friend, This function is of Boolean type.It checks whether a variable is an array or not. Here is an example: <?php $yes = array('Hello', 'World'); echo is_array($yes) ? 'Array
is _array()
is _array()  is _array()   Hi Friend, This function is of Boolean type.It checks whether a variable is an array or not. Here is an example: <?php $yes = array('Hello', 'World'); echo is_array($yes) ? 'Array

Ads