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



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

Have Programming Question? Ask it here!
 
 
 


Rafal
Selecting elements of 2D array with GUI
0 Answer(s)      2 years and 2 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
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
ARRAY ELEMENTS - Java Interview Questions
ARRAY ELEMENTS  How To Find Out Missing Elements {1,2,3,4,5,to 100}?I Want Source Code
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
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
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
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
2d arrays
2d arrays  what is the code for multiplying the values in a 2d array and printing out their sum
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
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
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
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
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
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
Java 2D
Java 2D  Hi, What is Java 2D? Thanks   Hi, Please see it at Java 2D API. Thanks
 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
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
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
Changing 2D graph using slider.
Changing 2D graph using slider.  Code for changing a 2d graph with help of slider
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
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
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
Concatenate 2D arrays
Concatenate 2D arrays  JFileChooser jf = new JFileChooser(); jf.setMultiSelectionEnabled(true); int returnVal = jf.showOpenDialog(frame); File[] file = jf.getSelectedFiles(); for(int i=0;i<file.length;i
Java 2D Graphics - Applet
Java 2D Graphics  I am working on GIS project.I want represent a line in different forms like railroad, airplane etc. How can i acheive this I know the standard forms like dashed, dotted line.My code
java 2d graphics - Java Beginners
java 2d graphics  Hello All I need to use 2d graphics in java to build up a map from the given geographic coordinates. What i am not getting is how to scale down these geographic coordinates to device coordinates. I would
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
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
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
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
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
selecting data from database
selecting data from database  how to select data from database using Dao in struts   Hi, You have to load the data from database using hibernate and send the data in a Java file object to jsp page. Please read at http
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
GUI framework
GUI framework  what do u mean by GUI framework
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
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
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
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
GUI component
GUI component  How can a GUI component handle its own events
 

 

 

DMCA.com