⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 guestbook.java

📁 模拟留言簿的网络程序,请收下
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                c.insets=new Insets(3,0,0,5);        c.fill=GridBagConstraints.NONE;        c.anchor=GridBagConstraints.WEST;        c.gridwidth=GridBagConstraints.REMAINDER;        tf1=new TextField("",32);       	gridbag.setConstraints(tf1,c);       	add(tf1);                c.insets=new Insets(3,5,0,0);        c.gridwidth=1;        c.fill=GridBagConstraints.NONE;        c.anchor=GridBagConstraints.EAST;        label = new Label("邮箱地址(可选项):");        gridbag.setConstraints(label,c);       	add(label);                c.insets=new Insets(3,0,0,5);        c.gridwidth=GridBagConstraints.REMAINDER;        c.fill=GridBagConstraints.NONE;        c.anchor=GridBagConstraints.WEST;        tf2=new TextField("",32);       	gridbag.setConstraints(tf2,c);       	add(tf2);       	        c.insets=new Insets(8,5,0,5);        c.gridwidth=GridBagConstraints.REMAINDER;        c.fill=GridBagConstraints.NONE;        c.anchor=GridBagConstraints.CENTER;        label = new Label("您可以在下面书写任何留言内容");        gridbag.setConstraints(label,c);       	add(label);       	c.insets=new Insets(3,5,3,5);        c.gridwidth=GridBagConstraints.REMAINDER;;        c.fill=GridBagConstraints.BOTH;        ta1=new TextArea("",6,66);       	gridbag.setConstraints(ta1,c);       	add(ta1);        c.insets=new Insets(3,5,3,0);        c.gridwidth=2;        c.fill=GridBagConstraints.HORIZONTAL;        sendButton =new tButton("发送");       	gridbag.setConstraints(sendButton,c);       	add(sendButton);        c.insets=new Insets(3,0,3,0);        tButton b=new tButton("清除");       	gridbag.setConstraints(b,c);       	add(b);        c.insets=new Insets(3,0,3,5);       	c.gridwidth=GridBagConstraints.REMAINDER;        b=new tButton("退出");       	gridbag.setConstraints(b,c);       	add(b);      	c.insets=new Insets(3,5,3,5);        c.gridwidth=GridBagConstraints.REMAINDER;;        c.fill=GridBagConstraints.BOTH;        ta2=new TextArea("准备就绪",3,66);       	gridbag.setConstraints(ta2,c);       	add(ta2,false);       	ta2.setEditable(false);       	validate();       	smtp.setScroller(ta2);       	setBackground(Color.lightGray);        System.out.println(COPYRIGHT);    }    private void clearText()    {        tf1.setText("");        tf2.setText("");        ta1.setText("");        ta2.setText("准备就绪");    }    public void show()    {        pack();        sendButton.enable();        clearText();        Dimension screenSize = getToolkit().getScreenSize();        move((screenSize.width - size().width)/2,                       (screenSize.height - size().height)/2);        super.show();    }    public boolean action(Event e, Object arg)    {        String NOT_SENT = "消息没有被发送出去.";        String NO_DATA  = "没有可发送的留言内容.";		if(arg.equals("退出")){			hide();	  		return true;        }        else if(arg.equals("清除")){            clearText();            return true;        }        else if (arg.equals("发送")){            if(tf1.getText().length() + tf2.getText().length() + ta1.getText().length() == 0){        	    ta2.appendText("\r\n" + NO_DATA);        	    System.out.println(NO_DATA);        	}        	else{        	    sendButton.disable();	        	String message="用户:" + tf1.getText() + "\n" +        			           "邮件地址: " + tf2.getText() + "\n\n" +        	    		       ta1.getText() ;                try{        	        smtp.mailMessage("Guestbook Entry!",message);                }catch (Exception exception){                    String errMsg=exception.toString();                    ta2.appendText("\r\n" + errMsg.substring(errMsg.indexOf(":")+2, errMsg.length()));                    System.out.println(errMsg.substring(errMsg.indexOf(":")+2, errMsg.length()));                    ta2.appendText("\r\n" + NOT_SENT);                    System.out.println(NOT_SENT);                    sendButton.enable();                }           	}        }        return false;    }}public class GuestBook extends Applet{    static final String COPYRIGHT  = "(C)2003 by Ali";    static final String IMAGE_LOAD = "正在载入图片...请稍后.";    static final String VERSION    = "留言簿v1.0";    static final String TITLE      = "留言簿";	int width,height;	tFrame window=null;	smtpSend smtp = null;	String szButton;	String szReceiver;	String szTitle;	String szAppletImage;	String szLogoImage;	int imageCount = 0;	imageLoader il=null;	Image images[];	boolean threeD;	Color bgColor;	Color fgColor;	Button button;	public void init()	{	    String szColor;        szReceiver = getParameter("receiver");		if(null==(szTitle=getParameter("title")))			szTitle=TITLE;		if(null==(szButton=getParameter("button")))			szButton=TITLE;		if(null==(szColor=getParameter("bgcolor")))			bgColor=Color.lightGray;	    else bgColor = parseColorString(szColor);		if(null==(szColor=getParameter("fgcolor")))			fgColor=Color.black;	    else fgColor = parseColorString(szColor);	    String param=getParameter("3d_logo");	    if(null != param && Integer.valueOf(param).intValue() > 0)threeD=true;	    else threeD=false;	    add (button=new Button(szButton));		width=size().width; height=size().height;        button.move((width-button.size().width)/2,						(width-button.size().width)/2);		if(null != (szAppletImage = getParameter("applet_image")))imageCount++;		if(null != (szLogoImage = getParameter("logo_image")))imageCount++;		if(imageCount > 0){		    int index=0;    		String szImage[] = new String[imageCount];    		if(null != szAppletImage)szImage[index++]=szAppletImage;    		if(null != szLogoImage)szImage[index]=szLogoImage;    		il=new imageLoader(this, szImage, imageCount, null);    		il.start();    		images=new Image[imageCount];    	} 	}    private Color parseColorString(String colorString)    {        if(colorString.length()==6){            int R = Integer.valueOf(colorString.substring(0,2),16).intValue();            int G = Integer.valueOf(colorString.substring(2,4),16).intValue();            int B = Integer.valueOf(colorString.substring(4,6),16).intValue();            return new Color(R,G,B);        }        else return Color.lightGray;    }	public void paint(Graphics g)	{		Color color=g.getColor();		FontMetrics fm=g.getFontMetrics();	    if(il != null){	        g.drawString(IMAGE_LOAD,(size().width-fm.stringWidth(IMAGE_LOAD))/2,size().height-fm.getMaxDescent()-3);	        while(null == (images = il.retrieveImages()));	        il.stop();	        il=null;	    }	    g.setColor(bgColor);		g.fill3DRect(0,0,size().width,size().height,true);		g.setColor(fgColor);	    if(null != szAppletImage && null != images)			    g.drawImage(images[0], (size().width-images[0].getWidth(this))/2, button.size().height				    +(size().height-images[0].getHeight(this)-button.size().height)/3,this);        g.drawString(COPYRIGHT,(size().width-fm.stringWidth(COPYRIGHT))/2,size().height-fm.getMaxDescent()-3);        g.setColor(color);	}    public boolean action(Event evt, Object arg)    {		if(arg.equals(szButton)){		    if (null == smtp)		        smtp=new smtpSend(getCodeBase().getHost(),szReceiver);            if(null == window)                window=new gbFrame(szTitle, smtp, (null != szLogoImage && null != images)? images[imageCount-1] : null, threeD);            window.show();			return true;        }		else return false;    }	//Applet 参数    public String[][] getParameterInfo()    {		String[][] info = {            {"width","int","width of the applet, in pixels"},            {"height","int","height of the applet, in pixels"},            {"receiver","string","SMTP 'RCPT TO:' parameter <null>"},            {"applet_image","string","GIF file to display on applet panel <null>"},            {"logo_image","string","GIF file to display on message dialog <null>"},            {"3d_logo","int","Non-zero produces an inletted logo image <0>"},            {"bgcolor","String","RGB hex triplet for applet panel background <lightGray>"},            {"fgcolor","String","RGB hex triplet for applet panel foreground <black>"},            {"title","string","title for popup window <Guest Book >"},            {"button","string","Label to appear in applet's button <Guest Book >"}        };        return info;    }    //Applet相关信息    public String getAppletInfo()    {        return (	VERSION + " - simulates a guest log\n" +        			"by E-mailing guest data to page owner, by Ali");    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -