package class8_Lab_RemoteControl_Invoker; import class8_Lab_RemoteControl_Invoker.other.Command; 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, yoder */ 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"); } /** * Return a new command to scrub with this Roomba * @return the scrub command */ public Command getScrubCommand() { return new Command() { @Override public String getCommandName() { return "Scrub, "+getTitle()+"!"; } @Override public boolean execute() { scrub(); return true; } @Override public boolean unexecute() { return false; } }; } /** * Simulate the command that tells the robot to clean up */ public void tidy() { status.setText("Cleaning up the mess"); } /** * Returns a new command to tidy with this Roomba * @return the tidy command */ public Command getTidyCommand() { return new Command() { @Override public String getCommandName() { return "Tidy, "+getTitle()+"!"; } @Override /** * Execute the tidy command */ public boolean execute() { tidy(); return true; } @Override /** * Execute the mess command */ public boolean unexecute() { mess(); return true; } }; } /** * Simulate the command that tells the robot to create a mess */ public void mess() { status.setText("Making a mess"); } }