java run time textfield and use with map

java run time textfield and use with map

i want to program which read data from file and store in map and display in different textfields which are generated at run time
like a text file store information

class a1
attr.name = name1
attr.value = 1

class a2
attr.name = name2
attr.value = 2
View Answers

May 18, 2010 at 11:10 AM

Hi Friend,

Try the following code:

import java.io.*;
import java.util.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class MapValuesInTextField {
public static void main(String[] args) throws Exception {
JButton b=new JButton("Put file data into TextFields");
JPanel p=new JPanel();
JPanel p1=new JPanel();
final JPanel p2=new JPanel(new GridLayout(4,2));
final JFrame f=new JFrame();

p1.add(b);
p.add(p1);
p.add(p2);
f.add(p);
f.setVisible(true);
f.pack();
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
int i=0;
try{
BufferedReader br = new BufferedReader(new FileReader("C:/data.txt"));
String strLine;
String id="",name="";
HashMap<String, String> hash = new HashMap<String, String>();
while((strLine = br.readLine()) != null){
String[] f = strLine.split(" ");
id = f[0];
name = f[1];
hash.put( id,name);
}
Set set = hash.entrySet();
Iterator it = set.iterator();
while(it.hasNext()){
Map.Entry me = (Map.Entry)it.next();
JTextField t1[]=new JTextField [4];
t1[i]=new JTextField(8);
t1[i].setText(me.getKey().toString());
p2.add(t1[i]);

JTextField t2[]=new JTextField [4];
t2[i]=new JTextField(8);
t2[i].setText(me.getValue().toString());
p2.add(t2[i]);
i++;
}
f.setSize(400,120);
}
catch(Exception ex){}
}
});
}
}

Here is the data.txt file:

1 AAAA
2 BBBB
3 CCCC
4 DDDD

Thanks









