making of dynamic textfields using swings

Ads

making of dynamic textfields using swings

how to crate dynamic texfields by clicking on button

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
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
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
TextFields
TextFields  How To create A details Of Student Using applet
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
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
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
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
SWINGS
SWINGS  WHAT ARE THE DIFFERENCES BETWEEN AWT AND SWINGS
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
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
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
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
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
How to put the logo in login form using swings/awt?
How to put the logo in login form using swings/awt?  Hi, How to put the logo in login form using swings/awt? I write the login form is working but i want to put the logo in login form plz help   Here is an example
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
swings question
swings question  how to change the background color with the help of color values by using 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
Which one is better for creating a GUI using swings either Manual coding or IDE(NetBeans,eclipse)..? drag and dropping components
Which one is better for creating a GUI using swings either Manual coding or IDE... in java application developing.... Which one is better for creating a GUI using swings either Manual coding or IDE(NetBeans,eclipse)..? drag and dropping components
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
Making Tab using Javascript
Making Tab using Javascript       This Example describes the way to make Tab using javascript and css.For this we are going to make program named 
swings header
swings header   have a string1 it contains 3 parts,for example "123456 service hello" and string2 contains text "change request " like... be dynamic data whatever we give from string2,that should be displayed on the screen
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
JSP & Swings
JSP & Swings  How to integrate jsp and swings
How to find the size of a dynamic webpage using java... eg : Youtube........
How to find the size of a dynamic webpage using java... eg : Youtube........  package newpack; import java.io.BufferedInputStream; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL
swings for webnms
swings for webnms  if i am expanding node of jtree then i want to collapse previous expanding node of jtree in swings how is it possible

Ads