Home Answers Viewqa Java-Beginners Create and Show Wordpad File on JButton Click

 
 


shweta
Create and Show Wordpad File on JButton Click
1 Answer(s)      3 years and a month ago
Posted in : Java Beginners

Hello Sir I want to create wordpad or word document on JButton Click Event.which contains data which is currently on Form ie filled by User,
with following format
STUDENT ADMISSION FORM
STUDENT ID: (JTextField1Value currenly on Form)

NAME: (JTextField2Value currenly on Form)

ADDRESS: (JTextField3Value currenly on Form)

CITY : (JTextField4Value currenly on Form)

plz Help Me.
View Answers

April 22, 2010 at 3:05 PM


Hi Friend,

Try the following code:

import java.io.*;
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.usermodel.*;
import org.apache.poi.hwpf.usermodel.Range;
import org.apache.poi.poifs.filesystem.*;
class Form extends JFrame{

JButton ADD;
JPanel panel,pan;
JLabel label1,label2,label3,label4;
final JTextField text1,text2,text3,text4;
Form() {
label1 = new JLabel();
label1.setText("Student Id:");
text1 = new JTextField(20);

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

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

label4 = new JLabel();
label4.setText("City:");
text4 = new JTextField(20);
ADD=new JButton("Add");

panel=new JPanel(new GridLayout(5,2));
panel.add(label1);
panel.add(text1);
panel.add(label2);
panel.add(text2);
panel.add(label3);
panel.add(text3);
panel.add(label4);
panel.add(text4);
panel.add(ADD);
add(panel,BorderLayout.CENTER);
setTitle("FORM");

ADD.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
String data="STUDENT ADMISSION FORM\n\n\nSTUDENT ID: "+text1.getText()+"\nNAME: "+text2.getText()+"\nADDRESS: "+text3.getText()+"\nCITY: "+text4.getText();
writeToFile(data, "Employee.doc");
JOptionPane.showMessageDialog(null,"Inserted into File");
}
});
}
private static void writeToFile(String content, String path) {
try{
POIFSFileSystem fs = new POIFSFileSystem();
DirectoryEntry directory = fs.getRoot();
directory.createDocument("WordDocument", new ByteArrayInputStream(content.getBytes()));
FileOutputStream out = new FileOutputStream(path);

fs.writeFilesystem(out);
out.close();
}
catch(Exception ex){
System.out.println(ex.getMessage());
}
}
}
class InsertToFile{
public static void main(String arg[]) {
try
{
Form frame=new Form();
frame.setSize(300,300);
frame.setVisible(true);
}
catch(Exception e)
{}
}
}

To run the above code, you need POI api.

Thanks









