Advertisement
dfozzle

binaryGATE

Sep 1st, 2014
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.69 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6.  
  7. package Digital;
  8.  
  9. import java.awt.Image;
  10. import java.beans.PropertyChangeEvent;
  11. import java.beans.PropertyChangeListener;
  12.  
  13. /**
  14.  *
  15.  * @author Daniel
  16.  */
  17. public abstract class BinaryGate  extends javax.swing.JPanel implements PropertyChangeListener{
  18.            
  19.  
  20.     protected OutputTerminal output = new OutputTerminal();
  21.     protected Terminal input0, input1;
  22.     protected Image image;
  23.    
  24.     @Override
  25.     protected void paintComponent(java.awt.Graphics g) {
  26.     g.drawImage(image, 0, 0, null);
  27.     }
  28.    
  29. public BinaryGate(String imgUrl){
  30.         java.net.URL url = getClass().getResource(imgUrl);
  31.         image = new javax.swing.ImageIcon(url).getImage();
  32.         this.setSize(image.getWidth(null), image.getHeight(null));
  33. }
  34.    
  35.     public Terminal getOutput(){
  36.         return output;
  37.     }
  38.  
  39.     public void setInput0(Terminal t){
  40.     if(t == null){
  41.         input0 = null;
  42.     }else{
  43.         input0 = t;
  44.     t.addPropertyChangeListener(this);
  45.     }
  46.         compute();      
  47.     }
  48.    
  49.     public void setInput1(Terminal t){
  50.     if(t == null){
  51.         input1 = null;
  52.     }else{
  53.         input1 = t;
  54.     t.addPropertyChangeListener(this);
  55.     }
  56.         compute();
  57.     }
  58.  
  59.     public Terminal getInput0(){
  60.         return input0;        
  61.     }
  62.    
  63.     public Terminal getInput1(){
  64.         return input1;
  65.     }
  66.    
  67.     protected abstract void compute();
  68.    
  69.  
  70.  
  71.     @Override
  72.     public void propertyChange(PropertyChangeEvent evt) {
  73.        compute();
  74.     }
  75.    
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement