Home Answers Viewqa Java-Beginners Selecting elements of 2D array with GUI

 
 


Rafal
Selecting elements of 2D array with GUI
0 Answer(s)      a year and a month ago
Posted in : Java Beginners

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 Pages:
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
2d arrays
2d arrays  what is the code for multiplying the values in a 2d array and printing out their sum
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
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
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
Summary - Basic GUI Elements
Java: Summary - Basic GUI Elements In this tutorial we will learn about Basic GUI elements in Java program. Following table summarizes the variable declarations. String s; // Any string. String t; // A string. //Interpreted
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
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
ARRAY ELEMENTS - Java Interview Questions
ARRAY ELEMENTS  How To Find Out Missing Elements {1,2,3,4,5,to 100}?I Want Source Code
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
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.... Given below code select the elements having particular class name as mention
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
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
Shift Array Elements in Jasva
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
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
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
Java 2D API
Java 2D API       Programming has become more interactive with Java 2D API. You can add images, figures, animation to your GUI and even pass visual information with the help of Java
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 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 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
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
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... and then it takes some inputs for the elements of the array how more you have
Jigloo SWT/Swing GUI Builder
be re-arranged to follow the preferred style (eg, using getters for GUI elements... Jigloo SWT/Swing GUI Builder         CloudGarden's Jigloo GUI Builder is a plugin
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
Array
(System.in); int array[]=new int[5]; System.out.println("Enter Array Elements...(); } System.out.println("Your Array Elements are: "); for(int i=0...Array  What if i will not declare the limit index of an array, how
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
array
array  wap to calculate reverse of 10 elements in an array?  ...("Enter 10 elements: "); for (int i=0;i<arr.length ;i++ ) { arr[i]=input.nextInt(); } System.out.print("Array
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
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
]=Integer.parseInt(br.readLine()); } System.out.println("Array Elements...array  how to getting values and storing values in array by using datainputstream?   Hi Friend, Try the following code: import java.io.
 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....  ShortBuffer put(short [] array) The put
Array
reserved. Use a one-dimensional array of primitive type Boolean to represent the seating chart of the cinema theater. Initialize all the elements of the array... the corresponding elements of the array to true to indicate that the seat is no longer
Java 2D
Java 2D  Hi, What is Java 2D? Thanks   Hi, Please see it at Java 2D API. Thanks
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
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
GUI application program
GUI application program  Write a GUI application program that meets the following requirements: Create an array with 100 randomly chosen integers. Create a textfield to enter an array index and another textfield to display
GUI Tips
elements to a layout after the GUI has already been started. If you want... Java NotesGUI Tips [Beginning of list of GUI tips -- needs much more.... Events and communication After the GUI is constructed, the program stops execution
java list program for common elements
collections list which takes two array list elements and display common elements in both the list as an output   Please visit the following link: Display Common Elements from two ArrayLists
Selecting element using jQuery.
Selecting element using jQuery In this tutorial , we will discuss about the different methods to select elements of html page. The jQuery has two ways to select elements. The first uses a combination of CSS and XPath selectors passed
Graphics 2D
Graphics 2D      ... In the given example, we have used Vector class to implement an array of objects..., filename or byte array.    Show Calendar
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
Rationale for GUI tutorial decisions
Table of Contents Rationale for GUI tutorial decisions Java offers many... learn GUI programming? All "normal" programs are GUI based, so this question... that some Java textbooks are written without any GUI coverage, and others cover
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  How to GUI in Net-beans ... ??   Please visit the following link: http://www.roseindia.net/java/java-tips/background/30java_tools/netbeans.shtml
Sorting elements of a Collection
Sorting elements of a Collection   ... elements of a Collection. You can see how to sort all elements of a Collection... the elements of a Collection in ascending order. If your text starts with the Upper case
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... a class "SquareMatrix".  Then we take an integer type array
Find sum of all the elements of matrix using Java
Find sum of all the elements of matrix using Java A matrix is a rectangular array of numbers. The numbers in the matrix are called its entries or its elements... dimensional array. Now to determine the sum of all these elements, we have
array ADT
array ADT  Write a program using array_ADT to retrieve a list of elements from a file