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
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 helpSwing 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 applicationSwing 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 ApplicationSwing 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 AWTHelp Required How to bring password field in JDialogueBox??? ... static String
HELP = "
help";
private JFrame controllingFrame; //needed...");
JButton helpButton = new JButton("
Help Combobox application - Swing AWTCombobox 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 excelswing 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 AWTNeed
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 ApplicationThreads 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 applicationcatching 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-SwingNeed
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
Retrieve data from database in swing applicationRetrieve data from database in
swing application I want to retrive data(doctor name,specilization,date) from my sql database.
............................................................................
doctors name(JLabel1
Opening IE from Java Swing Application in Kiosk modeOpening 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
SWINGSWING 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 swingswing Write a java
swing program to delete a selected record from a table
swingswing How to make
swing component auto-resizable when JFrame resize
SwingSwing 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
SwingSwing 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 CSSjava
swing and CSS can css be used in java
swing desktop
application in different forms for better styles?plzz
help swingswing 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
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
helphelp pls
help me to get the code of a java program
a program to perform different shapes in a menu using javaapplet
helphelp 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
HELPHELP 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