/** * Search Engine Applet 1.0.1 * @author Robert John Morton * @version 22 October 1999 modified 10 July 2009, 10 April 2012 * @copyright Robert John Morton (all rights reserved) */ import java.applet.*; // all the gubbins to make the applet work import javax.swing.*; // Swing GUI import java.awt.*; // for graphics operations (GUI) public class img3panel extends JPanel { // SUMMARY NUMBER DISPLAY PANEL // Declare a font for the url and summary number private static final Font font = new Font("Serif", Font.PLAIN, 18); // When true, the text must be displayed in red lettering private boolean redMsg = false; 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 int W, H, // width and height of message panel h; // height of the text base-line img3panel(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 lettering within a panel of height 'H'. FontMetrics fm = getFontMetrics(font); h = fm.getAscent() + (H - fm.getHeight()) /2; } void showNumber(String s) { // UPDATE SUMMARY'S NUMBER msg = s; // copy message to local variables repaint(); // schedule a repaint via the event despatching thread } public void paint(Graphics g) { // DISPLAY SUMMARY'S NUMBER g.drawImage(hf.IMG3,0,0,this); // draw background image on applet canvas g.setFont(font); // set font for summary number g.setColor(Color.black); // set text foreground colour g.drawString(msg, 5, h); // draw the summary number } }