Related Pages:
Create and Show Wordpad File on JButton Click - Java Beginners
Create and Show Wordpad File on JButton Click  Hello Sir I want to create wordpad or word document on JButton Click Event.which contains data which...; import org.apache.poi.poifs.filesystem.*; class Form extends JFrame{ JButton
Open TextFile on JButton Click - Java Beginners
Open TextFile on JButton Click  Hello Sir I Want to open TextFile on JButton Click. plz Help Me  Hi Friend, Do you want to simply open the text file or you want to open the file using JFileChooser,read that file
How to Open Text or Word File on JButton Click in Java - Java Beginners
How to Open Text or Word File on JButton Click in Java  How to Open Text or Word File on JButton Click in Java
Open Text or Word Document on JButton Click in Java - Java Beginners
Open Text or Word Document on JButton Click in Java  How to open Word document or Text File on JButton Click in java  Hi Friend, Try... JFrame{ JButton ADD; JPanel panel,pan; JLabel label1,label2,label3,label4
Java Swing : JButton Example
Java Swing : JButton Example In this section we will discuss how to create...()); JButton button=new JButton("Click"); button.addActionListener(new... object of Button as - JButton button=new JButton("Click"); addActionListener
css click box
css click box  I wanted to create a click box in CSS with a hyperlink that should appears flat.   Find the below given code.. In your HTML file .. click box Text CSS a { display:inline-block; width:30px
Jbutton[] background & foregroundcolor change
Jbutton[] background & foregroundcolor change  how to change the color of the selected JButton in java swing. I am create JButton in an array JButton button[]=new JButton[100]; if i select button[5] then the Jbutton
3D JButton in java?
3D JButton in java?  how we can create 3D button in java. thanks
jbutton
jbutton  How to use enter function in jbutton?plzz help
Jbutton
Jbutton  How to get the enter key function in multiple jbutton
Show Confirmation Dialog on Click the Command Link
Show Confirmation Dialog on Click the Command Link  How to show Confirmation Dialog when user Click the Command Link
how to open a file with a jbutton? - Java Beginners
how to open a file with a jbutton?  Hello Is it possible that by clicking on a button it can open java html file or doc exists on the pc? I searched and I found that it is possible to open a web page so I tried to open
HTML File Upload
; HTML File Upload is used to show the list of all file, when a user click... an example from HTML File Upload. In this code, we create a html page which show you...;input type="file> is used to create a upload file with a text box
Hide/show Image by click
Hide/show Image by click In this tutorial ,we will discuss about how to display image by click using jQuery. In the below example, a image and two lines... as well. But when we click on remaining line , it will display the image again
jQuery to Show Data Randomly
Randomly Step 1:         Create php file to that prints...)]; ?> Step 2: Write HTML page to call the script.php. Create a new file... jQuery to Show Data Randomly      
JFrame Close On Button Click
JFrame Close On Button Click In this section we will discuss about how to close frame on click on the button. This example explains you how a frame can... you a simple example which will demonstrate you about how to create a frame
iPhone Button Click Sound
the application to listen the sound on button click. The sound file that i have used... iPhone Button Click Sound In this series of iPhone button tutorial, we are going to create a small iphone application that is going to play a sound
cannot open .jar files by double click
cannot open .jar files by double click  I'm having a problem i create a .jar file in net beans and yesterday it work right b y and double click but i installed jre 7 and i got some errors and i uninstall the jre 7 and now i get
Adding a Rollover and Pressed Icon to a JButton Component in Java
about adding event i.e. the rollover and click icon to a JButton component of swing... Adding a Rollover and Pressed Icon to a JButton Component in Java... above the Button then your icon or image should be changed. When you click
When i click on Monitor Tomcat, it shows
When i click on Monitor Tomcat, it shows   To run servlet i have seen... installed java 7 and tomcat 7, when i click on Monitor Tomcat it shows... folder of apache tomcat. 1)create a servlet. import java.io.*; import
When i click on Monitor Tomcat, it shows
When i click on Monitor Tomcat, it shows   To run servlet i have seen... installed java 7 and tomcat 7, when i click on Monitor Tomcat it shows... folder of apache tomcat. 1)create a servlet. import java.io.*; import
Problem in show card in applet.
can I show all the card in the applet. Work I have done:- 1) Create Dynamic web...Problem in show card in applet.  The following link contained... but Not show card in the applet, then I add a code in paintComponent method like
Show output as a xml file using Velocity
Show output as a xml file using Velocity       This Example shows you how to show output as a xml file...:- Create object of VelocityContext Class. 3:- Create Template class object
How To Create a New File
How To Create a New File In this section we will discuss about how to create... store String, characters, numbers etc. In Java to create a File for storing... which will demonstrate you about how to create a new file in Java
Text change and click events
Text change and click events  Create user login form and apply textchange and click events in java
hide and show result in jsp
hide and show result in jsp  what codes do i have to change to make my result display if only i enter the correct value? suppose if i click search... or after my while statement in search.jsp file. please help. thank you so much
click on check box
click on check box  I create a check box in HTML and when i click on my check box relative information in page store in database
How to hide and show some field on a radio button click
How to hide and show some field on a radio button click  This is my code part:- PAYMENT DETAILS <table cellpadding="0" cellspacing="0" align="center" border="5" bordercolor="#003333" align="center" width="70%">
How to Create JSP Page
; In this section we will show you how you can create JSP page and then test... can be used. In this example I will show you how to create a simple JSP page...;date.jsp" and click on the "Save" button.   Note that the file
jquery button click
jquery button click  jquery button click - I have created a button in JQuery but the problem is that it's not detecting click. What could... to create a button event in JQuery. You can edit it as per your requirement. In Header
Select your project and right click on the it
;persistence.xml" in File name text box and click on "Finish" button... is appear on the screen. Click on project and go lib then all jars file is open...;JPACRUDApplication" project and right click on it. Select New => Package
Hide/Show paragraph by button click
Hide/Show paragraph by button click In this tutorial, we will discuss about... displays another button "click to show paragraph " .when we click...;); }); $("#butt2").click(function () { $("p").show("slow"
create
create  how to create an excel file using java
Java Swing Create XML file
Java Swing Create XML file In this tutorial, you will learn how to create XML file using swings. Here is a code that accepts the data from the user through... and fetch all the data from textfields and create an xml file with proper
Java JButton Key Binding Example
Java JButton Key Binding Example In this section we will discuss about how... example which will demonstrate you about how to bind Enter key on JButton.... In this method I have used JFrame to create a JFrame as well as used some other
Image Slide Show using 'Space gallery' plug-in
Image Slide Show using  'Space gallery' plug-in In this tutorial , we will create a slide show using 'Space gallery' plug-in .In this example , two tabs are given. in one tab 'Space gallery' slide show
How to create XML from Swings
How to create XML from Swings  How to create XML using Swings. I have a Swing GUI and capturing all data from it.When i click on submit, an xml... components and display it in xml file. import java.io.*; import java.util.*; import
Show text by button click using jQuery
Show text by button click using jQuery In this tutorial, we will discuss about hide/show text by clicking on button. In the below example, there are two buttons : hide and show .The "hide " button is used to hide text
Java Create Directory
The following example will show how to Create Directory in Java. Though this can be created by using mkdir() also, the following program has used file object... of the program. For this we cerate a file object in File class which will create a new
Show Balance
Show Balance  Hi I have a simple program I put together and it runs... and subtract num2 from num1 and show the remaining balance.... any help... JTextField text3=new JTextField(20); JButton button=new JButton("Calculate
Create Tag Library Descriptor (TLD) File
these steps to create the file:   1. Go to project option and right click... Create Tag Library Descriptor (TLD) File  ..., we learn how to create library descriptor file in your project. Developers can
Create and Save Excel File in JSP
Create and Save Excel File in JSP  ... file.  To create an excel sheet we can use third party API which is Apache.... The java.io.InputStream class is used to create file. We are creating an excel file
Non Editable Text File in java - Java Beginners
Non Editable Text File in java  Hello Sir ,I want to Show NonEditable TextFile on JButton Click which Contains User Manual of Project ,How I can Do It. plz Help Me
Open a .doc file by click on the link using struts - Struts
Open a .doc file by click on the link using struts   I want to open a doc extension file when i click a link on jsp page .I know only about which is write in web.xml but not exactly know how i do this.Plz any one can help me
Show message and confirm dialog box
Show Message and Confirm Dialog Box - Swing Dialogs       This section show you how to display several.... Once you click on the first button then the simple message box will open which
Copy a file to other destination and show the modification time of destination file
Copy a file to other destination and show the modification time of destination file      .... If destination file is not found in given directory this will create a new file and write
Show Hyperlink in HTML Page
code show you a HTML page, that create a link to another page. The code begins... page, Now we create another page that in which user can click on image... Show Hyperlink in HTML Page   
iPhone Create SubView
iPhone Create SubView In this tutorial, we are going to show you how to create... file, create a "IBOutlet UIView* myheader;" and write a property.... In the same ViewController.m file create a interface as i did ... @interface
How to generate pdf file on click of the links using jsp..
How to generate pdf file on click of the links using jsp..  How to generate the pdf file using jsp file. Generate table in pdf by using jsp.   Here is an example that will generate a pdf file into c drive.The pdf file
How to show next question from database on the click of next button..(Struts & Hibernate)
How to show next question from database on the click of next button..(Struts...?pageName=2&iid=<%=Id%>"><img src="images/edit-icon.png" title="Click Here To Update This Lists" alt="Click Here To Update This Stream"></a>

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.