making of dynamic textfields using swings

Ads

 
 

Share on Google+Share on Google+

Naresh Bammidi
making of dynamic textfields using swings
1 Answer(s)      6 years and 8 months ago
Posted in : Java Beginners

how to crate dynamic texfields by clicking on button

Ads
View Answers

March 2, 2011 at 11:11 AM


Java Swing Dynamic TextFields

import java.awt.*;
import java.sql.*;
import javax.swing.*;
import java.awt.event.*;
class DynamicTextFields
{
    public static void main(String[] args) 
    {
        JFrame frame=new JFrame();
        JButton b=new JButton("Add");
        b.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                try{
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
            Statement st=con.createStatement();
            ResultSet rs=st.executeQuery("select * from data where id=1");
            String name="",address="";
            if(rs.next()){
                name=rs.getString("name");
                address=rs.getString("address");
            }
             JFrame f=new JFrame();
             f.setLayout(null);
             JLabel lab1=new JLabel("Name");
             JTextField text1=new JTextField(20);
             JLabel lab2=new JLabel("Address");
             JTextField text2=new JTextField(20);
             lab1.setBounds(10,10,100,20);
             text1.setBounds(120,10,100,20);
             lab2.setBounds(10,40,100,20);
             text2.setBounds(120,40,100,20);
             text1.setText(name);
             text2.setText(address);
             f.add(lab1);
             f.add(text1);
             f.add(lab2);
             f.add(text2);
             f.setSize(300,100);
             f.setVisible(true);
                }
                catch(Exception ex){}
            }
        });
        frame.add(b);
        frame.pack();
        frame.setVisible(true);
    }
}

Ads









Related Tutorials/Questions & Answers:
making of dynamic textfields using swings
making of dynamic textfields using swings  How to make dynamic textfields using java swings
making of dynamic textfields using swings
making of dynamic textfields using swings  how to crate dynamic texfields by clicking on button
Advertisements
dynamic textfields
dynamic textfields  Hi, I am a fresher and joined recently in one company. they gave me a desktop application project using swings.here is my... textfield should be added to the screen.so please help.currently i am using
Image Movement using Swings
Image Movement using Swings  How to move image using Swings
TextFields
TextFields  How To create A details Of Student Using applet
java code using swings
java code using swings  code that should be able to enter data of student details using all swings into the access database using jdbc connectivity
How to insert data from textfields into database using hibernate?
How to insert data from textfields into database using hibernate?  ...(); } This method doesn't work. I tried with quotes for textfields, without them. The setters require other parameters, not textfields. I tried to cast them
An application using swings and vector methods
An application using swings and vector methods   Hi, I want an application in Java swings which uses good selection of Vectors methods
another frame by using awt or swings
another frame by using awt or swings  how to connect one frame to another frame by using awt or swings
create a table in access2007 from gui application using textfields and combox
create a table in access2007 from gui application using textfields and combox  I want to create a table in ms access 2007 from gui application in which when i click create button the table should get created based on textfield
Dynamic tree using textarea data
Dynamic tree using textarea data  I need to create a dynamic tree by using text area data(words) as child nodes in struts. Any body please help me. "very urgent". thanks in advance
Making 301 redirection by using <c:redirect>
Making 301 redirection by using   How can i set the status as 301 when using tag? When i use , I am able to redirect to the desired URL (here, Google page) but I get 302 as the status of redirect. I need this status as 301. Any
Create Dynamic Table using Hubernate
Create Dynamic Table using Hubernate  Thank's for reading my Post. I... into Database using hibernate. At first i use serialization. But i want my application... some browser conflict so now i am using upload bean. But all i cant do is upload
making a web application using Web-logic server - Struts
making a web application using Web-logic server  Hello Sir
making a web application using Web-logic server - Struts
making a web application using Web-logic server  Hello Sir
textfields and update - SQL
textfields and update  how can i retrieve a table from a database and put in on the textfields using jdbc?and at the same time update the items on the database
want a program for date picker by using java swings
program by using swings..please help me thank you in advance.   Have...want a program for date picker by using java swings  to write a program for the date picker by using java swings.any one please help me by providing
plz help me to write a snake game using swings - Swing AWT
plz help me to write a snake game using swings  write snake game program using swings
making a web application using Web-Logic Server - Struts
making a web application using Web-Logic Server  Hello , I am a beginner to the java platform so i am facing some problem in making a web aplication using a struts framework.Hence i referred the docs given in the link http
java swings - Java Beginners
java swings   Do you want to add textfields on the JPanel
SWINGS
SWINGS  WHAT ARE THE DIFFERENCES BETWEEN AWT AND SWINGS
making consistency of data member in the whole programme without using static keyword
making consistency of data member in the whole programme without using static keyword  In the below programme i use one boolean variable named check , which is being accessed inside main function by two objects of Tst1 and Test2
How to insert dynamic textbox values into database using Java?
How to insert dynamic textbox values into database using Java?  Hi I am trying to insert dynamic textbox values to database, my jsp form have 2... of dynamic textboxes with Name and Address will display....Now I want to Insert
swings
swings  Thank you deepak it is fine.... I think you have gone through mine sent code in that i am not able add that Textfield dynamically. Can youhelp me how can i add textfields dynamically in my code lookin forward to hear
textfields and update - SQL
textfields and update  how can i put retrieved table from a database to the textfields using jdbc?and at the same time update the items on the database..   Hello Friend As per ur 1st Q: Read the data from
How to set the border in header and footer from login page using swings/awt
How to set the border in header and footer from login page using swings/awt  Hi, How to set the border in header and footer from login page using swings/awt
Insert value of dynamic generated text box in jsp using javascript
Insert value of dynamic generated text box in jsp using javascript  hello sir , i want to generate dynamic text box at run time and i did that using... using for dynamic row generation. <script LANGUAGE="JavaScript"><
labels,textfields,buttons
labels,textfields,buttons  how to set the labels,textfields,buttons at certain positions such that we can add them without layout managers? my program is to design a login page with image and these labels at exact positions
swings
swings  i have a string1 it contains 3 parts,for example "123456 service hello" and string2 contains text "change request " like this. and the string3 should contain "123456 +(second string) hello" "second string can be dynamic
how can i draw a table using applet or swings - Java Beginners
how can i draw a table using applet or swings  Hi RoseIndia, Actually, I was trying for creating a table using applet or swings.......... My task is create a table and enter the integer values during run time......I have
swings question
swings question  how to change the background color with the help of color values by using swings

Ads

 
Advertisement null

Ads