Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Rafal
Selecting elements of 2D array with GUI
0 Answer(s)      2 years and 4 months 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


Advertisement
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
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
2d arrays
2d arrays  what is the code for multiplying the values in a 2d array and printing out their sum
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
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
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
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
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
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
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
 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
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
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
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
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
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
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
Changing 2D graph using slider.
Changing 2D graph using slider.  Code for changing a 2d graph with help of slider
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
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
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
 

 

 

DMCA.com