import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.net.URL;

//Author:H.Hakan GENÇ - 2001-2002 - Turkiye
//GSM: +905052610452, E-mail:hasanhakangenc@hotmail.com

public class bjt_evirici_2 extends Applet{
	
	Image winBellek;
	Graphics gBellek;
	
	int y1=10, y2=25, y3=25, RBy1=50, RBy2=50, RBy3=50, atom =10, direnc =60, tr_genislik=30, 
		x1 =220, x2=420, x3=620, son1 =250, son2=250, son3=250, 
		tr_baz=75, tr_kollektor=110, bas1=46, bas2=250, bas3=450;
	boolean baz=true, anahtar1=false, anahtar2=false;
	
	double VBE=0.7, VCEsat, VBEsat=0.8;
	final int betaF=100;
	final double betaR = 2;
	final int VCC=5;
	final double VT = 27E-3;
	int VHI=5, N=1; 
	double RC=1, RB=10;
	double IB, IC, X, VOH;
	double alfaR = betaR/(1+betaR), alfaF = betaF/(1+betaF);
	float Vout, Vout_t;

	String voltaj_giris_renk = "#ff0000";
	String zeminRenk, onRenk;

	DirencDialog RBdirenci = new DirencDialog(this,"RB");
	DirencDialog RCdirenci = new DirencDialog(this,"RC");
	
	VTC vtc;
	VTCPanel vtcPanel = new VTCPanel();
	Applet aplet = new Applet();
	public void init(){
		zeminRenk = getParameter("zeminrenk");
		onRenk = getParameter("onrenk");
		
		if ((zeminRenk == null) ||
			(onRenk == null))
		{
			zeminRenk = "f0f0f0";
			onRenk = "000000";
		}
		
		setBackground(stringToColor(zeminRenk));
		setForeground(stringToColor(onRenk));
		setLayout(new BorderLayout());
		vtcPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
		winBellek = createImage(this.getSize().width,this.getSize().height);
		gBellek = winBellek.getGraphics();
		
		IB = (VHI-VBE)/RB;
		IC = betaF*IB;
		 
		X = (1 + ((((VCC-0.3)/(IB*RC))+1)/betaR))/(1 - ((VCC-0.3)/(IB*RC))/betaF);
	//	X = ((1/alfaR) + (IC/IB)*(1/betaR))/(1 - (IC/IB)*(1/betaF));
		VCEsat = (VT*(Math.log(X)/Math.log(Math.E)));
		
		Vout = (float)(VCC - IC*RC);		
		
		if(Vout<=0.3) Vout = (float)VCEsat;
		VOH = VCC;
			 
		addMouseListener(new MouseAdapter(){
			public void mousePressed(MouseEvent olay){
				if(olay.getX()>=(bas1-atom) && olay.getX()<=bas1 
						 && olay.getY()>=son1-tr_baz-atom/2 && olay.getY() <=son1-tr_baz+atom/2){
					if(baz){
						baz = false;
						if(Vout > VBEsat){
							if(anahtar1 && anahtar2) Vout = (float)(VBE + ((RB/2)/(RB/2 + RC))*(Vout-VBE));
							else if(anahtar1 && !anahtar2) Vout = (float)(VBE + (RB/(RB + RC))*(Vout-VBE));
						}
						voltaj_giris_renk="#000000";
						repaint();
					}
					else{
						baz = true;
						voltaj_giris_renk="#ff0000";
						X = (1 + ((((VCC-0.3)/(IB*RC))+1)/betaR))/(1 - ((VCC-0.3)/(IB*RC))/betaF);
						VCEsat = (VT*(Math.log(X)/Math.log(Math.E)));
						Vout = (float)(VCC - IC*RC);		
						if(Vout<=0.3) Vout = (float)VCEsat;
						repaint();
					}
				}
				
				if((olay.getX() >= bas1+35 && olay.getX() <= bas1+95 && olay.getY() >= son1-tr_baz-10
				   && olay.getY() <= son1-tr_baz+10) || (olay.getX() >= bas2+35 && olay.getX() <= bas2+95 
					&& olay.getY() >= son2-tr_baz-10 && olay.getY() <= son2-tr_baz+10) || (olay.getX() >= bas3+35 
					&& olay.getX() <= bas3+95 && olay.getY() >= son3-tr_baz-10
				   && olay.getY() <= son3-tr_baz+10)){
					Point konum = bjt_evirici_2.this.getLocationOnScreen();
			
						RBdirenci.addWindowListener(new WindowAdapter(){
							public void windowClosing(WindowEvent olay){
								RBdirenci.dispose();
							}
						});
					RBdirenci.setLocation(konum.x+bas1+35,konum.y+son1-tr_baz-10);
					RBdirenci.show();
					RBdirenci.pack();
					RBdirenci.setResizable(false);
				}
				
				if((olay.getX() >= x1-10 && olay.getX() <= x1+10
					&& olay.getY() >= RBy1 && olay.getY() <= RBy1+60) || (olay.getX() >= x2-10 
					&& olay.getX() <= x2+10 && olay.getY() >= RBy2 && olay.getY() <= RBy2+60) || 
				   (olay.getX() >= x3-10 && olay.getX() <= x3+10
					&& olay.getY() >= RBy3 && olay.getY() <= RBy3+60))
				{
					Point konum = bjt_evirici_2.this.getLocationOnScreen();
						RCdirenci.addWindowListener(new WindowAdapter(){
							public void windowClosing(WindowEvent olay){
								RCdirenci.dispose();
							}
						});
					RCdirenci.setLocation(konum.x+x1-50,konum.y+RBy1);
					RCdirenci.show();
					RCdirenci.pack();
					RCdirenci.setResizable(false);
				}
				
				if(olay.getX() <= bas2+10 && olay.getX() >= bas2 && olay.getY() <= son2-tr_baz && olay.getY() >= son2-tr_baz-30){
					if(anahtar1){
						anahtar1 = false;
						if(baz){
							Vout = (float)(VCC - IC*RC);		
							if(Vout<=0.3) Vout = (float)VCEsat;
						}
						VOH = VCC;
					}
					else if(!anahtar1){
						anahtar1 = true;
						if(anahtar2){
							if(baz){
								Vout = (float)(VCC - IC*RC);		
								if(Vout<=0.3) Vout = (float)VCEsat;
								else if(Vout > VBEsat) Vout = (float)(VBE + ((RB/2)/(RB/2 + RC))*(Vout-VBE));
							}
							N=2;
						}
						else {
							if(baz){
								Vout = (float)(VCC - IC*RC);		
								if(Vout<=0.3) Vout = (float)VCEsat;
								else if(Vout > VBEsat) Vout = (float)(VBE + (RB/(RB + RC))*(Vout-VBE));
							}
							N=1;
						}
						VOH = VBEsat + ((RB/N)/(RB/N+RC))*(VCC-VBEsat);
					}
					vtc.guncelle(RC,RB,VOH,VCEsat,Vout);
					repaint();
				}
				
				if(olay.getX() <= bas2+10 && olay.getX() >= bas2 && olay.getY() >= son2-tr_baz && olay.getY() <= son2-tr_baz+30){
					if(anahtar2){ 
						anahtar2 = false;
						if(anahtar1){
							if(baz){
								Vout = (float)(VCC - IC*RC);		
								if(Vout<=0.3) Vout = (float)VCEsat;
								else if(Vout > VBEsat) Vout = (float)(VBE + (RB/(RB + RC))*(Vout-VBE));
							}
							N=1;
							VOH = VBEsat + ((RB/N)/(RB/N+RC))*(VCC-VBEsat);
						}
						else{
							if(baz){
							Vout = (float)(VCC - IC*RC);		
							if(Vout<=0.3) Vout = (float)VCEsat;
						}
							VOH = VCC;
						}
					}
					else if(!anahtar2){
						anahtar2 = true;
						if(anahtar1){
							if(baz){
								Vout = (float)(VCC - IC*RC);		
								if(Vout<=0.3) Vout = (float)VCEsat;
								else if(Vout > VBEsat) Vout = (float)(VBE + ((RB/2)/(RB/2 + RC))*(Vout-VBE));
							}
							N=2;
							VOH = VBEsat + ((RB/N)/(RB/N+RC))*(VCC-VBEsat);
						}
						else{
							if(baz){
							Vout = (float)(VCC - IC*RC);		
							if(Vout<=0.3) Vout = (float)VCEsat;
						}
							VOH = VCC;
						}
					}
					vtc.guncelle(RC,RB,VOH,VCEsat,Vout);
					repaint();
				}
			}
			
		}) ;
		addMouseMotionListener(new MouseMotionListener(){
			public void mouseMoved(MouseEvent olay){
				if((olay.getX()>=(bas1-atom) && olay.getX()<=bas1 
				   && olay.getY()>=son1-tr_baz-atom/2 && olay.getY() <=son1-tr_baz+atom/2) ||
				   (olay.getX() >= bas1+35 && olay.getX() <= bas1+95 && olay.getY() >= son1-tr_baz-10
					&& olay.getY() <= son1-tr_baz+10) || (olay.getX() >= bas2+35 && olay.getX() <= bas2+95 
					&& olay.getY() >= son2-tr_baz-10 && olay.getY() <= son2-tr_baz+10) || (olay.getX() >= bas3+35 
					&& olay.getX() <= bas3+95 && olay.getY() >= son3-tr_baz-10
				   && olay.getY() <= son3-tr_baz+10) || 
				   (olay.getX() >= x1-10 && olay.getX() <= x1+10
					&& olay.getY() >= RBy1 && olay.getY() <= RBy1+60) || (olay.getX() >= x2-10 && olay.getX() <= x2+10
					&& olay.getY() >= RBy2 && olay.getY() <= RBy2+60) || (olay.getX() >= x3-10 && olay.getX() <= x3+10
					&& olay.getY() >= RBy3 && olay.getY() <= RBy3+60) || (olay.getX() <= bas2+10 && olay.getX() >= bas2
																		  && olay.getY() >= son2-tr_baz && olay.getY() <= son2-tr_baz+30)
				   || (olay.getX() <= bas2+10 && olay.getX() >= bas2 && olay.getY() <= son2-tr_baz && olay.getY() >= son2-tr_baz-30))
				{
					setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
				}
				else setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
			}
			public void mouseDragged(MouseEvent olay){
			}
		});
		vtc = new VTC(zeminRenk, RC, RB, VOH, VCEsat, Vout);
		vtcPanel.add(vtc);
		add(vtcPanel,"South");

	}
	
	private Color stringToColor(String paramDeger)
	{
		int red;
		int green;
		int blue;

		red = (Integer.decode("0x" + paramDeger.substring(0,2))).intValue();
		green = (Integer.decode("0x" + paramDeger.substring(2,4))).intValue();
		blue = (Integer.decode("0x" + paramDeger.substring(4,6))).intValue();

		return new Color(red,green,blue);
	}
	
	public void direncGuncelle(double direnc_degeri, String direnc){
		if(direnc == "RB") this.RB = direnc_degeri;
		else if(direnc == "RC") this.RC = direnc_degeri;
		IB = (VHI-VBE)/RB;
		IC = betaF*IB;
		X = (1 + ((((VCC-0.3)/(IB*RC))+1)/betaR))/(1 - ((VCC-0.3)/(IB*RC))/betaF);
	//	X = ((1/alfaR) + (IC/IB)*(1/betaR))/(1 - (IC/IB)*(1/betaF));
		VCEsat = (VT*(Math.log(X)/Math.log(Math.E)));
		if(baz){
			Vout = (float)(VCC - IC*RC);
			if(Vout<=0.3) Vout = (float)VCEsat;
			else if(Vout > VBEsat){
				if(anahtar1 && anahtar2) Vout = (float)(VBE + ((RB/2)/(RB/2 + RC))*(Vout-VBE));
				else if(anahtar1 && !anahtar2) Vout = (float)(VBE + (RB/(RB + RC))*(Vout-VBE));
			}
		}
		
		if(anahtar1 || anahtar2) VOH = VBEsat + ((RB/N)/(RB/N+RC))*(VCC-VBEsat);
		else VOH = VCC;
		
		vtc.guncelle(RC,RB,VOH,VCEsat,Vout);
		repaint();
	}
	
	public void paint(Graphics g){
		
		gBellek.setColor(Color.decode("#"+zeminRenk));
		gBellek.setFont(new Font("TimesRoman",Font.PLAIN,12));
		gBellek.fillRect(0,0,this.getSize().width,this.getSize().height);
		gBellek.setColor(Color.decode("#007846"));
		gBellek.drawString("+VCC",x1,y1);
		gBellek.drawString("G i r i ş",0,son1-tr_baz);
		gBellek.setColor(Color.red);
		gBellek.drawOval(x1-atom/2,y1,atom,atom);
		gBellek.setColor(Color.decode(voltaj_giris_renk));
		gBellek.drawOval(bas1-atom,son1-tr_baz-atom/2,atom,atom);
		
		//5V 0V bilgileri yazdırılıyor
		gBellek.setColor(Color.red);
		gBellek.drawOval(20,250,atom,atom);
		gBellek.drawString("5V",18,240);
		gBellek.setColor(Color.black);
		gBellek.drawOval(50,250,atom,atom);
		gBellek.drawString("0V",48,240);
		
		gBellek.setColor(Color.black);
		gBellek.drawLine(x1,y1+10,x1,RBy1);
		gBellek.drawLine(x1,direnc+RBy1,x1,son1-tr_kollektor);
		gBellek.drawLine(bas1,son1-tr_baz,bas1+35,son1-tr_baz);
		gBellek.drawLine(bas1+95,son1-tr_baz,x1-tr_genislik,son1-tr_baz);
		gBellek.drawLine(x1,son1-tr_kollektor+70,x1,son1+10);
		
		gBellek.drawLine(x2,y2+10,x2,RBy2);
		gBellek.drawLine(x2,direnc+RBy2,x2,son2-tr_kollektor);
		gBellek.drawLine(bas2+10,son2-tr_baz,bas2+35,son2-tr_baz);
		gBellek.drawLine(bas2+95,son2-tr_baz,x2-tr_genislik,son2-tr_baz);
		gBellek.drawLine(x2,son2-tr_kollektor+70,x2,son2+10);
		
		gBellek.drawLine(x3,y3+10,x3,RBy3);
		gBellek.drawLine(x3,direnc+RBy3,x3,son3-tr_kollektor);
		gBellek.drawLine(bas3,son3-tr_baz,bas3+35,son3-tr_baz);
		gBellek.drawLine(bas3+95,son3-tr_baz,x3-tr_genislik,son3-tr_baz);
		gBellek.drawLine(x3,son3-tr_kollektor+70,x3,son3+10);
		
		//transistor çiziliyor
		gBellek.drawLine(x1-tr_genislik,son1-tr_baz-20,x1-tr_genislik,son1-tr_baz+20);
		gBellek.drawLine(x1,son1-tr_kollektor,x1-tr_genislik,son1-tr_kollektor+30);
		gBellek.drawLine(x1,son1-tr_kollektor+70,x1-tr_genislik,son1-tr_kollektor+40);
		gBellek.drawLine(x1,son1-tr_kollektor+70,x1-5,son1-tr_kollektor+60);
		gBellek.drawLine(x1,son1-tr_kollektor+70,x1-9,son1-tr_kollektor+66);
		
		gBellek.drawLine(x2-tr_genislik,son2-tr_baz-20,x2-tr_genislik,son2-tr_baz+20);
		gBellek.drawLine(x2,son2-tr_kollektor,x2-tr_genislik,son2-tr_kollektor+30);
		gBellek.drawLine(x2,son2-tr_kollektor+70,x2-tr_genislik,son2-tr_kollektor+40);
		gBellek.drawLine(x2,son2-tr_kollektor+70,x2-5,son2-tr_kollektor+60);
		gBellek.drawLine(x2,son2-tr_kollektor+70,x2-9,son2-tr_kollektor+66);
		
		gBellek.drawLine(x3-tr_genislik,son3-tr_baz-20,x3-tr_genislik,son3-tr_baz+20);
		gBellek.drawLine(x3,son3-tr_kollektor,x3-tr_genislik,son3-tr_kollektor+30);
		gBellek.drawLine(x3,son3-tr_kollektor+70,x3-tr_genislik,son3-tr_kollektor+40);
		gBellek.drawLine(x3,son3-tr_kollektor+70,x3-5,son3-tr_kollektor+60);
		gBellek.drawLine(x3,son3-tr_kollektor+70,x3-9,son3-tr_kollektor+66);
		
		// RC çiziliyor
		gBellek.drawString("RC = "+Double.toString(RC)+"k",x1+20,y1+70);
		gBellek.drawLine(x1,RBy1,x1+10,RBy1+5);
		gBellek.drawLine(x1+10,RBy1+5,x1-10,RBy1+15);
		gBellek.drawLine(x1-10,RBy1+15,x1+10,RBy1+25);
		gBellek.drawLine(x1+10,RBy1+25,x1-10,RBy1+35);
		gBellek.drawLine(x1-10,RBy1+35,x1+10,RBy1+45);
		gBellek.drawLine(x1+10,RBy1+45,x1-10,RBy1+55);
		gBellek.drawLine(x1-10,RBy1+55,x1,RBy1+60);
		
		gBellek.drawString("RC = "+Double.toString(RC)+"k",x2+20,y2+70);
		gBellek.drawLine(x2,RBy2,x2+10,RBy2+5);
		gBellek.drawLine(x2+10,RBy2+5,x2-10,RBy2+15);
		gBellek.drawLine(x2-10,RBy2+15,x2+10,RBy2+25);
		gBellek.drawLine(x2+10,RBy2+25,x2-10,RBy2+35);
		gBellek.drawLine(x2-10,RBy2+35,x2+10,RBy2+45);
		gBellek.drawLine(x2+10,RBy2+45,x2-10,RBy2+55);
		gBellek.drawLine(x2-10,RBy2+55,x2,RBy2+60);
		
		gBellek.drawString("RC = "+Double.toString(RC)+"k",x3+20,y3+70);
		gBellek.drawLine(x3,RBy3,x3+10,RBy3+5);
		gBellek.drawLine(x3+10,RBy3+5,x3-10,RBy3+15);
		gBellek.drawLine(x3-10,RBy3+15,x3+10,RBy3+25);
		gBellek.drawLine(x3+10,RBy3+25,x3-10,RBy3+35);
		gBellek.drawLine(x3-10,RBy3+35,x3+10,RBy3+45);
		gBellek.drawLine(x3+10,RBy3+45,x3-10,RBy3+55);
		gBellek.drawLine(x3-10,RBy3+55,x3,RBy3+60);
		
		// RB çiziliyor
		gBellek.drawString("RB = "+Double.toString(RB)+"k",bas1+50,son1-tr_baz-20);
		gBellek.drawLine(bas1+35,son1-tr_baz,bas1+40,son1-tr_baz-10);
		gBellek.drawLine(bas1+40,son1-tr_baz-10,bas1+50,son1-tr_baz+10);
		gBellek.drawLine(bas1+50,son1-tr_baz+10,bas1+60,son1-tr_baz-10);
		gBellek.drawLine(bas1+60,son1-tr_baz-10,bas1+70,son1-tr_baz+10);
		gBellek.drawLine(bas1+70,son1-tr_baz+10,bas1+80,son1-tr_baz-10);
		gBellek.drawLine(bas1+80,son1-tr_baz-10,bas1+90,son1-tr_baz+10);
		gBellek.drawLine(bas1+90,son1-tr_baz+10,bas1+95,son1-tr_baz);
		
		gBellek.drawString("RB = "+Double.toString(RB)+"k",bas2+50,son2-tr_baz-20);
		gBellek.drawLine(bas2+35,son2-tr_baz,bas2+40,son2-tr_baz-10);
		gBellek.drawLine(bas2+40,son2-tr_baz-10,bas2+50,son2-tr_baz+10);
		gBellek.drawLine(bas2+50,son2-tr_baz+10,bas2+60,son2-tr_baz-10);
		gBellek.drawLine(bas2+60,son2-tr_baz-10,bas2+70,son2-tr_baz+10);
		gBellek.drawLine(bas2+70,son2-tr_baz+10,bas2+80,son2-tr_baz-10);
		gBellek.drawLine(bas2+80,son2-tr_baz-10,bas2+90,son2-tr_baz+10);
		gBellek.drawLine(bas2+90,son2-tr_baz+10,bas2+95,son2-tr_baz);
		
		gBellek.drawString("RB = "+Double.toString(RB)+"k",bas3+50,son3-tr_baz-20);
		gBellek.drawLine(bas3+35,son3-tr_baz,bas3+40,son3-tr_baz-10);
		gBellek.drawLine(bas3+40,son3-tr_baz-10,bas3+50,son3-tr_baz+10);
		gBellek.drawLine(bas3+50,son3-tr_baz+10,bas3+60,son3-tr_baz-10);
		gBellek.drawLine(bas3+60,son3-tr_baz-10,bas3+70,son3-tr_baz+10);
		gBellek.drawLine(bas3+70,son3-tr_baz+10,bas3+80,son3-tr_baz-10);
		gBellek.drawLine(bas3+80,son3-tr_baz-10,bas3+90,son3-tr_baz+10);
		gBellek.drawLine(bas3+90,son3-tr_baz+10,bas3+95,son3-tr_baz);
		
		//transistor topragı çiziliyor
		gBellek.drawLine(x1-7,son1+10,x1+7,son1+10);
		gBellek.drawLine(x1-5,son1+15,x1+5,son1+15);
		gBellek.drawLine(x1-3,son1+20,x1+3,son1+20);
		
		gBellek.drawLine(x2-7,son2+10,x2+7,son2+10);
		gBellek.drawLine(x2-5,son2+15,x2+5,son2+15);
		gBellek.drawLine(x2-3,son2+20,x2+3,son2+20);
		
		gBellek.drawLine(x3-7,son3+10,x3+7,son3+10);
		gBellek.drawLine(x3-5,son3+15,x3+5,son3+15);
		gBellek.drawLine(x3-3,son3+20,x3+3,son3+20);
		
		//kollektor kesişimleri çiziliyor
		gBellek.drawLine(x1,y1+25,x3,y1+25);
		gBellek.drawLine(x2,y2+10,x2,y1+25);
		gBellek.drawLine(x3,y3+10,x3,y1+25);
		gBellek.fillOval(x2-atom/2,y1+25-atom/2,atom,atom);
		gBellek.fillOval(x1-atom/2,y1+25-atom/2,atom,atom);
		
		//baz kesişimleri çiziliyor
		gBellek.drawLine(x1,direnc+RBy1+15,bas2,direnc+RBy1+15);
		gBellek.drawLine(bas2,direnc+RBy1+15,bas2,son2-tr_baz-30);
		gBellek.fillOval(x1-atom/2,direnc+RBy1+15-atom/2,atom,atom);
		
		gBellek.drawLine(bas3,son3-tr_baz,bas3,son3-15);
		gBellek.drawLine(bas3,son3-15,bas2,son3-15);
		gBellek.drawLine(bas2,son3-15,bas2,son3-tr_baz+30);
		
		gBellek.setColor(Color.orange);
		if(!anahtar1){
			gBellek.drawLine(bas2+10,son2-tr_baz,bas2+10,son2-tr_baz-30);
		}
		if(anahtar1){
			gBellek.drawLine(bas2+10,son2-tr_baz,bas2,son2-tr_baz-30);
		}
		if(!anahtar2){
			gBellek.drawLine(bas2+10,son2-tr_baz,bas2+10,son2-tr_baz+30);
		}
		if(anahtar2){
			gBellek.drawLine(bas2+10,son2-tr_baz,bas2,son2-tr_baz+30);
		}
		
		gBellek.setColor(Color.black);
		gBellek.setFont(new Font("Courier",Font.BOLD,12));
		gBellek.drawString("Evirici Çıkışı= ",10,100);
		gBellek.setColor(Color.lightGray);
		gBellek.drawRect(121,86,85,20);
		gBellek.drawRect(121,86,86,21);
		gBellek.setColor(Color.blue);
		gBellek.drawRect(120,85,85,20);
		if(baz) Vout_t = Vout;
		else Vout_t = (float)VOH;
		gBellek.drawString(Float.toString(Vout_t),125,100);
		gBellek.setColor(Color.black);
		gBellek.drawString("V",Float.toString(Vout_t).length()*7+125,100);
		
		//imza
		gBellek.setFont(new Font("Courier",Font.ITALIC,14));
		gBellek.setColor(Color.red);
		gBellek.drawString("H.G.",0,20);
		
		g.drawImage(winBellek,0,0,this);
	}
	
	public void update(Graphics g){
		paint(g);
	}
}

class VTC extends Canvas{
	final int betaF=100, VCC=5, Vinput=5;
	double VOH;
	final double VBE=0.7;
	final double VIL=0.7;
	int yukseklik, genislik, eksen_x = 30, eksen_y = 20;
	double VCEsat, VIH, IBeos, Beta_forced, RC, RB;
	float Vout;
	boolean baz;
	String renk;
	Image winBellek;
	Graphics gBellek;
	
	public VTC(String renk, double RC, double RB, double VOH, double VCEsat, float Vout){
		this.renk = renk;
		this.RC = RC;
		this.RB = RB;
		this.VOH = VOH;
		this.VCEsat = VCEsat;
		this.Vout = Vout;
		this.baz = baz;
		
		if(Vout <=0.3){
		IBeos = ((VOH - VCEsat)/RC)/betaF;
		VIH = IBeos*RB + VBE;
		Beta_forced = ((VCC - VCEsat)/RC)/((Vinput - VBE)/RB);
		}
	}
	
	public void guncelle(double RC, double RB, double VOH, double VCEsat, float Vout){
		this.RC = RC;
		this.RB = RB;
		this.VOH = VOH;
		this.VCEsat = VCEsat;
		this.Vout = Vout;
		this.baz = baz;
		
		if(Vout<=0.3){
		IBeos = ((VOH - VCEsat)/RC)/betaF;
		VIH = IBeos*RB + VBE;
		Beta_forced = ((VCC - VCEsat)/RC)/((Vinput - VBE)/RB);
		}
			repaint();
	}
	
	public void paint(Graphics g){
		setBackground(Color.decode("#"+renk));
		yukseklik = this.getSize().height;
		genislik = this.getSize().width;
		
		winBellek = createImage(genislik,yukseklik);
		gBellek = winBellek.getGraphics();
		
		gBellek.setColor(Color.blue);
		gBellek.setFont(new Font("Courier",Font.BOLD,12));
		gBellek.drawString("Geçiş Eğrisi",80,15);
		
		//eksen çiziliyor
		gBellek.setColor(Color.black);
		gBellek.drawLine(eksen_x,yukseklik-eksen_y,250,yukseklik-eksen_y);
		gBellek.drawLine(eksen_x,yukseklik-eksen_y+1,250,yukseklik-eksen_y+1);
		gBellek.drawLine(eksen_x,yukseklik-eksen_y,eksen_x,10);
		gBellek.drawLine(eksen_x+1,yukseklik-eksen_y,eksen_x+1,10);
		gBellek.drawLine(eksen_x-3,15,eksen_x,10);
		gBellek.drawLine(eksen_x+4,15,eksen_x+1,10);
		gBellek.drawLine(245,yukseklik-eksen_y-3,250,yukseklik-eksen_y);
		gBellek.drawLine(245,yukseklik-eksen_y+4,250,yukseklik-eksen_y+1);
		
		gBellek.drawString("Vo",10,20);
		gBellek.drawString("Vi",230,yukseklik-eksen_y-5);
		if(VIH > VIL && Vout <=0.3){
			gBellek.setColor(Color.decode("#007846"));
			gBellek.drawLine(eksen_x,yukseklik-(int)(VOH*40)-eksen_y,eksen_x+(int)(VIL*40),
							 yukseklik-(int)(VOH*40)-eksen_y);
			gBellek.drawLine(eksen_x,yukseklik-(int)(VOH*40)-eksen_y+1,eksen_x+(int)(VIL*40),
							 yukseklik-(int)(VOH*40)-eksen_y+1);
			gBellek.drawLine(eksen_x+(int)(VIL*40),yukseklik-(int)(VOH*40)-eksen_y,
							 eksen_x+(int)(VIL*40)+(int)((VIH-VIL)*40),yukseklik-eksen_y-(int)(VCEsat*40));
			gBellek.drawLine(eksen_x+(int)(VIL*40)+1,yukseklik-(int)(VOH*40)-eksen_y,
							 eksen_x+(int)(VIL*40)+(int)((VIH-VIL)*40)+1,yukseklik-eksen_y-(int)(VCEsat*40));
			gBellek.drawLine(eksen_x+(int)(VIH*40),yukseklik-eksen_y-(int)(VCEsat*40),eksen_x+(int)(VOH*40),
							 yukseklik-eksen_y-(int)(VCEsat*40));
			gBellek.drawLine(eksen_x+(int)(VIH*40),yukseklik-eksen_y-(int)(VCEsat*40)+1,eksen_x+(int)(VOH*40),
							 yukseklik-eksen_y-(int)(VCEsat*40)+1);
			gBellek.setColor(Color.blue);
			gBellek.setFont(new Font("TimesRoman",Font.PLAIN,12));
			gBellek.drawString("VOH",0,yukseklik-(int)(VOH*40)-eksen_y);
			gBellek.drawString(Float.toString((float)VOH)+"V",35,yukseklik-(int)(VOH*40)-eksen_y);
			gBellek.drawString("VOL",0,yukseklik-(int)(VCEsat*40)-eksen_y);
			gBellek.drawString("VIL",eksen_x+(int)(VIL*40),yukseklik);
			gBellek.drawString("VIH",eksen_x+(int)(VIH*40)-10,yukseklik-eksen_y);
			gBellek.drawString("VOH",eksen_x+(int)(VOH*40),yukseklik);
			
			gBellek.setColor(Color.orange);
			gBellek.drawString("Kesim",eksen_x+5,yukseklik-(int)(VOH*40)-eksen_y+20);
			gBellek.drawString("Aktif",eksen_x+(int)(VIL*40)+(int)((VIH-VIL)/2)*40,(int)yukseklik/2);
			gBellek.drawString("Doyum",eksen_x+(int)(VIH*40),(int)yukseklik-eksen_y-(int)(VCEsat*40)-10);
			
			gBellek.setColor(Color.lightGray);
			gBellek.drawLine(eksen_x+(int)(VIL*40),yukseklik-(int)(VOH*40)-eksen_y,eksen_x+(int)(VIL*40),
							 yukseklik-eksen_y);
			gBellek.drawLine(eksen_x,yukseklik-eksen_y-(int)(VCEsat*40),eksen_x+(int)(VIH*40),
							 yukseklik-eksen_y-(int)(VCEsat*40));
			gBellek.drawLine(eksen_x+(int)(VIH*40),yukseklik-eksen_y-(int)(VCEsat*40),
							 eksen_x+(int)(VIH*40),yukseklik-eksen_y);
			gBellek.drawLine(eksen_x+(int)(VOH*40),yukseklik-eksen_y-(int)(VCEsat*40),
							 eksen_x+(int)(VOH*40),yukseklik-eksen_y);
		}
		
		g.drawImage(winBellek,0,0,this);
	}
	
	public void update(Graphics g){
		paint(g);
	}
	
	public Dimension getPreferredSize(){
		return new Dimension(300,250);
	}	
}

class VTCPanel extends Panel{
	public Dimension getPreferredSize(){
		return new Dimension(600,260);
	}
}