ComponentTest - timer.setForeground(Color.blue...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
G /* This applet tests two custom components, MirrorLabel and StopWatch. It also tests the validate() method. The user can click a button to change the text on the components in the applet. Clicking another button will validate the applet. This will cause components that have been invalidated to be resized. The MirrorLabel is automatically invalidated when its text is changed. For the StopWatch and Buttons, it might be platform-dependent. */ * import java.awt.*; import java.awt.event.*; import java.applet.*; i public class ComponentTest extends Applet implements ActionListener { p MirrorLabel greet; StopWatch timer; Button changeText, validate; public void init() { setBackground(Color.light±ray); greet = new MirrorLabel("PLEASE LET ME OUT!"); greet.setBackground(Color.black); greet.setForeground(Color.red); greet.setFont( new Font("SansSerif", Font.BOLD, 30) ); add(greet); timer = new StopWatch(); timer.setBackground(Color.white);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: timer.setForeground(Color.blue); timer.setFont(new Font("Serif", Font.PLAIN, 20)); add( timer ); changeText = new Button("Change Text in this Applet"); changeText.addActionListener(this); add(changeText); validate = new Button("Validate"); validate.addActionListener(this); add(validate); } public void actionPerformed(ActionEvent evt) { Object source = evt.getSource(); if (source == changeText) { if (greet.getText().equals("PLEASE LET ME OUT!")) greet.setText("Help!"); else greet.setText("PLEASE LET ME OUT!"); timer.setText("Please click me."); if (validate.getLabel().equals("Validate")) validate.setLabel("Do Validation"); else validate.setLabel("Validate"); if (changeText.getLabel().equals("Change")) changeText.setLabel("Change Text in this Applet"); else changeText.setLabel("Change"); } else if (source == validate) { validate(); } } }...
View Full Document

This note was uploaded on 01/15/2010 for the course CSC 115 taught by Professor Jackson during the Spring '09 term at University of Victoria.

Page1 / 2

ComponentTest - timer.setForeground(Color.blue...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online