代码如下
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.applet.*;
import javax.swing.*;
public class temp extends JApplet
{
JPanel p1=new JPanel();
Vector t=new Vector<teacher>(1,2);
Vector s=new Vector<student>();
JDialog j=new JDialog();
JTextField jtf=new JTextField();
JPasswordField jpf=new JPasswordField();
public void init()
{
Container c=this.getContentPane();
c.setLayout(new BorderLayout());
t.addElement(new teacher("111","111"));
makeJDialog();
}
void makeJDialog()
{
Container c=j.getContentPane();
c.setLayout(new BorderLayout());
JPanel jp=new JPanel(new GridLayout(1,3));
JLabel jl=new JLabel("用户验证");
JButton exact=new JButton("确认");
jp.add(jtf);
jp.add(jpf);
jp.add(exact);
c.add(jl,BorderLayout.NORTH);
c.add(jp,BorderLayout.CENTER);
exact.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
char[] str=jpf.getPassword();
String password=new String(str);
String name=jtf.getText();
while(true)
{
if(find(new teacher(name,password)))
{
j.setVisible(false);
}
else
{
jtf.setText("");
jpf.setText("");
}
}
}
});
}
boolean find(Object temp)
{
if(temp instanceof teacher)
{
Enumeration em=t.elements();
while(em.hasMoreElements())
{
if(em.nextElement().equals((teacher)temp))
{
return true;
}
}
}
else if(temp instanceof student)
{
Enumeration em=s.elements();
while(em.hasMoreElements())
{
if(em.nextElement().equals((student)temp))
{
return true;
}
}
}
return false;
}
}
为什么没有显示呢