import java.awt.*;
import java.util.Date;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import javax.swing.*;

public class MyApplet extends JApplet implements ActionListener
{
    JButton b=new JButton("查看");
    
    public void init()
    {
        b.addActionListener(this);
        Container cp=this.getContentPane();
        cp.add(b);      
    }

    public void actionPerformed(ActionEvent e)
    {
        URL url;
        try
        {
            //取得同servlet的连接
            url = new URL(getCodeBase(), "/test/testServlet");
            URLConnection con = url.openConnection();
            con.setUseCaches(false);
            //获得输入流
            InputStream in = con.getInputStream();
            ObjectInputStream objStream;
            objStream = new ObjectInputStream(in);
            //取得流中的对象
            Date d= (Date)objStream.readObject();
            //弹出消息框
            JOptionPane.showMessageDialog(this,d,"服务器时间",JOptionPane.INFORMATION_MESSAGE);
        }
        catch (Exception ee)
        {
            ee.printStackTrace();
        }
    }
}
