/** * Bandscope Receiver Applet 1.0.0 [MESSAGE PANEL] * @author Robert J Morton YE572246C * @version 13 March 2002, 20 March 2012 * @copyright Robert J Morton (all rights reserved) */ import javax.swing.*; // swing widgets import java.awt.*; // for graphics operations (GUI) class msgpanel extends JPanel { private int W, // width of message-panel H, // height of message-panel h, // text base line for panel of height H I = 5; // text inset from beginning of text area private String msg; // current time stamp message private Color bg; // background colour private boolean RedMsg = false; // true if message should be shown in red private Font font; msgpanel(Color bg, Font font, int W, int H) { // CONSTRUCTOR this.bg = bg; // set panel colour this.W = W; // set panel width this.H = H; // set panel height this.font = font; //compute baseline 'h' for the lettering within a panel of height 'H' FontMetrics fm = getFontMetrics(font); h = fm.getAscent() + (H - fm.getHeight()) /2; } void showMsg(String s, boolean b) { RedMsg = b; // true if the message should be shown in red msg = s; // message content repaint(); // schedule a repaint on the event-despatching thread } public void paint(Graphics g) { g.setColor(bg); // set background colour for the panel g.fillRect(0, 0, W, H); // clear the bandscope data file time stamp area g.setFont(font); // set the font for this panel /* If the message should be shown in red set the print colour to red; otherwise, by default, set the print colour to black. */ if(RedMsg) g.setColor(Color.red); else g.setColor(Color.black); g.drawString(msg, I, h); // display the message } }