Articles
|
News
|
Weblogs
|
Books
|
Forums
Artima Forums
|
Articles
|
Weblogs
|
Java Answers
|
News
Sponsored Link
•
Java Answers Forum
please check this code
1
reply on
1
page.
Most recent reply
: Jul 3, 2003 2:08 PM by
mmm
Welcome
Guest
Sign In
Back to Topic List
Reply to this Topic
Search Forum
Threaded View
Previous Topic
Next Topic
Flat View: This topic has
1
reply on
1
page
lazza
Posts: 3
Nickname: lazza
Registered: Jun, 2003
please check this code
Posted: Jul 3, 2003 1:34 AM
Reply
Advertisement
I am trying to write from a textfield to a file. The code I have written appears to be ok with the compiler, but when I try and send it to a file I get an error message in the textfield, can sombody please help
String newdata;
TextField tfn;
Button b1;
private void writedata(String arg) throws IOException
{
DataOutputStream os;
os=new DataOutputStream(new FileOutputStream("c:\\info.txt"));
os.writeBytes(arg);
os.close();
}
public void init()
{
tfn=new TextField(30);
add (tfn);
b1=new Button("Write text");
add(b1);
}
public boolean action(Event evt, Object arg)
{
if(evt.target==b1)
{
newdata=tfn.getText();
try
{
writedata(newdata);
}
catch(java.lang.Exception e) {tfn.setText("error while writing");}
repaint();
}
return true;
}
mmm
Posts: 2
Nickname: m3
Registered: Jul, 2003
Re: please check this code
Posted: Jul 3, 2003 2:08 PM
Reply
You might want to add an actionlistener to your button.
So modify your init() to the following:
public void init()
{
tfn=new TextField(30);
add (tfn);
b1=new Button("Write text");
// modification
b1.addActionListener(this);
// modification
add(b1);
}
Flat View: This topic has
1
reply on
1
page
Previous Topic
Next Topic
Sponsored Links
Web
Artima.com
Copyright
© 1996-2019 Artima, Inc. All Rights Reserved. -
Privacy Policy
-
Terms of Use