package yan1;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
class  PasException extends Exception
{
 
 public String getMessage(){
  return "password is error";
 
 }
 
 
 
}
public class Yan2 extends JApplet implements ActionListener
{String name;
String custompassword;
JPanel panelobj;
JLabel labname;
JLabel lanpassword;
JButton button;
JTextField text1;
JPasswordField text2;
void setPassword(String password) throws  PasException(){
 if(password.length()<6||password.length()>10)
  throw new PasException();
 else
  custompassword=password;
}public void init(){
 panelobj=new JPanel();
 getContentPane().add(panelobj);
 FlowLayout layout=new FlowLayout(FlowLayout.RIGHT,5,5);
 panelobj.setLayout(layout);
 labname=new JLabel("custom name:");
 lanpassword=new JLabel("password:");
 text1=new JTextField(15);
 text2=new JPasswordField(5);
 button=new JButton("logn");
 panelobj.add(labname);
 panelobj.add(text1);
 panelobj.add(lanpassword);
 panelobj.add(text2);
 panelobj.add(button);
 button.addActionListener(this);
 }
 
 
public void actionPerformed(ActionEvent evt) {
 Object obj=evt.getSource(); 
 if(obj==button) 
 {name=text1.getText();
 custompassword=new String(text2.getPassword());
    String entry=name+":"+custompassword;
      if(name.length()==0)
      {
    getAppletContext().showStatus("jiang gao!");      }
     if(custompassword.length()==0)
     { getAppletContext().showStatus("jiang gao!");
      
     }
     else
     {try
     {setPassword(custompassword);
   
     }
 
 catch( PasException e)
 {
 
 getAppletContext().showStatus(e.getMessage());
 
 return;
 
 
 }
 }
 try{
  File fileobj=new File("d:\\yan.txt");
 RandomAccessFile log=new RandomAccessFile(fileobj,"rw"); 
  log.seek(log.length());
 log.writeBytes(entry);
 
 
 }
 catch(IOException e)
 {
 
 
 getAppletContext().showStatus("not write to file");
 
 
 
 
 }
 }
}
}有两出错误请高手解决!

解决方案 »

  1.   

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    class  PasException extends Exception
    {
     
     public String getMessage(){
      return "password is error";
     
     }
     
     
     
    }
    public class Yan2 extends JApplet implements ActionListener
    {String name;
    String custompassword;
    JPanel panelobj;
    JLabel labname;
    JLabel lanpassword;
    JButton button;
    JTextField text1;
    JPasswordField text2;
    void setPassword(String password) throws  PasException
    {
     if(password.length()<6||password.length()>10)
      throw new PasException();
     else
      custompassword=password;
    }public void init(){
     panelobj=new JPanel();
     getContentPane().add(panelobj);
     FlowLayout layout=new FlowLayout(FlowLayout.RIGHT,5,5);
     panelobj.setLayout(layout);
     labname=new JLabel("custom name:");
     lanpassword=new JLabel("password:");
     text1=new JTextField(15);
     text2=new JPasswordField(5);
     button=new JButton("logn");
     panelobj.add(labname);
     panelobj.add(text1);
     panelobj.add(lanpassword);
     panelobj.add(text2);
     panelobj.add(button);
     button.addActionListener(this);
     }
     
     
    public void actionPerformed(ActionEvent evt) {
     Object obj=evt.getSource(); 
     if(obj==button) 
     {name=text1.getText();
     custompassword=new String(text2.getPassword());
        String entry=name+":"+custompassword;
          if(name.length()==0)
          {
        getAppletContext().showStatus("jiang gao!");      }
         if(custompassword.length()==0)
         { getAppletContext().showStatus("jiang gao!");
          
         }
         else
         {try
         {setPassword(custompassword);
       
         }
     
     catch( PasException e)
     {
     
     getAppletContext().showStatus(e.getMessage());
     
     return;
     
     
     }
     }
     try{
      File fileobj=new File("d:\\yan.txt");
     RandomAccessFile log=new RandomAccessFile(fileobj,"rw"); 
      log.seek(log.length());
     log.writeBytes(entry);
     
     
     }
     catch(IOException e)
     {
     
     
     getAppletContext().showStatus("not write to file");
     
     
     
     
     }
     }
    }
    }
      

  2.   

    void setPassword(String password) throws  PasException(){
      多了()