/** * Search Engine Applet 1.0.1 * @author Robert John Morton * @version 22 October 1999 modified 10 July 2009, 10 April 2012 JFramed Sat 04 Mar 2017 11:46:52 BRT * @copyright Robert John Morton (all rights reserved) */ import javax.swing.*; // Swing GUI import java.awt.*; // for graphics operations (GUI) import java.net.*; // for downloading data from the remote server public class img2panel extends JPanel{ // MESSAGE DISPLAY PANEL private static final Font // Fonts for message summary number and URL font1 = new Font("Sans",Font.BOLD,14), font2 = new Font("Sans",Font.PLAIN,12); private Color bg; // background colour for the message panel private String msg = ""; // string to hold the displayed message text private search hf; // instance reference of the search applet private boolean redMsg = false, // true = display message in red lettering imagesLoaded = false, // true once images have been loaded smallFont = true; // true = print message in the small font size private int W, H, // width and height of message panel h, // height of the text base-line common h1, // height of the text base-line for big font h2; // height of the text base-line for small font // INSTANCE CONSTRUCTOR img2panel(int W, int H, Color bg, search hf) { this.W = W; // set width of message panel to local variable this.H = H; // set height of message panel to local variable this.bg = bg; // set panel's background colour to local variable this.hf = hf; // copy applet's instance reference to local variable /* compute the baseline 'h' for each font for lettering within a panel of height 'H' */ FontMetrics fm1 = getFontMetrics(font1); h1 = fm1.getAscent() + (H - fm1.getHeight()) / 2; FontMetrics fm2 = getFontMetrics(font2); h2 = fm2.getAscent() + (H - fm2.getHeight()) / 2; } void setImagesLoaded(){imagesLoaded = true;} // NORMAL MESSAGES (INCLUDING ERROR MESSAGES) void showMsg(String msg, boolean redMsg) { this.msg = msg; // copy message to local variables this.redMsg = redMsg; // and also its display colour switch if(redMsg) // a red (error) message tends to be long smallFont = true; // so display it in a small font else smallFont = false; // display a normal message in the large font repaint(); // schedule a repaint via event despatching thread } // SHOW URL OF HTML PAGE FROM WHICH SUMMARY WAS RETRIEVED void showURL(URL url) { msg = "" + url; // convert the URL to a string redMsg = false; // URLs do not appear in red smallFont = true; // they tend to be long, so use a small font repaint(); // schedule a repaint via event despatching thread } // DISPLAY MESSAGE IN MESSAGE PANEL public void paint(Graphics g) { if(imagesLoaded) // If images now loaded, draw back- g.drawImage(hf.IMG2,0,0,this); // ground image onto applet canvas. else { g.setColor(bg); // set background colour for message display area g.fillRect(0,0,W,H); // wipe message display area } if(smallFont) { g.setFont(font2); // set the small font active h = h2; // set baseline height for the small font } else { g.setFont(font1); // set the big font active h = h1; // set baseline height for the big font } if(redMsg) //if the message should be displayed in red g.setColor(Color.red); //set text foreground colour to red (error) else g.setColor(Color.black); //set text foreground colour to black g.drawString(msg,5,h); //draw the message string } }