Biblioteca Java - Rev 3

Subversion Repositories:
Rev:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package designpatterns.mvc.gara;

import java.awt.Dimension;
import java.util.Observable;
import java.util.Observer;

/**
 *
 * @author evo2
 */

public class GaraView extends javax.swing.JFrame implements Observer{

    GaraControler controler;
    /**
     * Creates new form GaraView
     */

    public GaraView(GaraControler controler) {
        this.controler = controler;
        initComponents();
        this.setSize(new Dimension(500,400));
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel2 = new javax.swing.JLabel();
        jtLinia1 = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtArea = new javax.swing.JTextArea();
        jbSchimbaSemafor = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(null);

        jLabel2.setText("Linia 1");
        getContentPane().add(jLabel2);
        jLabel2.setBounds(30, 70, 50, 14);
        getContentPane().add(jtLinia1);
        jtLinia1.setBounds(80, 70, 100, 20);

        jtArea.setColumns(20);
        jtArea.setRows(5);
        jScrollPane1.setViewportView(jtArea);

        getContentPane().add(jScrollPane1);
        jScrollPane1.setBounds(20, 130, 370, 160);

        jbSchimbaSemafor.setText("Schimba semafor");
        jbSchimbaSemafor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbSchimbaSemaforActionPerformed(evt);
            }
        });
        getContentPane().add(jbSchimbaSemafor);
        jbSchimbaSemafor.setBounds(260, 70, 120, 23);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbSchimbaSemaforActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbSchimbaSemaforActionPerformed
        controler.schimbaSemafor();
    }//GEN-LAST:event_jbSchimbaSemaforActionPerformed

    /**
     * @param args the command line arguments
     */

    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */

        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(GaraView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(GaraView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(GaraView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(GaraView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new GaraView(null).setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jbSchimbaSemafor;
    private javax.swing.JTextArea jtArea;
    private javax.swing.JTextField jtLinia1;
    // End of variables declaration//GEN-END:variables

    @Override
    public void update(Observable o, Object arg) {
       
            Gara gara = (Gara)o;
           
            if(arg.equals(Gara.EVENIMENT_SOSESTE_TREN)){
                jtLinia1.setText(gara.getLinia1());
                jtArea.append("Trenul "+gara.getLinia1()+" a sosit in gara!\n");
            }
           
            if(arg.equals(Gara.EVENIMENT_SEMAFOR_SCHIMBAT)){            
                jtArea.append("Semafor schimbat:"+gara.getSemafor()+" \n");
            }
           
    }
}