Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



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

Have Programming Question? Ask it here!
 
 
 


vikram
java run time textfield and use with map
1 Answer(s)      4 years and 2 months 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

Advertisement
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 - 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 - 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 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
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
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
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
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
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
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 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
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
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 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
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
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
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
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
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
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
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 code for PartialSearch using Map????
java code for PartialSearch using Map????  java code for Partial Search using Map
Java tree map trouble
Java tree map trouble  This is a project for a class, and I am totally stuck! I've created a tree map using an input text file. I split the lines into fields so that I could work with 2 elements from the file. It appears
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
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
Java Map
Java Map         In Java, a Map is a kind of generalized array. It provides a more general way of storing elements. It is an object that maps keys to values. Map
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
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
Map Java Objects with Database tables
Map Java Objects with Database tables  How to map Java Objects with Database tables?   First write Java domain objects ie. beans with setter and getter methods. Then map java class to table and database columns to Java
map
map  using map, i want display message based on id selected [both are strings]   i do no   Hi Friend, Try the following code...) { Map map=new HashMap(); map.put("Message1","Hello
java code to compare two hash map objects
java code to compare two hash map objects  java code to compare two hash map objects
best os to run java
best os to run java  which is best os to run java program
how to run - Java Beginners
how to run   how to run java program... brifely  Hi Friend, Java Virtual Machine is responsible for running java program.Java uses... to execute or run the program. For ex, If you have the following java program
java not run on my pc
java not run on my pc  i have installed java in pc but when i run and compile any program the massage is display that 'javac' is not recognized as an internal or external command
compile and run java program
compile and run java program  Hello, everyone!!! I just want to ask if you anyone here knows how to compile java file in linux specifically UBUNTU. For example, I have a java file named Hello.java and saved at my desktop. how
how to run java program
how to run java program  i have jar file. in jar i have so many classes.in one of file i want modify .after modifying file i want replce in jar. please help me to how to generate class and how to replace
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
java pages run
java pages run  how do we run jsp file in the browser. do we need to install server. could it be run on the xamp server   You need Apache Tomcat Server to run the jsp code over it. Follow these steps to run the simple
Advertisements
 

 

 

DMCA.com