displaying an object variables from the Hashtable

Posted on 2003-03-10
Medium Priority
Last Modified: 2010-03-31
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));

          addWindowListener(new WindowAdapter(){
          public void windowClosing(WindowEvent e){
  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);
              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!
Question by:GuRdi
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Accepted Solution

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);

Author Comment

ID: 8108246
an Excellent answer ;-)
its all working now ...
thanks and enjoy the points :-)

Expert Comment

ID: 8108478
Thank you. :-)

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month9 days, 6 hours left to enroll

762 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