Home Answers Viewqa Java-Beginners java run time textfield and use with map

 
 


vikram
java run time textfield and use with map
1 Answer(s)      3 years ago
Posted in : Java Beginners

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 Pages:
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
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
Java run time polymorphism
Java run time polymorphism  What is run-time polymorphism or dynamic method dispatch
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
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 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
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
Map
Map  If I have an object implementing the Map interface in Java and I wish to iterate over every pair contained within it, what is the most efficient way of going through the map either iterator or for each loop or for loop
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
time
time  sir, i want to show system time on a textfield in awt(java). woulk you send me an example of time which can show time in standard format like H:M:S pls help me sir   Display time in JTextField import
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 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 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
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
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 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
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
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
How to run? - Hibernate
friends are told hibernate is a new entry to Java. so plz try to tell how to use...How to run?  Hiiiiiiiiiiiii friend.. i am Magesh... maps the Java classes to the database tables. It also provides the data query
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
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
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
Run time polymorphism
Run time polymorphism  What is run time polymorphism or dynamic method dispatch
Site map - C Tutorials
| Site Map | Business Software Services India Tutorial Section   C Tutorials  | Java Tutorials | PHP Tutorials  | Linux... Tutorials | Dojo Tutorials   | Java Script Tutorial | CVS Tutorial
Spring Map Factory, Spring Map Configuration
. The SetTargetListClass method set the class to use target Map. Week.java package...Spring Map Factory Ths MapFactoryBean is a simple factory for shared Map instance. The map element is defined in the xml bean definitions. The setSourceMap
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
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). Here
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
Use Map to display file data into textfields
Use Map to display file data into textfields Collection framework allows... of key/value pair and then these map values have to be displayed in different textfields which are generated at run time. In text file, we have written
what is the use of clone() in real time scenario?
what is the use of clone() in real time scenario?  what is the use of clone() in real time scenario?   Hi Friend, Clone() method is used... the following links: http://www.roseindia.net/java/java-get-example/java-clone
run a java application - Java Beginners
run a java application  Hai Deepak, I ve set my environment...$1.class,SwingDemo$2.class.But i couldnt run my file.During run time it gives... run any java file.So i want to know the problem actually i had.Thanks in advance
Applet run with appletviewer but not in browser, any code problem.
the 52 cards will be show in browser as by "appletviewer" and run as "java applet" I...Applet run with appletviewer but not in browser, any code problem.  ... fine but not run from the browser as http://localhost:8080/ProgressoApplication
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:00 I want to find the run time of both the jobs. (i.e when i run
Interactive map
Interactive map  hi........ i require map to be zoom in and enlarge the area and show its detail. Can anyone tel me how can this be done using java swings .... plz help
Map code
Map code  hi................ I have map of navi mumbai, where i want to see the location vashi, nerul, turbhe.... means want to zoom into this area... will help me to do so.....?????? i am using java swings
time
time  how to find the current system time between the user login and logout using java
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: Maps
Java: Maps Key-Value pairs Key-value pairs are stored in maps. Map interfaces Map implemented by HashMap and TreeMap SortedMap implemented by TreeMap.... Implementing classes A number of classes implement the Map interface, including
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
Map java Object to database.
Map java Object to database.  How do you map Java Objects with Database tables
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
parse map in java
parse map in java  What is a Parser? Can you give the source code to parse map in Java
from textfile to textfield
from textfile to textfield  Hi! Please help. I'm beginning to understand a bit about java thanks to this website but could you help me with this problem? Say I create a text file "Info.txt" and I saved in it the name and address
date and time in awt(java)
date and time in awt(java)  sir, do you have an example of date in awt java which can be view over a textfield.   Display time in JTextField import java.util.*; import javax.swing.*; import java.awt.event.*; public
Date and Time - Swing AWT
and plz enclose an anther program that does the same for the time.... i tried... currentdate_textfield; private JTextField enterdate_textfield; private JLabel...; private JLabel jLabel7; private JTextField result_day_textfield
how to move pointer in Textfield to newline
how to move pointer in Textfield to newline  consider my case...; class Table1 extends Frame implements ActionListener{ TextField tf1,tf2,tf3..."); l2.setBounds(100,50,200,20); tf1=new TextField(); tf1.setBounds(100,80,200,20

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.