大家好帮我看看这个是什么错误啊??
E:\java2\Customer.java:60: exception IllegalPasswordException is never thrown in body of corresponding try statement
catch(IllegalPasswordException e)
我的程序是:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class IllegalPasswordException extends Exception
{
public String getMessage()
{
return"Invalid lenght of the password. The customer shoule not be provided ";
}
}
public class Customer extends JApplet
{
String custName;
String custPassword;
JPanel panelObject;
JLabel labelCustName;
JLabel labelCustPassword;
JTextField textCustName;
JPasswordField textCustPassword;
JButton buttonLogin;
void setPassword(String password)
{
custPassword=password;
}
void setPassWord(String password) throws IllegalPasswordException
{
if(password.length()<6||password.length()>10)
throw new IllegalPasswordException();
custPassword=password;
}
public void init()
{
panelObject = (JPanel)getContentPane();
panelObject.setLayout(new FlowLayout());
labelCustName = new JLabel("Customer Login Name");
labelCustPassword = new JLabel("Password");
textCustName = new JTextField(15);
textCustPassword = new JPasswordField(15);
buttonLogin=new JButton("Login");
panelObject.add(labelCustName);
panelObject.add(textCustName);
panelObject.add(labelCustPassword);
panelObject.add(textCustPassword);
panelObject.add(buttonLogin);
LoginAction loginrequest=new LoginAction();
buttonLogin.addActionListener(loginrequest);
}
class LoginAction implements ActionListener
{
public void actionPerformed(ActionEvent evt)
{
Object obj=evt.getSource();
if(obj==buttonLogin)
{ String password = new String(textCustPassword.getPassword()).trim();
try{
setPassword(password);
getAppletContext().showStatus("Valid entry for customer password");
}
catch(IllegalPasswordException e)
{
//System.out.print(e.getMessage());
getAppletContext().showStatus(e.getMessage());
}
}
}
}}
目的是要打输入的密码控制要6到10个字符之间!否则抛出异常!那位可以帮我看看一下!谢了!
E:\java2\Customer.java:60: exception IllegalPasswordException is never thrown in body of corresponding try statement
catch(IllegalPasswordException e)
我的程序是:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class IllegalPasswordException extends Exception
{
public String getMessage()
{
return"Invalid lenght of the password. The customer shoule not be provided ";
}
}
public class Customer extends JApplet
{
String custName;
String custPassword;
JPanel panelObject;
JLabel labelCustName;
JLabel labelCustPassword;
JTextField textCustName;
JPasswordField textCustPassword;
JButton buttonLogin;
void setPassword(String password)
{
custPassword=password;
}
void setPassWord(String password) throws IllegalPasswordException
{
if(password.length()<6||password.length()>10)
throw new IllegalPasswordException();
custPassword=password;
}
public void init()
{
panelObject = (JPanel)getContentPane();
panelObject.setLayout(new FlowLayout());
labelCustName = new JLabel("Customer Login Name");
labelCustPassword = new JLabel("Password");
textCustName = new JTextField(15);
textCustPassword = new JPasswordField(15);
buttonLogin=new JButton("Login");
panelObject.add(labelCustName);
panelObject.add(textCustName);
panelObject.add(labelCustPassword);
panelObject.add(textCustPassword);
panelObject.add(buttonLogin);
LoginAction loginrequest=new LoginAction();
buttonLogin.addActionListener(loginrequest);
}
class LoginAction implements ActionListener
{
public void actionPerformed(ActionEvent evt)
{
Object obj=evt.getSource();
if(obj==buttonLogin)
{ String password = new String(textCustPassword.getPassword()).trim();
try{
setPassword(password);
getAppletContext().showStatus("Valid entry for customer password");
}
catch(IllegalPasswordException e)
{
//System.out.print(e.getMessage());
getAppletContext().showStatus(e.getMessage());
}
}
}
}}
目的是要打输入的密码控制要6到10个字符之间!否则抛出异常!那位可以帮我看看一下!谢了!
throw new IllegalPasswordException();
custPassword=password; //这里是到大不了的代码!因为上面throw了!
}