📄 gb2.java
字号:
gbFrame(String title, smtpSend smtp, Image image, boolean threeD) { super(title); this.smtp=smtp; setFont(new Font("System",Font.PLAIN,14)); GridBagLayout gridbag=new GridBagLayout(); GridBagConstraints c=new GridBagConstraints(); setLayout(gridbag); if(null != image){ c.insets=new Insets(5,5,8,5); c.weightx=1;c.weighty=1; c.fill=GridBagConstraints.NONE; c.gridwidth=GridBagConstraints.REMAINDER; logoPanel lp=new logoPanel(image, threeD); gridbag.setConstraints(lp,c); add(lp); } c.weightx=1;c.weighty=1; c.insets=new Insets(3,5,0,0); c.gridwidth=1; c.fill=GridBagConstraints.NONE; c.anchor=GridBagConstraints.EAST; Label label = new Label(" Your Name (optional): "); gridbag.setConstraints(label,c); add(label); 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(" Your Email (optional): "); 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(" Any comments or suggestions are welcome! "); 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("Send"); gridbag.setConstraints(sendButton,c); add(sendButton); c.insets=new Insets(3,0,3,0); tButton b=new tButton("Clear"); gridbag.setConstraints(b,c); add(b); c.insets=new Insets(3,0,3,5); c.gridwidth=GridBagConstraints.REMAINDER; b=new tButton("Quit"); 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("Ready.",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("Ready."); } public void show() { pack(); //resize(preferredSize()); 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 = "Message NOT sent."; String NO_DATA = "Nothing to send."; if(arg.equals("Quit")){ hide(); return true; } else if(arg.equals("Clear")){ clearText(); return true; } else if (arg.equals("Send")){ 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="Guest: " + tf1.getText() + "\n" + "Address: " + 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 gb2 extends Applet{ static final String COPYRIGHT = "(C) 1996 by W.Giel"; static final String IMAGE_LOAD = "Loading Images...wait."; static final String VERSION = "Guest Book II v2.0a (4 July 1996)"; static final String TITLE = "Guest Book II"; 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 parameters - pretty much self-explanatory /////////////////////////////////////////////////// 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 II>"}, {"button","string","Label to appear in applet's button <Guest Book II>"} }; return info; } ///////////////////////////////////// //Applet name, author and info lines ///////////////////////////////////// public String getAppletInfo() { return ( VERSION + " - simulates a guest log\n" + "by E-mailing guest data to page owner, by Bill Giel\n" + "http://www.nai.net/~rvdi/home.htm or rvdi@usa.nai.net\n" + "Copyright 1996 by William Giel."); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -