⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 controleur.java

📁 a program in java to control the automatic door in the garage
💻 JAVA
字号:
package be.controleur;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Observable;
import java.util.Observer;

import be.garage.PorteGarage;
import be.garage.PorteGarage.Evenement;
import be.ihm.Ihm;

/**
 * @author Fabrice Tranchand
 *
 */
public final class Controleur implements Observer, ActionListener {
	// la porte simul閑
	private PorteGarage porte;

	// repr閟entation graphique de la porte
	private Ihm ihm;

	public Controleur() {
		super();
		porte = new PorteGarage();
		porte.addObserver(this);
	}

	public void actionPerformed(ActionEvent arg0) {
		assert ihm != null;
		if (arg0.getSource().equals(ihm.getBoutonObstacle())) {
			// clic sur le bouton obstacle
			if (ihm.getBoutonObstacle().isSelected()) {
				// apparition de l'obstacle
				arriveeObstacle();
			}
			else{
				// disparition de l'obstacle
				departObstacle();
			}
		} else if (arg0.getSource().equals(ihm.getBoutonTelecommande())) {
			clic();
		}
	}

	public void attachIhm() {
		assert porte != null;
		ihm = new Ihm(porte);
		ihm.init(this);
	}

	private void arriveeObstacle() {
		assert porte != null;
		porte.setObstacle(true);
		porte.changerEtat(Evenement.OBSTACLE);
	}

	private void departObstacle() {
		assert porte != null;
		porte.setObstacle(false);
	}

	public void clic() {
		assert porte != null;
		porte.changerEtat(Evenement.CLIC);
	}

	/**
	 * notification de changement d'閠at de la porte
	 */
	public void update(Observable arg0, Object arg1) {
		assert ihm != null;
		ihm.updateEtat();
	}

	public static void main(String[] args) {
		new Controleur().attachIhm();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -