package example8_1_InClass; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import java.awt.Color; import java.awt.Container; /** * This class delegates world domination to a mindless automaton * @author hornick * */ public class Robot extends JFrame { JLabel status = new JLabel(); public Robot(String title) { setTitle(title); setSize(250, 80); setLocation(250, 200); setResizable(false); setVisible(true); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // Retrieves the window's contentPane and sets the background color Container contentPane = getContentPane(); JPanel jp = new JPanel(); contentPane.add(jp); jp.setBackground(Color.LIGHT_GRAY); status.setText("robot sleeping"); jp.add(status); contentPane.validate(); contentPane.repaint(); } /** * Simulate the command that tells the robot to scrub the floor */ public void scrub() { status.setText("Washing the floor"); } /** * Simulate the command that tells the robot to clean up */ public void tidy() { status.setText("Cleaning up the mess"); } /** * Simulate the command that tells the robot to create a mess */ public void mess() { status.setText("Making a mess"); } }