Swing Application help

Swing Application help

Hi am developing an application. I have set up an ADD button, which if clicked should open the add information form in the same window. I mean should not close and open another window. also after the last text box should show the save button to save the records in database

View Answers

June 8, 2012 at 5:57 PM

Here is a swing application that will insert the form data into database. For this, set up an ADD button, which when clicked should open the add information form in the same window. This form data will contain the information entered by the user and saved it to database.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
class Form extends JFrame
{
JButton ADD,SAVE;
JPanel panel;
JLabel label1,label2,label3,label4,label5;
final JTextField text1,text2,text3,text4,text5;
Form(){
    setLayout(null);
label1 = new JLabel();
label1.setText("UserID:");
text1 = new JTextField(20);

label2 = new JLabel();
label2.setText("First Name:");
text2 = new JTextField(20);

label3 = new JLabel();
label3.setText("Last Name:");
text3 = new JTextField(20);

label4 = new JLabel();
label4.setText("ADDRESS:");
text4 = new JTextField(20);

label5 = new JLabel();
label5.setText("Email:");
text5 = new JTextField(20);

ADD=new JButton("ADD");
SAVE=new JButton("SAVE");

ADD.setBounds(20,20,100,20);

label1.setBounds(20,50,100,20);
text1.setBounds(140,50,100,20);

label2.setBounds(20,80,100,20);
text2.setBounds(140,80,100,20);

label3.setBounds(20,110,100,20);
text3.setBounds(140,110,100,20);

label4.setBounds(20,140,100,20);
text4.setBounds(140,140,100,20);

label5.setBounds(20,170,100,20);
text5.setBounds(140,170,100,20);


SAVE.setBounds(140,200,100,20);

add(label1);
add(text1);
add(label2);
add(text2);
add(label3);
add(text3);
add(label4);
add(text4);
add(label5);
add(text5);
add(ADD);
add(SAVE);

label1.setVisible(false);
text1.setVisible(false);
label2.setVisible(false);
text2.setVisible(false);
label3.setVisible(false);
text3.setVisible(false);
label4.setVisible(false);
text4.setVisible(false);
label5.setVisible(false);
text5.setVisible(false);
SAVE.setVisible(false);

setTitle("FORM");
ADD.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
label1.setVisible(true);
text1.setVisible(true);
label2.setVisible(true);
text2.setVisible(true);
label3.setVisible(true);
text3.setVisible(true);
label4.setVisible(true);
text4.setVisible(true);
label5.setVisible(true);
text5.setVisible(true);
SAVE.setVisible(true);
}
});
SAVE.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){

String value1=text1.getText();
String value2=text2.getText();
String value3=text3.getText();
String value4=text4.getText();
String value5=text5.getText();
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root" );
        Statement st=conn.createStatement();

             st.executeUpdate("insert into data(id,fname,lname,address,email) values('"+value1+"','"+value2+"','"+value3+"','"+value4+"','"+value5+"')");
            JOptionPane.showMessageDialog(null,"Inserted Successfully!");
        }
catch(Exception e){
System.out.print(e);
}
}
});
}
}
class FormDemo
{
public static void main(String arg[])
{
try
{
Form frame=new Form();
frame.setSize(300,300);
frame.setVisible(true);
}
catch(Exception e){
}
}
}









