import java.awt.*; import java.awt.image.*; import java.awt.event.*; import java.awt.font.*; import javax.swing.*; import java.util.Observer; import java.util.Observable; import java.util.Properties; import java.io.*; public class Neuron5 extends Panel implements Runnable, ActionListener { int[] xPoints={10, 60, 110, 60, 10 }; int nPoints=5; String strB, strR; int[] yPoints={60, 10, 60, 110, 60 }; int tempR; int tempB; int intR; int intG; int intB; int Spike; int delay; Color color; Thread thread; int weight; Button btnStart; Panel btnPanel; Label lblR, lblB; TextField txtR, txtB; public Neuron5() { tempR=0; tempB=250; intR=0; intG=0; intB=250; int width; int height; width=170; height=100; lblR= new Label("R:"); lblB=new Label("B:"); txtR=new TextField("", 3); txtB=new TextField("", 3); setLayout(new BorderLayout()); btnStart = new Button("Start"); btnStart.addActionListener(this); setBackground(Color.white); btnPanel = new Panel(); strB=new String(); strR=new String(); btnPanel.add(lblR); btnPanel.add(txtR); btnPanel.add(btnStart); btnPanel.add(lblB); btnPanel.add(txtB); thread = new Thread(this); add(btnPanel, BorderLayout.SOUTH); setSize(new Dimension(width, height)); } public void run() { while(true) { if(intB >= 0) { intB=intB - 10; intR=intR + 10; tempR=tempR+10; tempB=tempB-10; color=new Color(intR,intG,intB); System.out.println("temp R:" + tempR); System.out.println("temp B:" + tempB); } if(intR > 249) { intR=0; tempR=0; } if(intB < 11) { intB=250; tempB=250; } txtR.setText(strR.valueOf(intR)); txtB.setText(strB.valueOf(intB)); try{ repaint(); Thread.sleep(300); } catch(InterruptedException e){} } } public boolean isRunning() { if(thread.isAlive()) return true; return false; } public void start() { thread.start(); } public int getR() { return intR; } public int getSpike() { int Spike=0; if(intR > 140) { Spike= intR; } return Spike; } public void actionPerformed(ActionEvent e) { if(e.getSource() == btnStart) this.start(); } public void setR(int Spike) { int sumR=tempR; int sumB=tempB; sumB=sumB - Spike/7; if(sumB < 0) sumB=0; intB= sumB; sumR=sumR+Spike/7; if(sumR > 255) sumR = 255; intR=sumR; System.out.println("end spike=" + Spike +" sumR="+sumR); } //---------------------------------------------------- public void paint(Graphics g) { g.setColor(color); g.fillPolygon(xPoints, yPoints, nPoints); if(intR > 220) { g.setColor(Color.black); g.drawLine(110, 60, 210, 60); g.drawLine(130, 30, 130, 90); g.drawLine(133, 30, 133, 90); g.drawLine(136, 30, 136, 90); g.drawLine(139, 30, 139, 90); g.drawLine(150, 30, 150, 90); g.drawLine(153, 30, 153, 90); g.drawLine(156, 30, 156, 90); g.drawLine(159, 30, 159, 90); g.drawLine(165, 30, 165, 90); g.drawLine(168, 30, 168, 90); g.drawLine(171, 30, 171, 90); g.drawLine(174, 30, 174, 90); } else { if(intR > 180) { g.setColor(Color.black); g.drawLine(110, 60, 210, 60); g.drawLine(130, 30, 130, 90); g.drawLine(133, 30, 133, 90); g.drawLine(136, 30, 136, 90); g.drawLine(139, 30, 139, 90); g.drawLine(150, 30, 150, 90); g.drawLine(153, 30, 153, 90); g.drawLine(156, 30, 156, 90); g.drawLine(159, 30, 159, 90); g.setColor(Color.white); g.drawLine(165, 30, 165, 90); g.drawLine(168, 30, 168, 90); g.drawLine(171, 30, 171, 90); g.drawLine(174, 30, 174, 90); } else { if(intR > 140) { g.setColor(Color.black); g.drawLine(110, 60, 210, 60); g.drawLine(130, 30, 130, 90); g.drawLine(133, 30, 133, 90); g.drawLine(136, 30, 136, 90); g.drawLine(139, 30, 139, 90); g.setColor(Color.white); g.drawLine(150, 30, 150, 90); g.drawLine(153, 30, 153, 90); g.drawLine(156, 30, 156, 90); g.drawLine(159, 30, 159, 90); g.drawLine(165, 30, 165, 90); g.drawLine(168, 30, 168, 90); g.drawLine(171, 30, 171, 90); g.drawLine(174, 30, 174, 90); } else { g.setColor(Color.white); g.drawLine(110, 60, 210, 60); g.drawLine(130, 30, 130, 90); g.drawLine(133, 30, 133, 90); g.drawLine(136, 30, 136, 90); g.drawLine(139, 30, 139, 90); g.drawLine(150, 30, 150, 90); g.drawLine(153, 30, 153, 90); g.drawLine(156, 30, 156, 90); g.drawLine(159, 30, 159, 90); g.drawLine(165, 30, 165, 90); g.drawLine(168, 30, 168, 90); g.drawLine(171, 30, 171, 90); g.drawLine(174, 30, 174, 90); } } } } public void update(Graphics g) { paint(g); } }