Total members 11889 |It is currently Fri Mar 29, 2024 11:41 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka



Go to page 1, 2  Next


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




Author:
Newbie
User avatar Posts: 6
Have thanks: 0 time

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.");
            }
        });
        
 


_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

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


Author:
Newbie
User avatar Posts: 6
Have thanks: 0 time

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.


Author:
Newbie
User avatar Posts: 6
Have thanks: 0 time

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

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

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






Author:
Newbie
User avatar Posts: 6
Have thanks: 0 time

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) {}

}




Author:
Newbie
User avatar Posts: 6
Have thanks: 0 time

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.");
            }
        }); 


_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

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.");
            }
        });  


_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

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.?


Author:
Newbie
User avatar Posts: 6
Have thanks: 0 time
Post new topic Reply to topic  [ 11 posts ]  Go to page 1, 2  Next

  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     -  
 image slide show     -  
 Show Progress Bar using JQuery     -  



Topic Tags

Java Collections
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com