Related Tutorials/Questions & Answers:
Swing Application help
Swing Application help  Hi am developing an application. I have set up an ADD button, which if clicked should open the add information form...;Here is a swing application that will insert the form data into database
Swing application
Swing application  Hello, I want to develop a Swing application... the application not through web browsers, instead through a Swing desktop application GUIs. Please help me to develop such an application
Advertisements
Swing Application
Swing Application  hello, i am making swing application in java i am unable to run prog......when my rite clikcing on my project name and clicking thn run it is not showing output .....and when i am cliking on individual java
Help Required - Swing AWT
Help Required  How to bring password field in JDialogueBox??? ... static String HELP = "help"; private JFrame controllingFrame; //needed..."); JButton helpButton = new JButton("Help
Combobox application - Swing AWT
Combobox application  hi, i am facing a problem in updation of the comboboxes i m using in an application...for the first time the selectec item does... function...please suggest...  Is it Swing ? If not using
swing application to import a object in a excel
swing application to import a object in a excel  Hi sir, I want to make a swing application where I can import a object in a cell of a excel... to do it. please help. The details of the excel operation which i want to do
Need Help with Java-SWING progrmming - Swing AWT
Need Help with Java-SWING progrmming  Hi sir, I am a beginner in java-swing programming. I want to know how we can use the print option with a program in swing. Could you help me with an example? Regards Sreejith 
Threads in Java Swing MVC Application
Threads in Java Swing MVC Application  Hello, I am currently making a Java Swing application, but I am having a lot of trouble with implementing... it to work in the MVC program. Please help me, or point me to some information
catching tomcat object to swing application
catching tomcat object to swing application  Hi, I have 2 java projects, one is running on tomcat server and another is at client pc ie swing application. So I need to catch a server side object from swing application. How can I
Java application Help?
Java application Help?  Write an application that accepts a users password from the keyboard. When the entered password is less then six characters more then 10 characters, or does not contain at lease one letter and one digit
Java application help!
Java application help!  In Deep Water Associates operates a business... (based on the fill-up time) for a pool. Write an application that prompts the user...-up price. Save the application as Swimming.java. Parameter Fee for cleaning Pool
Java application Help?
Java application Help?  Write an application that can hold five doubles in an array. Display the doubles from first to last, and then display the doubles from last to first. Save the file as DblArray.java. Use the logic
Need Help To Connect XML as backend in Java-Swing
Need Help To Connect XML as backend in Java-Swing  Seat arrangment swing screenshot I made XML program to connect to swing like this. <?xml version="1.0" encoding="iso-8859-1"?> <BUISNESS-CLASS> <PERSON>
How to run java swing application from jar files .
How to run java swing application from jar files .  Hello Sir, I developed a java swing application .Now i want to execute it as .exe... the main class program will exit" from "java virtual machine". Plz help me
Changing Look and Feel of Swing Application
Changing Look and Feel of Swing Application  ... and feel for your Swing Application. The look and feel feature of Java Swing provides more interactivity of the frame for user application. Swing allows
Linking excel file with a application tool using swing
Linking excel file with a application tool using swing  I have to link an excel file with my application software using java swing.As soon as i... a template containing the questions.please help me with the code
Retrieve data from database in swing application
Retrieve data from database in swing application  I want to retrive data(doctor name,specilization,date) from my sql database. ............................................................................ doctors name(JLabel1
steps to create desktop application in java swing using eclipse with drag and drop options
steps to create desktop application in java swing using eclipse with drag and drop options  please help to create desktop application in java swing using eclipse with drag and drop and what are the plugins required
help to load information in init of application - Struts
help to load information in init of application  Thanks for ur... that is in init of the application , please remember, i am using struts2 framework. In this application i am not using any user defined interceptor. So can
Opening IE from Java Swing Application in Kiosk mode
Opening IE from Java Swing Application in Kiosk mode  Hi All, I want to open a URL in IE from my Java Swing application running in Wiindows. I am... in swing application. class OpenBrowser { public static void main(String[] args
need help - Swing AWT
How to execute mysql query based on checkboxes values in java swing application.
How to execute mysql query based on checkboxes values in java swing application.  Hello Sir, I have a java swing application and i have to execute query based on selection of checkboxes.Means I have to to execute
How to execute mysql query based on checkboxes values in java swing application.
How to execute mysql query based on checkboxes values in java swing application.  Hello Sir, I have a java swing application and i have to execute query based on selection of checkboxes.Means I have to to execute
How to execute mysql query based on checkboxes values in java swing application.
How to execute mysql query based on checkboxes values in java swing application.  Hello Sir, I have a java swing application and i have to execute query based on selection of checkboxes.Means I have to to execute
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
SWING
SWING  A JAVA CODE OF MOVING TRAIN IN SWING
Chess Application In Java Swing
.style1 { margin-right: 0px; } Chess Application In Java Swing       In this section, you will learn how to create chess game in java swing
Hii i want a JMS application can anybody help me
Hii i want a JMS application can anybody help me  jms application
How to link a excel file with a application software using java swing
How to link a excel file with a application software using java swing  I have to link an excel file with a application software which I am... you please help me with this? import java.io.*; import java.awt.*; import
How to link a excel file with a application software using java swing
How to link a excel file with a application software using java swing  I have to link an excel file with a application software which I am... you please help me with this? import java.io.*; import java.awt.*; import
How to link an excel file with the application software using java swing
How to link an excel file with the application software using java swing  I have to link an excel file with a application software which I am... later.could you please help me with this? import java.io.*; import java.awt.*; import
swing
swing  Write a java swing program to delete a selected record from a table
swing
swing  How to make swing component auto-resizable when JFrame resize
Need help to create Struts 2 MySQL based HRMS application.
Need help to create Struts 2 MySQL based HRMS application.   Hi Sir, I am doing my project based on Human Resource Management system using struts 2... given here. Some are working but some are not. Can you please help me to create
Need Help in creating online quiz application using JSP - JSP-Servlet
Need Help in creating online quiz application using JSP  Hi, i am creating online Quiz application using JSP and MySQl ,Apache 6 in Netbeans IDE. i..., JSP Page Online Quize Application
Swing
Swing  Write a java swing program to search the details of the students. Searching is performed on studentâ??s first name. The details of all those students having same name as in given in searching criterion will be displayed
Swing
Swing  Write a java swing program to search the details of the students. Searching is performed on studentâ??s first name. The details of all those students having same name as in given in searching criterion will be displayed
java swing and CSS
java swing and CSS  can css be used in java swing desktop application in different forms for better styles?plzz help
swing
swing  i wanted to create a gui desktop application .that can take the database name and mysql password from text box, and after the click of a button it should show connection status,and go for next from there on button click
How to send and view data in seperate tables of a swing application, to a japser reporting(two)
How to send and view data in seperate tables of a swing application, to a japser reporting(two)  I have 2 tables in one swing user interface. I want to view and get printed them in a jasper report. In the jasper report
How to send and view data in seperate tables of a swing application, to a japser reporting(two)
How to send and view data in seperate tables of a swing application, to a japser reporting(two)  I have 2 tables in one swing user interface. I want to view and get printed them in a jasper report. In the jasper report
Java Swing Tutorial - Learning Java Swing programming step by step
applications. Swing application can also be used with the Applet through Java Web... application dropped. In case of Swing Desktop application is required to install and configure swing application in each user desktop. It becomes very
Java Swing Tutorial - Learning Java Swing programming step by step
applications. Swing application can also be used with the Applet through Java Web... application dropped. In case of Swing Desktop application is required to install and configure swing application in each user desktop. It becomes very
Java Swing Tutorial - Learning Java Swing programming step by step
applications. Swing application can also be used with the Applet through Java Web... application dropped. In case of Swing Desktop application is required to install and configure swing application in each user desktop. It becomes very
help
help   how i can send a pitcture on url in java
What is Swing?
What is Swing?  What is Java Swing? Where to get the tutorials of Swing? I am beginner in Java Swing programming and trying to find the tutorials of Swing. Tell me the urls to learn swing. Thanks   Hi, Swing is Java
help
help  pls help me to get the code of a java program a program to perform different shapes in a menu using javaapplet
help
help  i need help with this code. write a java code for a method named addSevenToKthElement that takes an integer array, and an integer k as its arguments and returns the kth element plus 7. any help would be greatly
HELP
HELP  I need this code to open in a new web browser. but no matter what i do it wont please help?? Directive 055 Storage Requirements for the Upstream Petroleum Industry
Help...
Help...  Write a class that displays your first name vertically down the screen â?? where each letter uses up to 5 rows by 5 columns of a character input by you with a blank line between each letter

Ads