Doubt in java programming....?
import java.io.*;Everything works fine while compiling and executing but unable to create the output text file.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/*<Applet code="p" height=400 width=400></applet>*/
public class p extends JApplet implements ActionListener
{
JLabel l1,l2;
JButton b;
JTextField f1,f2;
String str;
public void init()
{
l1=new JLabel("username");
l2=new JLabel("password");
b=new JButton("submit");
f1=new JTextField(20);
f2=new JTextField(20);
FlowLayout f=new FlowLayout(100,20,25);
Container c=getContentPane();
c.setLayout(f);
b.addActionListener(this);
c.add(l1);
c.add(f1);
c.add(l2);
c.add(f2);
c.add(b);
}
public void actionPerformed(ActionEvent e)
{
Object o=e.getSource();
if(o==b)
{
repaint();
str=f1.getText()+" "+f2.getText();
RandomAccessFile r=null;
try
{
//String dir="mohit";
r=new RandomAccessFile("mo.txt","rw");
r.writeBytes(str);
r.close();
}
catch(Exception ee)
{ }
//r.close();
}
}
public void paint(Graphics g)
{
g.drawString(str,100,200);
}
}
Can any one help me to find the mistakes.