?
Solved

displaying an object variables from the Hashtable

Posted on 2003-03-10
3
Medium Priority
?
207 Views
Last Modified: 2010-03-31
hi,
In my program the GUI looks like this:

----------    tf1  key1(String)
----------    tf2  key2(String)
----------    tf3  key3(int)
----------    tf4
----------    tf5
store button
---------------------

----------    tf6  key1(String)
----------    tf7  key2(String)
----------    tf8  key3(int)
display button

---------------------
----------    tf9
----------    tf10
----------    tf11  
----------    tf12
----------    tf13


---------------------------
in the tf1,tf2,tf3,tf4,tf5 you enter  in tf1 and tf2 String, tf3 int, tf4 floatand tf5 int.
in tf1, tf2 and tf3 you enter data as key to be stored into the Hashtable using store button.

By entering those keys into the tf6(String),tf7(String), and tf8(int) and pressing display button you should get the stored Object variables into the tf9-tf13 as stored previously in tf1-tf5 in the same order.

I n my program I can store the object but I don't know how to make the object variables entered to be displayed in the tf9-tf13 in the same order.

Here is my code:
-----------------------------
import java.awt.*;
import java.util.*;
import java.awt.event.*;

public class MyTable extends Frame implements ActionListener{

    //definig variables
    private TextField tf1,tf2,tf3,tf4,tf5,tf6,tf7,tf8,tf9,tf10,tf11,tf12,tf13;
    private Button store, display;
    private Hashtable table;
    String str1,str2,str3,str4;
    int int1,int2,in3;
    float flo;
    Object object ;

       public MyTable () {

              /* the GUI with 13 textfields (5 used for storing, 3 to input keys and 5 for displaying object variables stored)
              plus 2 buttons(one used to store values and the other to display)*/

            //building a Hashtable
            table = new Hashtable();
           setSize(new Dimension(370, 244));
            show();

          addWindowListener(new WindowAdapter(){
          public void windowClosing(WindowEvent e){
              System.exit(0);
        }
   });
}
  public static void main(String[] args) {
          MyTable tab = new MyTable ();
     }


  public void actionPerformed(ActionEvent e) {

          str1 = tf1.getText();
          str2 = tf2.getText();
          str3 = tf6.getText();
          str4 = tf7.getText();
          int1 = Integer.parseInt(tf3.getText());
          int2 = Integer.parseInt(tf5.getText());    
          int3 = Integer.parseInt(tf8.getText());
          Float float1 = Float.valueOf(tf4.getText());
           flo = float1.floatValue();
         
           if (e.getSource() == store){
               
               createObject OBJ = new createObject (str1,str2,int1,flo,int2);
               Object object = table.put(str1+str2+int1,OBJ);
               tf1.setText("");
               tf2.setText("");
               tf3.setText("");
               tf4.setText("");
               tf5.setText("");
             }
           
              if (e.getSource() == display){

//// im not sure what to put here (this is where I'm stuck)!
  }

}

class createObject{

   //definig variables of the class
   public String STR1, STR2;
   public int INT1, INT2;
   public float FLOAT1;

   /* a method to create an object which contains the entered values from the first 5 textfields tf1,tf2,tf3,tf4,tf5)*/
   public createObject (String tf1, String tf2, int tf3, float tf4, int tf5)
   {
      STR1= tf1;
      STR2= tf2;
      INT1= tf3;
      FLOAT1= tf4 ;
      INT2= tf5;


   }

}

-------------------------------
hope its clear!
0
Comment
Question by:GuRdi
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
yongsing earned 300 total points
ID: 8107808
if (e.getSource() == display){
  String key = tf6.getText() + tf7.getText() + tf8.getText();
  createOBJ OBJ = (createOBJ)table.get(key);
  tf9.setText(OBJ.STR1);
  tf10.setText(OBJ.STR2);
  tf11.setText(OBJ.INT1);
  tf12.setText(OBJ.FLOAT1);
  tf13.setText(OBJ.INT2);
}
0
 

Author Comment

by:GuRdi
ID: 8108246
an Excellent answer ;-)
its all working now ...
thanks and enjoy the points :-)
0
 
LVL 9

Expert Comment

by:yongsing
ID: 8108478
Thank you. :-)
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month6 days, 16 hours left to enroll

593 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question