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



Home Answers Viewqa Applet Creating a log in a text file
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


hersh
Creating a log in a text file
1 Answer(s)      6 years and 2 months ago
Posted in : Applet



Advertisement
View Answers

October 3, 2008 at 4:11 PM


Hi,


import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.Applet;
import java.net.*;

public class AppletTextDemo extends Applet{
JButton write = new JButton("WriteToFile");
Label label1 = new Label("Enter the file name:");
TextField text = new TextField(20);
Label label2 = new Label("Write your text:");
TextArea area = new TextArea(10,20);
public void init(){
add(label1);
label1.setBackground(Color.lightGray);
add(text);
add(label2);
label2.setBackground(Color.lightGray);
add(area);
add(write,BorderLayout.CENTER);
write.addActionListener(new ActionListener (){
public void actionPerformed(ActionEvent e){
new WriteText();
}
});
}
public class WriteText {
WriteText(){
try {
String str = text.getText();
if(str.equals("")){
JOptionPane.showMessageDialog(null,"Please enter the file name!");
text.requestFocus();
}
else{
File f = new File(str);
if(f.exists()){
BufferedWriter out = new BufferedWriter(new FileWriter(f,true));
if(area.getText().equals("")){
JOptionPane.showMessageDialog(null,"Please enter your text!");
area.requestFocus();
}
else{
out.write(area.getText());
if(f.canWrite()){
JOptionPane.showMessageDialog(null,"Text is written in "+str);
text.setText("");
area.setText("");
text.requestFocus();
}
else{
JOptionPane.showMessageDialog(null,"Text isn't written in "+str);
}
out.close();
}
}
else{
JOptionPane.showMessageDialog(null,"File not found!");
text.setText("");
text.requestFocus();
}
}
}
catch(Exception x){
x.printStackTrace();
}
}
}
}

----------------------
<HTML>
<BODY>
<div align = "center">
<APPLET CODE = "AppletTextDemo.class" WIDTH = "500" HEIGHT = "400"></APPLET>
</div>
</BODY>
</HTML>

------------------------------------


Visit for more information.

http://www.roseindia.net/java/

Thanks


Related Tutorials/Questions & Answers:
Creating a log in a text file - Applet
Creating a log in a text file  Hey there, I have created an applet... as an application. Therefore i have added it onto a frame. I need to create a text file... time it is run. I have figured of a way of writing the time to a text file using
How could we get log file as simple text format
How could we get log file as simple text format  Above given javaerrorlog creates the log file in xml code how could we get it in simple text Manmohan
Advertisements
a jsp code for creating a text file
a jsp code for creating a text file  Hello,i need jsp code for creating a new text file for each user, when they login in to the website for creating a new data file. So i need a jsp code for following options. when user login
Writing Log Records to a Log File
Writing Log Records to a Log File   ... to a log file. Logger provides different types of level like: warning, info and severe that have log records. Log records are written into a log file
Creating a File I/O using import scanner, io.* and text.*
Creating a File I/O using import scanner, io.* and text.*  open a file for reading and open another file for writing data. input file hours-int, hourly rate-double, name-string. output file name-string, hours-int, hourly rate
Error in log file
Error in log file  Hi, I AM using Apache tomcat 6.0.16 server... of executing project i get following errors in "Apache Tomcat 6.0.16 log". Apr 17, 2011 11:57:57 AM org.apache.catalina.core.ApplicationContext log INFO: Marking
Error in log file
Error in log file  Hi, I AM using Apache tomcat 6.0.16 server... of executing project i get following errors in "Apache Tomcat 6.0.16 log". Apr 17, 2011 11:57:57 AM org.apache.catalina.core.ApplicationContext log INFO: Marking
Error in log file
Error in log file  Hi, I AM using Apache tomcat 6.0.16 server... of executing project i get following errors in "Apache Tomcat 6.0.16 log". Apr 17, 2011 11:57:57 AM org.apache.catalina.core.ApplicationContext log INFO: Marking
Where is servlet log file in net beans?
Where is servlet log file in net beans?  When you use context.log("some string"); then the string get written into the servlet log file. But where is the servlet log file in netbeans? I am using netbeans 6.9. I can't locate
Limiting the Size of a Log File in Java
Limiting the Size of a Log File in Java  ... to limit the size of a log file in Java. Log files haven't any boundation at the file creation time but Java provides the facility for limiting the size of a log
Creating an executable jar file
Creating an executable jar file  When I try to create jar.exe through CMD, the manifest file created doesn't contain Main-Class attribute, even though it is included in text file used during creation of jar file
log in
log in  sir i designed one login.jsp page with one form, username,login,and one submit button .if i enter username and password its been verify the mydatabase in in table in the field of username and password while it s correct
text file
text file  Hello can I modify the program below so that all the numerical data is stored in an external text file,that is the data contained in the array list.Thank you! mport java.util.*; import java.text.*; import
Creating a setup file
Creating a setup file  How to create a setup file in tomcat as done in visual studio... could plz tell me as early as possible
Creating XMl file - XML
Creating XMl file   I went on this page: http://www.roseindia.net/xml/dom/createblankdomdocument.shtml and it shows me how to create an XML file, however there is something I don't understand. I have to create an XML file
creating a file in a directory
creating a file in a directory  hi i have tried all the file methods to create a file inside a directory but none of them r working some of them are new File ( ".", "C:/fileInRoot.txt" ) new File ( "myDir", "/otherDir" ) File
text file
text file  Hi can you help me I have to modify the program below so that all the data held in it is stored in an external text file.So there should... at the start of the program from a seperate external text file.Thank you! mport
I am creating one jsp page in which I read in a text file, then display that data in tabular format. Now I need to calculate a total.
I am creating one jsp page in which I read in a text file, then display that data in tabular format. Now I need to calculate a total.  I am reading the file using BufferedReader, then writing the output like this: String
i need a program that will generate daily base log file dynamically - Log4J
i need a program that will generate daily base log file dynamically  i need a program that will generate daily base log file dynamically... produce a log file with today date and when next day comes, again it ll produce
Creating an exe file
Creating an exe file  Hi All, I have developed java application using swing by Net Beans IDE. Now I need to convert my application into exe file... as an exe file. Please anyone suggest me.Thanks in Advance. Thanks, T.Thanga meena
How to delete content of a log file from linux terminal?
How to delete content of a log file from linux terminal?  Hi, My... of the mysql log file: cat /dev/null > /var/log/slow-queries.log Thanks... running queries. But first I want to delete the content of the /var/log/slow
creating an .exe file - Java Beginners
creating an .exe file  how to create an .exe file in java? thanks in advance
Creating a File in the directory.
Creating a file using HTML form action In this example, you will learn to make a query form asking to to create a file in PHP. You will have to write... of PHP code in the form. for creating a file in PHP, first declare a file name
Reading a text file in java
Reading a text file in java  What is the code for Reading a text file... in java.io.* package for reading and writing to a file in Java. To learn more about reading text file in Java see the tutorial Read File in Java. Thanks
creating a jar file - JSP-Servlet
creating a jar file  Can you give me detail answer 1. i am having a servlet.class file in classes folder 2. web.xml file my questions are 1. where to place the html or jsp files 2. how to create a jar file and how can
Convert Text File to PDF file
Convert Text File to PDF file  Here is the way how to covert your Text file to PDF File, public class TextFileToPDF { private static void...(inLine); System.out.println("Text is inserted into pdf file
Sorting text file
Sorting text file  Hello friends, i'm writing search page for my local website. i'm storing all file list in text file. And also adding a value... according to begin value. Text File having list like this: 5| 3| can anyone
inserting text into text file using java application
inserting text into text file using java application  Hi, I want to insert a text or string into a text file using java application
Creating JAR File - Java Beginners
Creating JAR File  Respected Sir, I would like you to please help me, in letting me know, as to how to create JAR file from my JAVA source or class files. And what is this manifest file, and what changes needs to be done
Creating JAR File - Java Beginners
Creating JAR File  Respected Sir, Thankyou very much for your... to change the contents of my manifest file. I read somewhere regarding i have to add a line to my manifest file (i.e. Main-Class: mypackage.MyClass
how to update the text file?
how to update the text file?  if my text file contains a string and integer in each line say,: aaa 200 bbb 500 ccc 400 i need a java code to update the integer value if my input String matches with the string in file. please
Advertisements
 

 

 

DMCA.com