package class8_1_RemoteControl; import class8_1_RemoteControl.other.Command; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import java.awt.Color; import java.awt.Container; /** * This class controls the operation of an automobile * @author hornick */ public class Car extends JFrame { // Currently used only for positioning the windows. static int instanceCount = 0; private String title; JLabel status = new JLabel(); /** * @param title name of car */ public Car(String title) { setTitle(title); this.title = title; setSize(200, 80); setLocation(100, 100+80*instanceCount++); 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("engine off"); jp.add(status); contentPane.validate(); contentPane.repaint(); } /** * Simulate the command that starts the engine */ public void startEngine() { status.setText("engine on"); } /** * Simulate the command that shuts the engine off */ public void stopEngine() { status.setText("engine off"); } // Any number of other commands may be implemented here public final Command carStartCommand = new Command() { public String getCommandName() { return "Start "+title; } public boolean execute() { startEngine(); return true; } public boolean unexecute() { stopEngine(); return true; } }; }