Switch to full style
Java2 codes,problems ,discussions and solutions are here
Post a reply

how to show hashmap value in a textbox

Fri Jul 27, 2012 9:21 am

i have done a hashmap and when i click one of the option in a combobox i want the hasmap value to appear in a textbox i prepared. how do i do that?..i am not using any database for my project. thank you in advance.
Code:
if (command == "hashmapBox")
{
HashMap<StringStringlookup = new HashMap<StringString>();
lookup.put("switch name"" 1.3.6.1.2.1.1.5.0");
lookup.put("another name"" 1.3.6.1.2.1.1.4.0");
System.out.println(lookup.get("another name"));
Set s lookup.entrySet();
Iterator i s.iterator();
while (
i.hasNext()) {
System.out.println(i.next());



}
}
 


the hashmap is the combobox and the textbox is OIDlabel..after this coding i am stuck and confused how to make it come out in the textbox



Re: how to show hashmap value in a textbox

Fri Jul 27, 2012 10:18 pm

using event handlers and listeners like this :
for button
Code:
JButton loadBts = new JButton("Load");
  loadBts .addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                // change text value here.
            }

        });


or for combo box when the item selected changes


Code:

     JComboBox comboBox
= new JComboBox();
    
comboBox.addItemListener(new ItemListener() {

            public 
void itemStateChanged(ItemEvent e) {
                 
// change the text field value here.
                
throw new UnsupportedOperationException("Not supported yet.");
            }
        });
        
 


Re: how to show hashmap value in a textbox

Sat Jul 28, 2012 5:01 am

oo ok il try this method and get back to you. thank you so much.

Re: how to show hashmap value in a textbox

Sat Jul 28, 2012 8:21 am

sir i understand it but when i want to implement i do not how..i have ask this question in many forums they give me good answer but my understanding is low in java so i have trouble implementing it.

Re: how to show hashmap value in a textbox

Sat Jul 28, 2012 3:20 pm

Please can you post the code snippet for the gui part u r working on ??

Re: how to show hashmap value in a textbox

Sat Jul 28, 2012 3:43 pm

this is the coding..

Code:

OIDLabel = new JLabel("OID:"); 
OIDField = new JTextField(20); 
OIDField.setEditable(true); 
   
   
hashmapBox = new JComboBox(); 
hashmapBox.addItem("switch name"); 
hashmapBox.addItem("another name"); 
   
   
if (command == "hashmapBox") 

HashMap<String, String> lookup = new HashMap<String, String>(); 
lookup.put("switch name", " 1.3.6.1.2.1.1.5.0"); 
lookup.put("another name", " 1.3.6.1.2.1.1.4.0"); 
System.out.println(lookup.get("another name")); 
Set s = lookup.entrySet(); 
Iterator i = s.iterator(); 
while (i.hasNext()) { 
System.out.println(i.next()); 
   
   





Re: how to show hashmap value in a textbox

Sat Jul 28, 2012 4:05 pm

i tried to implement this coding with the coding i gave above to add action listener and all bus i rely dono how to do it.

Code:

import java.awt.*;
import java.awt.event.*;

public class AL extends Frame implements WindowListener,ActionListener {
        TextField text = new TextField(20);
        Button b;
        private int numClicks = 0;

        public static void main(String[] args) {
                //AL myWindow = new AL("My first window");
                myWindow.setSize(350,100);
                myWindow.setVisible(true);
        }

        public AL(String title) {

                super(title);
                setLayout(new FlowLayout());
                addWindowListener(this);
                b = new Button("Click me");
                add(b);
                add(text);
                b.addActionListener(this);
        }

        public void actionPerformed(ActionEvent e) {
                numClicks++;
                text.setText("Button Clicked " + numClicks + " times");
        }

        public void windowClosing(WindowEvent e) {
                dispose();
                System.exit(0);
        }

        public void windowOpened(WindowEvent e) {}
        public void windowActivated(WindowEvent e) {}
        public void windowIconified(WindowEvent e) {}
        public void windowDeiconified(WindowEvent e) {}
        public void windowDeactivated(WindowEvent e) {}
        public void windowClosed(WindowEvent e) {}

}



Re: how to show hashmap value in a textbox

Sat Jul 28, 2012 4:36 pm

annette wrote:this is the coding..

Code:

OIDLabel = new JLabel("OID:"); 
OIDField = new JTextField(20); 
OIDField.setEditable(true); 
   
   
hashmapBox = new JComboBox(); 
hashmapBox.addItem("switch name"); 
hashmapBox.addItem("another name"); 
   
   
if (command == "hashmapBox") 

HashMap<String, String> lookup = new HashMap<String, String>(); 
lookup.put("switch name", " 1.3.6.1.2.1.1.5.0"); 
lookup.put("another name", " 1.3.6.1.2.1.1.4.0"); 
System.out.println(lookup.get("another name")); 
Set s = lookup.entrySet(); 
Iterator i = s.iterator(); 
while (i.hasNext()) { 
System.out.println(i.next()); 
   
   





so great
u have a comboBox , what u need i just to add a listener to it :
like this

Code:
    hashmapBox.addItemListener(new ItemListener() {

            public 
void itemStateChanged(ItemEvent e) {
                 
// change the text field value here.
                
throw new UnsupportedOperationException("Not supported yet.");
            }
        }); 


Re: how to show hashmap value in a textbox

Sat Jul 28, 2012 4:39 pm

annette wrote:i tried to implement this coding with the coding i gave above to add action listener and all bus i rely dono how to do it.

Code:

import java.awt.*;
import java.awt.event.*;

public class AL extends Frame implements WindowListener,ActionListener {
        TextField text = new TextField(20);
        Button b;
        private int numClicks = 0;

        public static void main(String[] args) {
                //AL myWindow = new AL("My first window");
                myWindow.setSize(350,100);
                myWindow.setVisible(true);
        }

        public AL(String title) {

                super(title);
                setLayout(new FlowLayout());
                addWindowListener(this);
                b = new Button("Click me");
                add(b);
                add(text);
                b.addActionListener(this);
        }

        public void actionPerformed(ActionEvent e) {
                numClicks++;
                text.setText("Button Clicked " + numClicks + " times");
        }

        public void windowClosing(WindowEvent e) {
                dispose();
                System.exit(0);
        }

        public void windowOpened(WindowEvent e) {}
        public void windowActivated(WindowEvent e) {}
        public void windowIconified(WindowEvent e) {}
        public void windowDeiconified(WindowEvent e) {}
        public void windowDeactivated(WindowEvent e) {}
        public void windowClosed(WindowEvent e) {}

}



Not the frame it self that should implement the listeners, just do inline definition for it , like this:
Code:
    hashmapBox.addItemListener(new ItemListener() {

            public 
void itemStateChanged(ItemEvent e) {
                 
// change the text field value here.
                
throw new UnsupportedOperationException("Not supported yet.");
            }
        });  


Re: how to show hashmap value in a textbox

Sat Jul 28, 2012 4:49 pm

ooo ok. so then what is the meaning for // change the text field value here and "Not supported yet."..should i add anything in this place.?

Post a reply
  Related Posts  to : how to show hashmap value in a textbox
 HashMap class with generics     -  
 Print the content of hashMap object     -  
 AutoComplete TextBox     -  
 Disable TextBox html by php     -  
 add data from form1 textbox to form2 combo box     -  
 calling method to form- displaying textbox data in messagbox     -  
 Re: An example show what is LAN     -  
 show the content of set     -  
 How to Show a message before the login ?     -  
 image slide show     -  

Topic Tags

Java Collections