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



Home Answers Viewqa Java-Beginners Swing Application help

Have Programming Question? Ask it here!
 
 
 


Pranit Sonawane
Swing Application help
1 Answer(s)      2 years and a month ago
Posted in : Java Beginners


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


Advertisement
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
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
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
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 
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
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
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
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
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
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
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
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
SWING
SWING  A JAVA CODE OF MOVING TRAIN IN SWING
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  How to make swing component auto-resizable when JFrame resize
swing
swing  Write a java swing program to delete a selected record from a table
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
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
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
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
swing - Java Beginners
Swing application testing  What are the conventions for testing a Java swing application
How to invoke other java class by selecting from dropdown menu and subsequently clicking button in java swing application
How to invoke other java class by selecting from dropdown menu and subsequently clicking button in java swing application  Hello Sir, first of all thanx and congratulations to u all guys for helping programmers like us who
How to invoke other java class by selecting from dropdown menu and subsequently clicking button in java swing application
How to invoke other java class by selecting from dropdown menu and subsequently clicking button in java swing application  Hello Sir, first of all thanx and congratulations to u all guys for helping programmers like us who
How to invoke other java class by selecting from dropdown menu and subsequently clicking button in java swing application
How to invoke other java class by selecting from dropdown menu and subsequently clicking button in java swing application  Hello Sir, first of all thanx and congratulations to u all guys for helping programmers like us who
swing-awt - Swing AWT
swing-awt  Hi, Thanks for replying to my question...I'm getting some confusion to add action events in my application(Rich Text Editor).How to add action events? Thank U
help
help   how i can send a pitcture on url in 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
Swing EJB
Swing EJB  Hi everyone !!! I tried to find wether EJB architecture can operate with swing, because I am trying to make application which would work... with webstart so a client with one click can download some swing application which
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
 

 

 

DMCA.com