Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * 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 Digital;
- import java.awt.Image;
- import java.beans.PropertyChangeEvent;
- import java.beans.PropertyChangeListener;
- /**
- *
- * @author Daniel
- */
- public abstract class BinaryGate extends javax.swing.JPanel implements PropertyChangeListener{
- protected OutputTerminal output = new OutputTerminal();
- protected Terminal input0, input1;
- protected Image image;
- @Override
- protected void paintComponent(java.awt.Graphics g) {
- g.drawImage(image, 0, 0, null);
- }
- public BinaryGate(String imgUrl){
- java.net.URL url = getClass().getResource(imgUrl);
- image = new javax.swing.ImageIcon(url).getImage();
- this.setSize(image.getWidth(null), image.getHeight(null));
- }
- public Terminal getOutput(){
- return output;
- }
- public void setInput0(Terminal t){
- if(t == null){
- input0 = null;
- }else{
- input0 = t;
- t.addPropertyChangeListener(this);
- }
- compute();
- }
- public void setInput1(Terminal t){
- if(t == null){
- input1 = null;
- }else{
- input1 = t;
- t.addPropertyChangeListener(this);
- }
- compute();
- }
- public Terminal getInput0(){
- return input0;
- }
- public Terminal getInput1(){
- return input1;
- }
- protected abstract void compute();
- @Override
- public void propertyChange(PropertyChangeEvent evt) {
- compute();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement