freelanceprogrammers.org Forum Index » Java
printing file`s contenet into a JTextArea..can i do it???
Joined: 12 Apr 2004
Posts: 2
printing file`s contenet into a JTextArea..can i do it???
dearest friends :
hope u r fine
well.. i wanna ask u how could i insert a file content into a JTextArea
plz tell me how???
i neeeeed alot..plz help me???
many many thx in advance
---------------------------------
Do you Yahoo!?
Yahoo! Tax Center - File online by April 15th
[Non-text portions of this message have been removed]
Joined: 12 Apr 2004
Posts: 1
printing file`s contenet into a JTextArea..can i do it???
I think u got a really nice name Rasha Naimi , I only hope u`re a nice person
too........
---------------------------------
Do you Yahoo!?
Yahoo! Tax Center - File online by April 15th
[Non-text portions of this message have been removed]
Joined: 11 Apr 2004
Posts: 11
printing file`s contenet into a JTextArea..can i do it???
mohammad Bahnacy wrote:
> hi Rasha
> i hope you are fine
> this a small program that insert a text file content in a JTextArea
> Press File, Open, and select the file you wanna insert its content, and then
perss
> Open Button.
> i hope the prog to be helpful
> bye
> Rasha Naimi <rasha_naimi@...> wrote:
> dearest friends :
> hope u r fine
>
> well.. i wanna ask u how could i insert a file content into a JTextArea
> plz tell me how???
> i neeeeed alot..plz help me???
>
> many many thx in advance
If you sent that program as an attachment, you need to be aware
that this list does not allow attachments and all attachments are
stripped off before distribution to the list members.
--
Dale Erwin
Salamanca 116
Pueblo Libre
Lima 21 PERU
Tel. +51(1)461-3084
Cel. +51(1)9743-6439
DALE ERWIN`S OPERA FILES - http://www.geocities.com/dale_erwin
Joined: 14 Apr 2004
Posts: 4
printing file`s contenet into a JTextArea..can i do it???
hi Rasha
i hope you are fine
this a small program that insert a text file content in a JTextArea
Press File, Open, and select the file you wanna insert its content, and then
perss
Open Button.
i hope the prog to be helpful
bye
Rasha Naimi <rasha_naimi@...> wrote:
dearest friends :
hope u r fine
well.. i wanna ask u how could i insert a file content into a JTextArea
plz tell me how???
i neeeeed alot..plz help me???
many many thx in advance
---------------------------------
Do you Yahoo!?
Yahoo! Tax Center - File online by April 15th
[Non-text portions of this message have been removed]
---------------------------------
Yahoo! Groups Links
To visit your group on the web, go to:
http://groups.yahoo.com/group/beginnersclub/
To unsubscribe from this group, send an email to:
beginnersclub-unsubscribe@yahoogroups.com
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
---------------------------------
Do you Yahoo!?
Yahoo! Small Business $15K Web Design Giveaway - Enter today
[Non-text portions of this message have been removed]
Joined: 14 Apr 2004
Posts: 4
printing file`s contenet into a JTextArea..can i do it???
Dale Erwin <daleerwin@...> wrote:mohammad Bahnacy wrote:
> hi Rasha
> i hope you are fine
> this a small program that insert a text file content in a JTextArea
> Press File, Open, and select the file you wanna insert its content, and then
perss
> Open Button.
> i hope the prog to be helpful
> bye
> Rasha Naimi <rasha_naimi@...> wrote:
> dearest friends :
> hope u r fine
>
> well.. i wanna ask u how could i insert a file content into a JTextArea
> plz tell me how???
> i neeeeed alot..plz help me???
>
> many many thx in advance
If you sent that program as an attachment, you need to be aware
that this list does not allow attachments and all attachments are
stripped off before distribution to the list members.
--
Dale Erwin
Salamanca 116
Pueblo Libre
Lima 21 PERU
Tel. +51(1)461-3084
Cel. +51(1)9743-6439
DALE ERWIN`S OPERA FILES - http://www.geocities.com/dale_erwin
---------------------------------
Yahoo! Groups Links
To visit your group on the web, go to:
http://groups.yahoo.com/group/beginnersclub/
To unsubscribe from this group, send an email to:
beginnersclub-unsubscribe@yahoogroups.com
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
Thanx alot Dale
I really didn`t know that.
so this the code
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileView;
import javax.swing.border.*;
import java.io.*;
import java.util.*;
public class insert
{
public static void main (String[] args)
{
myframe frame =new myframe();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}
class myframe extends JFrame implements ActionListener
{
public static final int width =350;
public static final int height =200;
JFileChooser chooser = new JFileChooser();
JPanel panel =new JPanel();
Container contentpane =getContentPane();
JMenuBar menuBar=new JMenuBar();
JMenu fileMenu =new JMenu("FILE");
JMenuItem openFile =new JMenuItem("OPEN");
JMenuItem exitFile =new JMenuItem("EXIT");
JTextArea textareaINPUT =new JTextArea(2,20);
StringBuffer CipherText=new StringBuffer();
public myframe()
{
setTitle("INSERT A TEXT FILE CONTENT");
setSize(width,height);
contentpane.add(panel);
setJMenuBar(menuBar);
menuBar.add(fileMenu);
fileMenu.add(openFile);
openFile.addActionListener(this);
fileMenu.add(exitFile);
panel.setBackground(Color.red);
textareaINPUT.setEditable(false);
textareaINPUT.setText(" INPUT_ FILE");
JScrollPane scrollpaneINPUT=new JScrollPane(textareaINPUT);
contentpane.add(scrollpaneINPUT);
contentpane.add(textareaINPUT);
contentpane.add(textareaINPUT);
}
public void actionPerformed(ActionEvent p1)
{
if(p1.getSource()==openFile)
{
chooser.setCurrentDirectory(new File("."));
ExtensionFileFilter filter = new ExtensionFileFilter();
filter.addExtension("txt");
filter.setDescription("text files");
chooser.setFileFilter(filter);
int result = chooser.showOpenDialog(myframe.this);
if (result == JFileChooser.APPROVE_OPTION)
{
String name = chooser.getSelectedFile().getPath();
try{
RandomAccessFile f=new RandomAccessFile(name,"r");
StringBuffer fileContent=new StringBuffer();
String s=f.readLine();
while(s!=null)
{
fileContent.append(s+"
");
s=f.readLine();
}
textareaINPUT.setText(fileContent.toString());
}
catch(Exception e){}
}
}
else if (p1.getSource()==exitFile)
{
System.exit(0);
}
}
}
class ExtensionFileFilter extends FileFilter
{
public void addExtension(String extension)
{
if(!extension.startsWith("."))
extension = "." + extension;
extensions.add(extension.toLowerCase());
}
public void setDescription(String aDescription)
{
description = aDescription;
}
public String getDescription()
{
return description;
}
public boolean accept(File f)
{
if(f.isDirectory()) return true;
String name = f.getName().toLowerCase();
for(int i =0 ; i<extensions.size(); i++)
if (name.endsWith((String)extensions.get(i)))
return true;
return false;
}
private String description = " ";
private ArrayList extensions = new ArrayList();
}
i hope to be helpful
bye
---------------------------------
Do you Yahoo!?
Yahoo! Tax Center - File online by April 15th
[Non-text portions of this message have been removed]
Joined: 12 Apr 2004
Posts: 2
printing file`s contenet into a JTextArea..can i do it???
hope u r fine freinds
i would like 2 ask u
ive this code
String file_name=JOptionPane.showInputDialog("will you please enter the file
name with its extention.E.g "program.txt"...
That must be availabe in the
same folder that contains this program
");
// to make FileReader object to read from the source file ( text file)
FileReader filereader1 =new FileReader(file_name);
BufferedReader data = new BufferedReader(filereader1);
// testing whether the file exists or not
/*if ( condition )
i dunno what should i test here to make sure that the name of the file i enterd
is existing or no
{
JOptionPane.showMessageDialog(null,"Sorry...but there is somthing worng with
the file..please check the source_code file`s name again ");
System.exit(0);
}*/
how can i test the file if its available or not???
and when its not it should give a msg that the file is not availabele...what
should i doo??
if u want 2 change some of statments in the code above its ok with me...but hope
it will work
plz help
many many thx in advance
---------------------------------
Do you Yahoo!?
Yahoo! Tax Center - File online by April 15th
[Non-text portions of this message have been removed]
Joined: 16 Apr 2004
Posts: 4
printing file`s contenet into a JTextArea..can i do it???
Hi Rasha,
that`s easy. Just take the name as entered by the user and create a
new File out of this name, like this:
File testMe = new File( file_name);
This instance of the File class is just an object in memory, it does
not yet refer to any existing file. BUT: you can ask this File
instance whether a real thing with this name exists, namely by:
if (testMe .exists() && testMe .canRead())
// all right, file is there and can be read.
...
else
JOptionPane.showMessageDialog(null,"Sorry...but there is
something wrong with the file. Please check the source code file`s
name again.");
And the best way to make sure that this is done until a real file
name has been entered is a loop like this:
String fileName;
File testMe;
boolean fileIsOk;
do
{ fileName = JOptionPane .showInputDialog( "Please enter file name
plus extension.");
testMe = new File( fileName);
fileIsOk = testMe .exists() && testMe .canRead();
if ( ! fileIsOk)
JOptionPane .showMessageDialog( (null, "Sorry...but there is
something wrong with the file. Please check the source code file`s
name again.");
} while ( ! fileIsOk);
I haven`t tried this code, you should check for the return values of
the show...Dialog() functions because if I recall correctly
showInputDialog() returns something else if you click Abort in the
entry form. But the general outline above should do the trick.
Regards,
Nico
--- In beginnersclub@yahoogroups.com, Rasha Naimi <rasha_naimi@y...>
wrote:
>
> hope u r fine freinds
>
> i would like 2 ask u
>
> ive this code
>
> String file_name=JOptionPane.showInputDialog("will you please enter
the file name with its extention.E.g "program.txt"...
That must be
availabe in the same folder that contains this program
");
>
>
> // to make FileReader object to read from the source file ( text
file)
>
> FileReader filereader1 =new FileReader(file_name);
> BufferedReader data = new BufferedReader(filereader1);
>
> // testing whether the file exists or not
>
> /*if ( condition )
>
> i dunno what should i test here to make sure that the name of the
file i enterd is existing or no
> {
> JOptionPane.showMessageDialog(null,"Sorry...but there is
somthing worng with the file..please check the source_code file`s
name again ");
> System.exit(0);
> }*/
>
> how can i test the file if its available or not???
>
> and when its not it should give a msg that the file is not
availabele...what should i doo??
<snip>
All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help
China Wholesale - Electronics Products
Character Studio - Tutorials and Help







