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



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


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

 

 

DMCA.com