pass data from java frame to file

pass data from java frame to file

i want to write the data to file, and data must be copy from java frame java frame contains 7-8 labels n below that 1 table.

i want store all this data to 1 file. plz help me

View Answers

January 8, 2013 at 7:15 PM

import javax.swing.JFrame; import javax.swing.JTextArea; import javax.swing.JLabel; import javax.swing.JScrollPane; import javax.swing.JTextField; import javax.swing.JButton; import javax.swing.JPanel; import javax.swing.JOptionPane; import javax.swing.JTable; import javax.swing.JScrollPane; import java.awt.Container; import java.awt.Dimension; import java.awt.Insets; import java.awt.*; import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener;

import java.sql.*;

public class CopyFrameDataToFile implements ActionListener { String name, course, subject; int rollNo, marks; JFrame frame; JLabel lab1, lab2, lab3, lab4, lab5; JTextField text1, text2, text3, text4, text5; JButton button;

 public void createUI()
  {         
    frame = new JFrame("Copy Frame Data To File Example");
    frame.setLayout(null);
    frame.setSize(400,300);

    lab1 = new JLabel("Enter Name : ");
    lab2 = new JLabel("Enter Roll No : ");
    lab3 = new JLabel("Enter Course : ");
    lab4 = new JLabel("Enter Subject : ");
    lab5 = new JLabel("Enter Marks : ");

    Container pane =frame.getContentPane();
    pane.setLayout(null);
    Insets insets = pane.getInsets();
    Dimension size;

    JPanel p = new JPanel();

    text1=new JTextField(10);
    text1.setText("");
    text1.setEditable(true);
    p.add(lab1);
    p.add(text1);       
    pane.add(p);
    size = p.getPreferredSize();
    p.setBounds(100 + insets.left, 50 + insets.top,
    size.width, size.height);


    p = new JPanel();

    text2=new JTextField(10);
    text2.setText("");
    text2.setEditable(true);
    p.add(lab2);
    p.add(text2);
    pane.add(p);
    size = p.getPreferredSize();
    p.setBounds(100 + insets.left, 80 + insets.top,
    size.width, size.height);

    p = new JPanel();

    text3=new JTextField(10);
    text3.setText("");
    text3.setEditable(true);
    p.add(lab3);
    p.add(text3);
    pane.add(p);
    size = p.getPreferredSize();
    p.setBounds(100 + insets.left, 110 + insets.top,
    size.width, size.height);

    p = new JPanel();

    text4=new JTextField(10);
    text4.setText("");
    text4.setEditable(true);
    p.add(lab4);
    p.add(text4);
    pane.add(p);
    size = p.getPreferredSize();
    p.setBounds(100 + insets.left, 140 + insets.top,
    size.width, size.height);

    p = new JPanel();

    text5=new JTextField(10);
    text5.setText("");
    text5.setEditable(true);
    p.add(lab5);
    p.add(text5);
    pane.add(p);
    size = p.getPreferredSize();
    p.setBounds(100 + insets.left, 170 + insets.top,
    size.width, size.height);

    p = new JPanel();
    pane.add(p);
    button = new JButton("SUBMIT");
    button.addActionListener(this);
    p.add(button);
    size = p.getPreferredSize();
    p.setBounds(200 + insets.left, 200 + insets.top,
    size.width, size.height);

    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  }// createUI() closed

continue.....


January 8, 2013 at 7:17 PM

public void actionPerformed(ActionEvent e)
    {
        button = (JButton)e.getSource();
        name = text1.getText();
        rollNo = Integer.parseInt(text2.getText());
        course = text3.getText();
        subject = text4.getText();
        marks = Integer.parseInt(text5.getText());
        submitValue();
        System.out.println("Value Submitted Successfully");     
    }
  public void submitValue()
    {
        try
        {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection con = DriverManager.getConnection("jdbc:odbc:swing");
            String sql = "INSERT INTO employee(name, rollNo, course, subject, marks) Values('"+name+"','"+
                rollNo+"','"+course+"','"+subject+"','"+marks+"')";
            Statement st = con.createStatement();
            st.execute(sql);
            JOptionPane.showMessageDialog(null, "Record Added Succesfully.","Record Added",
                            JOptionPane.INFORMATION_MESSAGE);
        }
        catch(Exception e)
        {
            JOptionPane.showMessageDialog(null, e.getMessage(),"Error",
                            JOptionPane.ERROR_MESSAGE);
        }

    }
  public static void main(String args[])
        {
            CopyFrameDataToFile cfdf = new CopyFrameDataToFile();
            cfdf.createUI();
        }// main() closed

}// class closed









