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:
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);
}
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 < rainfall[0].length; j++) {
if (sum[j] > 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
Ads
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
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
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
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
2d arrays
2d arrays what is the code for multiplying the values in a
2d array and printing out their sum
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
Java 2D
Java
2D Hi,
What is Java
2D?
Thanks
Hi,
Please see it at Java
2D API.
Thanks
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
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
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
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
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
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
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
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
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... have
taken an
array of three
elements and we will be joining them
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
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
C array sort example
the
implementation of quicksort algorithm to sort the
elements of an
array.
Syntax...
C
array sort example
In this section, you will learn how to sort an
array in C.
For sorting
C Dynamic Array
the
number of
elements that he want to set into the
array...
C Dynamic
Array
 ... of a
dynamic
array in C.
The dynamic
array is an
array data structure which can