import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import java.beans.*; public class Banner extends JComponent { private Color currentColor = Color.blue; private Color textColor = Color.yellow; private String text = "Welcome to the Tutorial Zone"; public void paintComponent(Graphics g) { g.setColor(currentColor); //Draw the background Dimension drawHere = getSize(); Insets borderInsets = getBorder().getBorderInsets(this); g.fillRect(borderInsets.left, borderInsets.top, (drawHere.width - borderInsets.right - borderInsets.left), (drawHere.height - borderInsets.top - borderInsets.bottom)); //Draw the text g.setColor(textColor); g.setFont(new Font("SansSerif", Font.BOLD, 24)); FontMetrics fontMetrics = g.getFontMetrics(); int stringWidth = fontMetrics.stringWidth(text); int stringHeight = fontMetrics.getHeight(); g.drawString(text, drawHere.width/2 - stringWidth/2, drawHere.height/2 + stringHeight/2); } //Setters and getters public void setColor(Color newColor) { currentColor = newColor; repaint(); } public Color getColor() { return currentColor; } public void setTextColor(Color newColor) { textColor = newColor; repaint(); } public Color getTextColor() { return textColor; } public void setText(String newText) { text = newText; repaint(); } public String getText() { return text; } }