package class9_1_RemoteControl_start; 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; JLabel status = new JLabel(); /** * @param title name of car */ public Car(String title) { setTitle(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 }