Related Tutorials/Questions & Answers:
java run time textfield and use with map - Java Beginners
java run time textfield and use with map  i want to program which read data from file and store in map and display in different textfields which are generated at run time like a text file store information class a1
Java run time polymorphism
Java run time polymorphism  What is run-time polymorphism or dynamic method dispatch
Advertisements
java run time error - JDBC
java run time error  when i m running for batch execution program in jdbc i m facing this kind of runtime error as Exception in thread "main" java.sql.SQLException: Io exception: The Network Adap ter could not establish
java run time error in loading the driver - JDBC
java run time error in loading the driver  when i mrunning the program in oracle using type 4 driver it is giving the error as Error:jdbc.driver.OracleDriver the code was as follows: please suggest me how it can
java run time error - Java Beginners
java run time error  i am getting error "main" java.lang.NullPointerException" in my program, iam sending code actually motive of program... only, i have to display number of files and its last modified time ,i use
java run time error - Java Beginners
java run time error  when i compile my program it didnt show any error in my program.but i cant run my program, if i run my program means..." java.lang.ArrayIndexOutOfBoundsException: 0 at Armstrong.main(Armstrong.java:22) Java Result: 1
java applet run time error - Applet
java applet run time error  Hi, Im new to java applet.please help me. i have create a MPEG movie player in applet. when i run that program... { Player player = null; /*String location="file:///E:/java"; MediaLocator
objects create at run time - Java Interview Questions
objects create at run time  how to create objects at runtime,other than instantiation.  Hi friend, Object : Objects are the basic run time entity or in other words object is a instance of a class . An object
java code to insert select at run time....????
java code to insert select at run time....????  java database code...;/html> 2)edit.jsp: <%@page language="java"%> <%@page import... the application Java Swing then Visit Here   You can also visit
error in java progran at run time - Java Beginners
error in java progran at run time  Hello sir,,, i make a servlet program in java,,but i face some problem,,so please me.. Actually this type of error are come in my all servlet program My Servlet-- Error
error in java progran at run time - Java Beginners
error in java progran at run time  Hello sir,,, i make a servlet program in java,,but i face some problem,,so please me.. Actually this type of error are come in my all servlet program My Servlet-- Error
Run time exception
Run time exception  What class of exceptions are generated by the Java run-time system?  Java runtime system generates RuntimeException and Error exceptions
Run time polymorphism
Run time polymorphism  What is run time polymorphism or dynamic method dispatch
Run time error - WebSevices
Run time error  Hello, Anyone know, how run the template files in zend framework.Anybody help me. Rgds, Pras  code to help in solving the problem : protected function _run($template
get integer at run time
get integer at run time  how to get integer value at run time in j2ee using servlets   Hi, You can get the value from request parameter and then convert using the function Integer.parseInt(variable).ADS_TO_REPLACE_1
run time error
run time error  my program compile successfully but does not showing output for any program ...   Post your code.   public class... name with HelloWorld? One more thing did you use the following command
Run time problem
Run time problem  when i run a project,it shows an exception like "unable to create MIDlet".It also shows "running with locale:English_united States.1252 running in the identified third party security domain" "please help
Java textfield validaton
Java textfield validaton  Sir... i'm new to java. In java JTextfield when we entered a negative value after pressing one button it have to display an error message dialog of textfield and also the textfield should accept
Java textfield validaton
Java textfield validaton  Sir... i'm new to java. In java JTextfield when we entered a negative value after pressing one button it have to display an error message dialog of textfield and also the textfield should accept
JSP handle run-time exceptions
JSP handle run-time exceptions  How does JSP handle run-time exceptions?   You can use the errorPage attribute of the page directive to have uncaught run-time exceptions automatically forwarded to an error processing
How to find run time in SQL.
How to find run time in SQL.  I have 10 backend jobs in sql which runs at different time intervals. Sample data is shown below Table name:- Job_Run... 22/10/2010 17:30:00ADS_TO_REPLACE_1 I want to find the run time of both the jobs
jdbc run time error - JDBC
jdbc run time error  i m creating the table using thin driver it is showing the following run time error: Exception in thread "main" java.lang.ClassNotFoundException: jdbc.oracle.OracleD river
java textfield problem
java textfield problem  I want to navigate the content of text field from one class to another and viceversa through button but when I am getting the text from first class I am getting null value.please help me..here is the code
How to Type in japanese in java Textfield?
How to Type in japanese in java Textfield?  Hello Sir/madam; Am creating an application in java in which i want to get a japanese String input from... in textfield ..Please help me and tell me how to write in japanese
How to stop java scripting engine when the script being run is taking too much time?
How to stop java scripting engine when the script being run is taking too much time?   How to stop java scripting engine when the script being run is taking too much time? for e,g, in case of infinite loop the memory is getting
data to the textfield by means of an actionListener - Java Beginners
data to the textfield by means of an actionListener  how can i put the data of the database 1 at a time to the textfields by means of an actionlisteners and can be view by next or previous
Threads(suspend(),resume()) run time abnormal behaviour
Threads(suspend(),resume()) run time abnormal behaviour   class...=new Thread(this); t.start(); } public void run..."); a1.t.resume(); } } hi! when i run this code after some seconds
Simple Java applet that need usernam, password and textfield.
Simple Java applet that need usernam, password and textfield.  Hi. Anyone can help me on this matter: I need to create a small application... a textfield box. Anything that been input to that textbox will be transfer to DB2
Data transfer object at run time - Development process
Data transfer object at run time  I have to assign data from resulset to data transfer object.. but i don't know the the number of coloums in selected table. So i have creted a Data Object class with 100 getter setter methods
Map java Object to database.
Map java Object to database.  How do you map Java Objects with Database tables
parse map in java
parse map in java  What is a Parser? Can you give the source code to parse map in Java
Java Map Example
Java Map Example  How we can use Map in java collection?   The Map interface maps unique keys to value means it associate value to unique... in order to use it. Here Map is implemented by its subclass HashMap. Using the put
Version of jsf-extensions>jsf-extensions-run-time dependency
List of Version of jsf-extensions>jsf-extensions-run-time dependency
Maven Dependency jsf-extensions-run-time >> 1.0.4
You should include the dependency code given in this page to add Maven Dependency of jsf-extensions >> jsf-extensions-run-time version1.0.4 in your project
Java Map iterator with example
Java Map Iterator is an interface. It keeps the data in the key and value form. It is implemented by HashMap, Tree Map. Map has no iterator method. So...() method to get the data in Set object form. Java Map Iterator with Example
Maven dependency for com.graphhopper - map-matching version 0.4.0-RC1 is released. Learn to use map-matching version 0.4.0-RC1 in Maven based Java projects
. Developer can use this version ( com.graphhopper - map-matching version 0.4.0-RC1...; com.graphhopper - map-matching version 0.4.0-RC1 in Java projects. Follow the step... - map-matching version 0.4.0-RC1 Now the next step is to use the latest
Maven dependency for org.webjars.npm - source-map version 0.7.2 is released. Learn to use source-map version 0.7.2 in Maven based Java projects
version of  org.webjars.npm - source-map library is 0.7.2. Developer can use this version ( org.webjars.npm - source-map version 0.7.2 ) in their Java.... Step 1: Create or use a Maven project First of all you have to create a new Java
Maven dependency for org.webjars.npm - source-map version 0.5.4 is released. Learn to use source-map version 0.5.4 in Maven based Java projects
version of  org.webjars.npm - source-map library is 0.5.4. Developer can use this version ( org.webjars.npm - source-map version 0.5.4 ) in their Java.... Step 1: Create or use a Maven project First of all you have to create a new Java
Maven dependency for org.webjars.npm - source-map version 0.7.4 is released. Learn to use source-map version 0.7.4 in Maven based Java projects
version of  org.webjars.npm - source-map library is 0.7.4. Developer can use this version ( org.webjars.npm - source-map version 0.7.4 ) in their Java.... Step 1: Create or use a Maven project First of all you have to create a new Java
java code for PartialSearch using Map????
java code for PartialSearch using Map????  java code for Partial Search using Map
Run time Exception after Clean and Build JavaNetBeans Project
Run time Exception after Clean and Build JavaNetBeans Project  I have... problem when i run it in NetBeans using Run Main Project Button. Then i 'Clean... The PROBLEM IS... When is run the jar file from the dist folder , the first form (i.e
Java map building - Development process
Java map building  Hello All I want to build a map for a road... to proceed further i need to build a map using these coodinates which i am unable to think of how to do it. I can only use java swing or 2d for this purpose. Any
TextField on the Image
TextField on the Image  how we set label or textfield etc. on the Image
Java Map Iterate
Map is an Interface in the Collection Framework. Map is implemented by its two sub classes HashMap Treemap Map has no iterator method. So use the entrySet() method.It returns the data as Set Example of Java Map
How to convert map to json in Java
How to convert map to json in Java  Hi, I my program I have an object of HashMap and I have to output this into json string. How to convert map to json in Java? Thanks   Hi, You have to use the Google Gson library
How to convert map to json in Java
How to convert map to json in Java  Hi, I my program I have an object of HashMap and I have to output this into json string. How to convert map to json in Java? Thanks   Hi, You have to use the Google Gson library
How to use Map in velocity
How to use Map in velocity       This Example shows you how to use map in velocity. The method... velocity run time engine through method  init(). 2:- Create object
Maven dependency for io.siddhi.extension.map.avro - siddhi-map-avro version 2.2.2 is released. Learn to use siddhi-map-avro version 2.2.2 in Maven based Java projects
- siddhi-map-avro library is 2.2.2. Developer can use this version ( io.siddhi.extension.map.avro - siddhi-map-avro version 2.2.2 ) in their Java project...; io.siddhi.extension.map.avro - siddhi-map-avro version 2.2.2 in Java projects. Follow the step
Maven dependency for io.siddhi.extension.map.avro - siddhi-map-avro version 2.2.1 is released. Learn to use siddhi-map-avro version 2.2.1 in Maven based Java projects
- siddhi-map-avro library is 2.2.1. Developer can use this version ( io.siddhi.extension.map.avro - siddhi-map-avro version 2.2.1 ) in their Java project...; io.siddhi.extension.map.avro - siddhi-map-avro version 2.2.1 in Java projects. Follow the step
Maven dependency for com.igormaznitsa - mind-map-model version 1.6.0 is released. Learn to use mind-map-model version 1.6.0 in Maven based Java projects
Developer can use this version ( com.igormaznitsa - mind-map-model version 1.6.0...; com.igormaznitsa - mind-map-model version 1.6.0 in Java projects. Follow the step...; com.igormaznitsa - mind-map-model version 1.6.0 Now the next step is to use the latest

Ads