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



Home Answers Viewqa Swing-AWT pass data from java frame to file

Have Programming Question? Ask it here!
 
 
 


aniket pawar
pass data from java frame to file
2 Answer(s)      a year and 6 months ago
Posted in : Swing AWT


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


Advertisement
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
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
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
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
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
Insert Data From File
Insert Data From File       Insert Data From File is  used to insert data from file... to insert data from file. To understand this example, we create a table 'Stu_Table
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
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
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
Insert Data From File
Insert Data From File       Insert Data From File is  used to insert data from file. Understand with Example The Tutorial illustrate an example to insert data from
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
PHP Pass Post Data
PHP Pass Post Data  How to pass POST data to the PHP-CGI
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
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 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
Java Frame
Java Frame  What is the difference between a Window and a Frame
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
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
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
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
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
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
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
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...). Create a file "FlatFileXml.java"  used to create an XML and data
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... (EmployeeDetails.java) that retrieves data from it. When you run the program it asks for a file
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
Is Java pass-by-reference?
Is Java pass-by-reference?  Is Java pass-by-reference
Pass values from form to form
Pass values from form to form       Java program to pass values from one form to another form in JSP There are many occasions when the programmer need to pass some value to many
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
Pass by Reference - Java Beginners
Pass by Reference  Hi Friends, What is Pass by value and Pass by Reference?can u please explain with examples.is java supports Pass by reference...); } } Java programming language does not pass objects by reference
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
pass method reference in java
pass method reference in java  How to pass method reference in Java
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
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... to write the Java Objects into a XML file and unmarshal() method to read XML
call frame - Java Beginners
call frame   dear java, I want to ask something about call frame to another frame and back to first frame. I have FrameA and FrameB. In frameA...(); rb5.setText("Icon from a JPEG file"); rb5.setActionCommand(FILE_ICON
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
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
how to pass variable from simple java main class(not servlet) to the jsp page?
how to pass variable from simple java main class(not servlet) to the jsp page?  I have a simple Java class in which I invoke a call to a JSP page... from the simple Java class to the JSP page. How can I do that? Here is my
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
Java Frame/ Applet /swing/awt
Java Frame/ Applet /swing/awt  I have produced a .exe file with the help of .jar file................... Now How can I Protect my software( .exe ) file bulid in Java from being Copy and Paste....????????? please reply
Drag and Drop components from one frame to another frame
Drag and Drop components from one frame to another frame... button etc.) from one frame to another frame. In this code we have used...(); } } Compile this java code with javac command  from command
java pass by reference
java pass by reference  i understood java always pass arguments by pass by value so that the original value does not change...... but i want to know how we change the value and make it effect the original value by passing
 

 

 

DMCA.com