\ru\ifmo\alarm\gui\AlarmFrame.java

package ru.ifmo.alarm.gui; 
 
import java.awt.Color; 
import java.awt.BorderLayout; 
import java.awt.Dimension; 
import java.awt.Font; 
import java.awt.event.*; 
 
import javax.swing.JFrame; 
import javax.swing.JLabel; 
import javax.swing.JPanel; 
import javax.swing.JTextArea; 
import javax.swing.JScrollPane; 
import javax.swing.ScrollPaneConstants; 
import javax.swing.plaf.metal.MetalBorders; 
 
public class AlarmFrame extends JFrame { 
    static final long serialVersionUID = 0;     //eclipse wants me to write this :( 
     
    public static AlarmFrame alarmFrame = new AlarmFrame(); //static instance so that each controlled object could access it 
     
    protected CarPanel carPanel; 
    protected RemoteControlPanel remoteControlPanel; 
    protected JPanel content;       // a panel with white background, which contains all needed panels 
    protected JLabel helpLabel;     // a label with comment for a component under cursor 
    protected JTextArea commentsArea;    // a text area where actions will be written 
    protected JScrollPane scrollPane;   // a scroll pane for viewing of actions area 
     
    public AlarmFrame() { 
        super("AlarmFrame"); 
        this.setBounds(20, 0, 600, 720); 
        content = new JPanel(); 
            content.setBackground(Color.WHITE); 
            content.setLayout(null); 
         
            // adding panel of remote control 
            remoteControlPanel = new RemoteControlPanel(); 
                content.add(remoteControlPanel); 
                remoteControlPanel.setBounds(10, 20, remoteControlPanel.getWidth(), remoteControlPanel.getHeight()); 
         
            // adding panel of car 
            carPanel = new CarPanel(); 
                content.add(carPanel); 
                carPanel.setBounds(this.getWidth() - carPanel.getWidth() - 10, 0, carPanel.getWidth(), carPanel.getHeight()); 
             
            content.setBounds(0, 0, carPanel.getX() + carPanel.getWidth(), carPanel.getHeight()); 
                             
            //adding all labels 
            JLabel label1 = new JLabel("<html><b>1</b> - включить</html>"); 
            JLabel label2 = new JLabel("<html><b>2</b> - выключить</html>"); 
            JLabel label3 = new JLabel("<html><b>3</b> - тихий режим</html>"); 
            label1.setFont(new Font(null, Font.PLAIN, 14)); 
            label2.setFont(new Font(null, Font.PLAIN, 14)); 
            label3.setFont(new Font(null, Font.PLAIN, 14)); 
            label1.setBounds(155, 65, 120, 15); 
            label2.setBounds(155, 100, 120, 15); 
            label3.setBounds(155, 135, 120, 15); 
            content.add(label1); 
            content.add(label2); 
            content.add(label3); 
             
            commentsArea = new JTextArea(); 
                commentsArea.setEditable(false); 
                commentsArea.setLineWrap(true); 
                commentsArea.setWrapStyleWord(true); 
                commentsArea.setFont(new Font(null, Font.PLAIN, 12)); 
                 
            JScrollPane scrollPane = new JScrollPane(commentsArea, 
                            ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, 
                            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); 
                scrollPane.setBounds(20, 310, 250, 320); 
                commentsArea.setSize(scrollPane.getWidth(), scrollPane.getHeight()); 
                content.add(scrollPane); 
                 
            JLabel commentsAreaComments = new JLabel("Комментарии:"); 
                commentsAreaComments.setFont(new Font(null, Font.PLAIN, 14)); 
                commentsAreaComments.setBounds(scrollPane.getX(), scrollPane.getY() - 20, 100, 15); 
                content.add(commentsAreaComments); 
                         
        helpLabel = new JLabel(" "); 
            helpLabel.setPreferredSize(new Dimension(200, 35)); 
            helpLabel.setBackground(Color.GRAY); 
            helpLabel.setBorder(new MetalBorders.TextFieldBorder()); 
            helpLabel.setFont(new Font(null, Font.PLAIN, 12)); 
            addHelpListeners(); 
         
        this.getContentPane().add(content, BorderLayout.CENTER); 
        this.getContentPane().add(helpLabel, BorderLayout.SOUTH); 
         
        //this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
        this.setResizable(false); 
        this.setVisible(true); 
    } 
     
    private void addHelpListeners() { 
        carPanel.addMouseListener(new MouseListener () { 
            public void mouseClicked(MouseEvent e) {} 
            public void mouseEntered(MouseEvent e) { 
                helpLabel.setText("  Нажмите левой кнопкой мыши для " + 
                        "слабого удара или правой для сильного"); 
            } 
            public void mouseExited(MouseEvent e) { 
                helpLabel.setText(" "); 
            } 
            public void mousePressed(MouseEvent e) {} 
            public void mouseReleased(MouseEvent e) {} 
        }); 
        remoteControlPanel.getButton1().addMouseListener(new MouseListener() { 
            public void mouseClicked(MouseEvent e) {} 
            public void mouseEntered(MouseEvent e) { 
                helpLabel.setText("  Включает сигнализацию, что подтверждается звуковым " + 
                        "сигналом и миганием фар"); 
            } 
            public void mouseExited(MouseEvent e) { 
                helpLabel.setText(" "); 
            } 
            public void mousePressed(MouseEvent e) {} 
            public void mouseReleased(MouseEvent e) {} 
        }); 
        remoteControlPanel.getButton2().addMouseListener(new MouseListener() { 
            public void mouseClicked(MouseEvent e) {} 
            public void mouseEntered(MouseEvent e) { 
                helpLabel.setText("  Выключает сигнализацию, что подтверждается звуковым " + 
                        "сигналом и миганием фар"); 
            } 
            public void mouseExited(MouseEvent e) { 
                helpLabel.setText(" "); 
            } 
            public void mousePressed(MouseEvent e) {} 
            public void mouseReleased(MouseEvent e) {} 
        }); 
        remoteControlPanel.getButton3().addMouseListener(new MouseListener() { 
            public void mouseClicked(MouseEvent e) {} 
            public void mouseEntered(MouseEvent e) { 
                helpLabel.setText("<html>&nbsp;&nbsp;Включает \"тихий режим\": если сразу " + 
                        "после ее нажатия включить или выключить сигнализацию, " + 
                        "<p>&nbsp;&nbsp;звукового подтверждения не будет</html>"); 
            } 
            public void mouseExited(MouseEvent e) { 
                helpLabel.setText(" "); 
            } 
            public void mousePressed(MouseEvent e) {} 
            public void mouseReleased(MouseEvent e) {} 
        }); 
    } 
     
    public CarPanel getCarPanel() { 
        return carPanel; 
    } 
     
    public RemoteControlPanel getRemoteControlPanel() { 
        return remoteControlPanel; 
    } 
     
    public JTextArea getCommentsArea() { 
        return commentsArea; 
    } 
 
}