Related Tutorials/Questions & Answers:
pass data from java frame to file
pass data from java frame to file  i want to write the data to file, and data must be copy from java frame java frame contains 7-8 labels n below that 1 table. i want store all this data to 1 file. plz help me
How To Pass data from one GUI to another in java swing
How To Pass data from one GUI to another in java swing  I'm new to java and part of our assignment is to build a GUI and display a result set from data input. I'm stuck at how to get the user's input from JTextFields and combobox
Advertisements
use data from database as hyperlink and pass the data in the hyperlink
use data from database as hyperlink and pass the data in the hyperlink  Hi Friends, I am using the data from database as hyperlink and pass the data... and display tag property I have displayed a column data as hyperlink. I want to pass
Fetching the exact data from file using java
Fetching the exact data from file using java  **hi ... i am having one .lst file.. that file consists of instructions and opcodes.. now i want to fetch only the opcode from that file.. could u pls anyone guide me this using java
java program to insert data into a file and count the number of words from the file???????
java program to insert data into a file and count the number of words from the file???????  java program to insert data into a file and count the number of words from the file
Insert Data From File
Insert Data From File       Insert Data From File is  used to insert data from file... an example to insert data from file. To understand this example, we create
pass parameter - file - Java Beginners
pass parameter - file  Hi, I want to pass paramter file to method... immediately. file.jsp ========== File Parameter Use Please Select the file 2. Display.java
How to Pass data from jTextField1 in jFrame1 to jLabel1 in jFrame2
How to Pass data from jTextField1 in jFrame1 to jLabel1 in jFrame2  I have a Form login_pass (jFrame) which has a jTextField1 to take input (employee id) from the user. I want that the value of employee id given by user
Insert Data From File
Insert Data From File       Insert Data From File is  used to insert data from file... an example to insert data from file. To understand this example, we create
Data extraction from an image file.
Data extraction from an image file.  I have made an image... data from the the image which also include deleted data.Can i used java to extract these data from the image file? Which are the libraries to be used
How to export data from html file to excel sheet by using java
How to export data from html file to excel sheet by using java   reading the data from Html file
How to export data from html file to excel sheet by using java
How to export data from html file to excel sheet by using java    How to export data from html file to excel sheet by using java
convert data from pdf to text file - Java Beginners
convert data from pdf to text file   how to read the data from pdf file and put it into text file(.txt
how to go from one frame to another frame in swings - Java Beginners
how to go from one frame to another frame in swings  Hi, My task is to go from one frame to another.......... let us think that iam having two buttons on a frame........button names are ok and next........ when iam clicking
connection of java file to excel file and put data from excel file into oracle db
connection of java file to excel file and put data from excel file into oracle db  how to create button on excel sheet using java swing and how we give action to that button excel sheet? how we connect excel file to java file
Read specific column data from text file in java
Read specific column data from text file in java  My question is if my text file contain 15 columns and i want read specific column data from that text file then what code i should do
How to Retrieve Data from the database and write into excel file using Java
How to Retrieve Data from the database and write into excel file using Java  Hi, I am trying to develop an small application where i trying to retrieve Data from the database and store the details in excel file. Please can
Java Write To File From String
Java Write To File From String In this tutorial you will learn how to write to file from string. Write to file from string using java at first we will have...) and then pass the file object or file name (in case of the existing file
how to display data from jsp file into database
how to display data from jsp file into database  this is a jsp file...(); in the below example. the error is "cannot convert from java.sql.Statement to com.mysql.jdbc.Statement please help me with it. thanks <%@ page language="java
With PySpark read list into Data Frame
is used to   create data frame from RDD, a list or pandas DataFrame... the list into Data Frame in PySpark (using Python): from pyspark.sql import...({}); There is third way of creating the Data Frame from list by providing the Data
Reading the data from property file from java stand alone application in linux
Reading the data from property file from java stand alone application in linux  Please send me the example of reading the data from a property file from java stand alone application in linux. I don't know how to give path
PHP Pass Post Data
PHP Pass Post Data  How to pass POST data to the PHP-CGI
Importing data into sql plus from a text file...
Importing data into sql plus from a text file...  How to import a text file into oracle 10g enterprise edition directly to create tables and data
Importing data into sql plus from a text file...
Importing data into sql plus from a text file...  How to import a text file into oracle 10g enterprise edition directly to create tables and data
data insertion from xml file to database table
data insertion from xml file to database table  Hi all, I have data in the XML file. I need to insert it into table in the database using servlet. so please reply me . ThankYou
how to pass arraylist data from one jsp to another jsp - JSP-Servlet
how to pass arraylist data from one jsp to another jsp  hi to all iam not able to pass the data which is stroed in arraylist, actually i need to receive all employee id's that are retrived from the database in the first jsp
Exporting data from mysql to csv file
Exporting data from mysql to csv file  Hi friends.... I want to export the data from mysql to csv file... i am having 30 columns in my database.. Eg... example that retrieves the data from the database and save it into csv file
Create XML file from flat file and data insert into database
Create XML file from flat file and data insert into database... have developed an application to create xml file from flat file and data insert  into database in Java.  Two files are used "FlatFileXml.java
reading data from excel file and plotting graph
reading data from excel file and plotting graph  I am doing a project... the data in excel file, i have to plot graphs based on CELL ID selected. please help... that reads an excel file using POI api and using the data of excel file
How to read and display data from a .properties file from a jsp page
How to read and display data from a .properties file from a jsp page  I have a .properties file. I have to create a jsp page such that it reads the data from this .properties file and display it in table format. Ex:by using
How to pass variable from one class to another in java
How to pass variable from one class to another in java  How to pass variable from one class to another in java?   Example: public class Class1 { //Class1 private String name = "Class1
Get Data From the XML File
Get Data From the XML File       Here you will learn to retrieve data from XML file using SAX parser. We use the JAXP APIs to retrieve data from XML document . Description
Read from file java
Read from file java  How to Read from file java? What is the best method for a text file having a size of 10GB. Since i have to process the file one line at a time so tell me the very best method. Thank you
Retrieve Data from the database and write into excel file
Retrieve Data from the database and write into excel file. In this section, we are going to retrieve data from the database and write into the excel file...); fileOut.close(); System.out.println("Data is saved in excel file
Example program to pass value from Html to java script
Example program to pass value from Html to java script       We can also pass the values from... which will pass the value to the java script function and this value
Pass values from form to form
Pass values from form to form       Java program to pass values from one form to another form... to only pass values from one page to another consecutive page which is being
How to read data from txt file and save to database MySql - Java Beginners
How to read data from txt file and save to database MySql  Please help me again ,my problem right know is how to read data from txt file then data save to database from JButton.Please give me a tutorial and source code
Java Pass Value Example
can also pass the value from a JSP page to the java script as we have done in our... page. We can pass values from iframe to the parent page with the use of java... to java script We can also pass the values from html code to java
Show a hidden frame previously from another from
Show a hidden frame previously from another from  How can i show a hidden frame previously by this code: jframe_name.hide(); and make it visible from another frame i'm waiting for the answer, and i'll be thankfull
Java Frame
Java Frame  What is the difference between a Window and a Frame
JAXB Create XML File And Get Data From XML
JAXB Create XML File And Get Data From XML In this section we will read about how to create XML file and how to convert XML file's data to Java Object... an XML file using Java Object then we will read that XML data as Java Object
how read data from doc file in same formate in jsp
how read data from doc file in same formate in jsp  how we can read and display data on jsp page, from doc file with the same formatting
Read data from excel file and update database using jsp
Read data from excel file and update database using jsp  read data from excel file and update database using jsp Hi, I am using a MySQL database for scientific research analysis. My team members sends research data in excel file
Data needs to be gathered in XML file from the database (MySql) using JSP
Data needs to be gathered in XML file from the database (MySql) using JSP ... data regarding particular id from the database table. Data needs to be gathered in XML file from the database (MySql) using appropriate JSP/Java Bean functions
Sava data from Form to XML file using strutrs
Sava data from Form to XML file using strutrs  I'am a biginner with struts want so save data from my form in an Xml file using struts but i'm searching witout finding a solution thanks fo your help
Java read lines from file
Java read lines from file  Any code example related to Java read lines from file? In my project there is requirement of reading the file line by line... of reading file line by line in Java. Can any one share me the code for reading
Retrieve data from the database and write into ppt file
Java Retrieve data from the database & write into ppt file In this section, we are going to retrieve data from the database and write into the .ppt file... * from data"); String name = ""; String address = ""; while (rs.next
create login page using data from text file
create login page using data from text file  I want to create login page using data store in textfile(data submit from regiter page to textfile) using jsp and servlet. Thanks
Display data from xml file to Swings - Swing AWT
Display data from xml file to Swings  Hi, We are Preparing a stand alone application. Where the Swings is the front end. There will be only... clicking the buttons in swings it has to display 20 record in one shot in table
Java Read username, password and port from properties file
Java Read username, password and port from properties file In this section... the properties file and display the data from the database. Now to load the data from the properties file, we have used Properties class. This class allowed us to save data

Ads