// Source file: Stacja/stacja.java package Stacja; import java.awt.*; import java.awt.*; import java.applet.Applet; public class stacja extends Applet implements Runnable { public wyswietlacz wys = new wyswietlacz (this, 0, 0); public kasa KASA = new kasa (0, 400); public zbiornik ZbiornikON = new zbiornik (150, 517); public zbiornik ZbiornikPB = new zbiornik (150, 547); public dystrybutorON dysON = new dystrybutorON (this, 30, 30); public dystrybutorON dysON1 = new dystrybutorON (this, 430, 30); public dystrybutorPB dysPB = new dystrybutorPB (this, 230, 30); public dystrybutorPB dysPB1 = new dystrybutorPB (this, 630, 30); Thread sprzedawca; Image numerki; Image automat; Image automat1; Image sw_red; Image sw_ziel; /** @roseuid 375C450B02F1 */ public void start() { if (sprzedawca == null) { sprzedawca = new Thread(this); sprzedawca.start(); } resize(830,650); } /** @roseuid 375C450B02F2 */ public void stop() { if (sprzedawca != null) { sprzedawca.stop(); sprzedawca = null; } } /** @roseuid 375C450B02F3 */ public boolean mouseDown(Event evt, int x, int y) { dysON.mouseDown(x,y); dysON1.mouseDown(x,y); dysPB.mouseDown(x,y); dysPB1.mouseDown(x,y); if(KASA.wybierz.wcisniecie(x,y)) KASA.Wybierz(); if(ZbiornikPB.napel.wcisniecie(x,y)) ZbiornikPB.Napelnij(); if(ZbiornikON.napel.wcisniecie(x,y)) ZbiornikON.Napelnij(); repaint(); return true; } /** @roseuid 375C450B02F7 */ public void run() { boolean odswiez=false; while (true){ odswiez=dysON.run(); try { Thread.sleep(100); } catch (InterruptedException e) { } odswiez=(dysON1.run() || odswiez); try { Thread.sleep(100); } catch (InterruptedException e) { } odswiez=(dysPB.run() || odswiez); try { Thread.sleep(100); } catch (InterruptedException e) { } odswiez=(dysPB1.run() || odswiez); if(odswiez)repaint(); odswiez=false; try { Thread.sleep(100); } catch (InterruptedException e) { } } } /** @roseuid 375C450B02F8 */ public void init() { numerki = getImage(getCodeBase(),"strip1.gif"); automat = getImage(getCodeBase(),"dyson.jpg"); automat1 = getImage(getCodeBase(),"dys94.jpg"); sw_ziel= getImage(getCodeBase(),"ziel.jpg"); sw_red = getImage(getCodeBase(),"red.jpg"); setBackground(Color.white); ZbiornikON.Napelnij(); ZbiornikPB.Napelnij(); } /** @roseuid 375C450B02F9 */ public void update(Graphics g) { paint(g); } /** @roseuid 375C450B02FB */ public void paint(Graphics g) { dysON.paint(g,true); dysON1.paint(g,true); dysPB.paint(g,true); dysPB1.paint(g,true); ZbiornikON.paint(g); ZbiornikPB.paint(g); KASA.paint(g); } } //************************************************* // Source file: Stacja/dystrybutor.java package Stacja; import java.awt.Graphics; public class dystrybutor { public int litry; public int zaplata; int x; int y; byte AktualnyStan = 1; static byte Tabela[][] = {{2,0,0,0,0},{0,3,0,4,0},{0,0,2,0,0},{0,0,0,0,1}}; public przycisk raczka; public przycisk spust; public przycisk kasuj; public RysujDystrybutor narysuj; public wyswietlacz WyswietlLitry = new wyswietlacz (); public wyswietlacz WyswietlZaplate = new wyswietlacz (); public stacja STACJA; public swiatlo SW; /** @roseuid 375C450A0333 */ dystrybutor() { } /** @roseuid 375C450A0334 */ byte Stan() { return AktualnyStan; } /** @roseuid 375C450A0335 */ void init() { SW = new swiatlo(STACJA,x+100,y+20); AktualnyStan=1; WyswietlLitry.setxy(x+60,y+52); WyswietlZaplate.setxy(x+60,y+70); raczka=new przycisk(x+70,y+220); raczka.zmienName("raczka"); spust=new przycisk(x+70,y+260); spust.zmienName("spust"); kasuj=new przycisk(x+70,y+390); kasuj.zmienName("kasuj"); raczka.aktywnosc(true); spust.aktywnosc(false); kasuj.aktywnosc(false); } /** @roseuid 375C450A0336 */ public void ZacznijNalewac() { litry=0; zaplata=0; WyswietlLitry.zmien(litry); WyswietlZaplate.zmien(zaplata); } /** @roseuid 375C450A0337 */ public void kasuj() { litry=0; zaplata=0; WyswietlLitry.zmien(litry); WyswietlZaplate.zmien(zaplata); } /** @roseuid 375C450A0338 */ public void mouseDown(int x, int y) { if(raczka.wcisniecie(x,y)) if(Stan()!=2) eventNotify((byte)0); else eventNotify((byte)3); if(spust.wcisniecie(x,y)) if(Stan()!=3) eventNotify((byte)1); else eventNotify((byte)2); if(kasuj.wcisniecie(x,y)) eventNotify((byte)4); } /** @roseuid 375C450A033B */ boolean eventNotify(byte evId) { boolean res; res=(Tabela[AktualnyStan-1][evId]==0); if(!res){ AktualnyStan=Tabela[AktualnyStan-1][evId]; switch(evId) { case 0 : raczka.aktywnosc(false); spust.aktywnosc(true); break; //chyba na razie nic case 1 : raczka.aktywnosc(false); break; //mozna pokombinowac z lampkami case 2 : raczka.aktywnosc(true); break; case 3 : raczka.aktywnosc(false); spust.aktywnosc(false); SW.zmien(); kasuj.aktywnosc(true); break; case 4 : STACJA.KASA.zaplac(zaplata); kasuj(); SW.zmien(); kasuj.aktywnosc(false); raczka.aktywnosc(true); spust.aktywnosc(false); break; } } return res; } /** @roseuid 375C450A033D */ public void paint(Graphics g, boolean all) { if(all) narysuj.rysuj(g); SW.rysuj(g); WyswietlLitry.maluj(g); WyswietlZaplate.maluj(g); raczka.rysuj(g); spust.rysuj(g); kasuj.rysuj(g); } } //************************************************************ // Source file: Stacja/dystrybutorON.java package Stacja; public class dystrybutorON extends dystrybutor { private int cenaON; /** @roseuid 375C450A002C */ public dystrybutorON(stacja parent, int xx, int yy, int a) { STACJA=parent; ZmienCene(a); x=xx; y=yy; super.init(); narysuj=new RysujDystrybutor(STACJA,x,y,true); } /** @roseuid 375C450A0031 */ public dystrybutorON(stacja parent, int xx, int yy) { STACJA=parent; ZmienCene(2); x=xx; y=yy; super.init(); narysuj=new RysujDystrybutor(STACJA,x,y,true); } /** @roseuid 375C450A0035 */ boolean run() { if(Stan()==3){ nalewaj(); return true; } return false; } /** @roseuid 375C450A0036 */ public synchronized boolean nalewaj() { boolean ok=true; ok=STACJA.ZbiornikON.ZeZbiornika(1); if(ok){ litry++; zaplata+=cenaON*1; // STACJA.KASA.zaplac(1*cenaON); WyswietlLitry.zmien(litry); WyswietlZaplate.zmien(zaplata); } return ok; } /** @roseuid 375C450A0037 */ public void ZmienCene(int a) { cenaON=a; } } //************************************************************ // Source file: Stacja/dystrybutorPB.java package Stacja; public class dystrybutorPB extends dystrybutor { private int cenaPB; /** @roseuid 375C450A0067 */ public dystrybutorPB(stacja parent, int xx, int yy, int a) { STACJA=parent; ZmienCene(a); x=xx; y=yy; super.init(); narysuj=new RysujDystrybutor(STACJA,x,y,false); } /** @roseuid 375C450A006C */ public dystrybutorPB(stacja parent, int xx, int yy) { STACJA=parent; ZmienCene(3); x=xx; y=yy; super.init(); narysuj=new RysujDystrybutor(STACJA,x,y,false); } /** @roseuid 375C450A0070 */ boolean run() { if(Stan()==3){ nalewaj(); return true; } return false; } /** @roseuid 375C450A0071 */ public synchronized boolean nalewaj() { boolean ok=true; ok=STACJA.ZbiornikPB.ZeZbiornika(1); if(ok){ litry++; zaplata+=cenaPB*1; //STACJA.KASA.zaplac(1*cenaPB); WyswietlLitry.zmien(litry); WyswietlZaplate.zmien(zaplata); } return ok; } /** @roseuid 375C450A0072 */ public void ZmienCene(int a) { cenaPB=a; } } //************************************************************ // Source file: Stacja/kasa.java package Stacja; import java.awt.Graphics; public class kasa { private int aktualnie; int x; int y; public wyswietlacz wyswietlStan = new wyswietlacz (); public przycisk wybierz; public RysujKase rysk; /** @roseuid 375C450A00DE */ kasa(int xx, int yy) { aktualnie=0; x=xx; y=yy; wybierz=new przycisk(x+300,y+177); rysk= new RysujKase(x,y); wyswietlStan.setxy(x+150,y+177); wybierz.zmienName("wybierz"); } /** @roseuid 375C450A00E1 */ public synchronized void zaplac(int ile) { aktualnie+=ile; wyswietlStan.zmien(aktualnie); } /** @roseuid 375C450A0104 */ public synchronized void Wybierz() { aktualnie=0; wyswietlStan.zmien(aktualnie); } /** @roseuid 375C450A0105 */ public void paint(Graphics g) { wyswietlStan.maluj(g); wybierz.rysuj(g); rysk.rysuj(g); } } //************************************************************ // Source file: Stacja/przycisk.java package Stacja; import java.awt.Graphics; import java.awt.Font; import java.awt.Color; public class przycisk { int x; int y; int wys = 20; int szer = 70; private String name = "przyc"; private Color kolor = Color.black; /** @roseuid 375C450A0175 */ przycisk(int xx, int yy) { x=xx; y=yy; } /** @roseuid 375C450A0178 */ public void aktywnosc(boolean a) { if(a) kolor=Color.black; else kolor=Color.gray; } /** @roseuid 375C450A017A */ boolean wcisniecie(int gdzieX, int gdzieY) { if(gdzieX>=x && gdzieX<=x+szer && gdzieY>=y && gdzieY<=y+wys){ return true; } else{return false;} } /** @roseuid 375C450A017D */ void zmienName(String s) { name=s; } /** @roseuid 375C450A017F */ public void setxy(int xx, int yy) { x=xx; y=yy; } /** @roseuid 375C450A0182 */ void rysuj(Graphics g) { g.setColor(kolor); // g.fillRect(x,y,szer,wys); // g.setColor(Color.black); g.drawRect(x,y,szer,wys); g.drawString(name,x+20,y+wys-5); } } //************************************************************ // Source file: Stacja/RysujDystrybutor.java package Stacja; import java.awt.Graphics; import java.awt.Font; import java.awt.Color; public class RysujDystrybutor { int x; int y; boolean on; static stacja STACJA; private Font czcionka = new Font ("TimesRoman", Font.BOLD, 70); private Font czcionka2 = new Font ("Arial", Font.PLAIN, 25); /** @roseuid 375C450A0220 */ RysujDystrybutor(stacja xxx, int xx, int yy, boolean ON) { STACJA=xxx; x=xx; y=yy; on=ON; } /** @roseuid 375C450A0225 */ RysujDystrybutor(stacja xxx) { STACJA=xxx; } /** @roseuid 375C450A0227 */ public void rysuj(Graphics g) { if(on){ int wid=STACJA.automat.getWidth(STACJA); int hei=STACJA.automat.getHeight(STACJA); g.drawImage(STACJA.automat,x,y,wid,hei,STACJA); }else{ int wid=STACJA.automat1.getWidth(STACJA); int hei=STACJA.automat1.getHeight(STACJA); g.drawImage(STACJA.automat1,x,y,wid,hei,STACJA); } } } //************************************************************ // Source file: Stacja/RysujKase.java package Stacja; import java.awt.Graphics; import java.awt.Font; import java.awt.Color; public class RysujKase { int x; int y; private Font czcionka = new Font ("TimesRoman", Font.BOLD, 30); private Font czcionka2 = new Font ("Arial", Font.PLAIN, 15); /** @roseuid 375C45090373 */ RysujKase(int xx, int yy) { x=xx; y=yy; } /** @roseuid 375C45090376 */ public void rysuj(Graphics g) { g.setFont(czcionka); g.drawString("KASA",x+380,y); g.setFont(czcionka2); g.drawString("stan kasy: ",x+30,y+190); g.drawString("złotych ",x+230,y+190); g.drawString("zbiornik ON ",x+30,y+130); g.drawString("litrów ",x+230,y+130); g.drawString("zbiornik PB ",x+30,y+160); g.drawString("litrów ",x+230,y+160); } } //************************************************************ // Source file: Stacja/swiatlo.java package Stacja; import java.awt.Graphics; import java.awt.Font; import java.awt.Color; public class swiatlo { int x; int y; boolean on; static stacja STACJA; /** @roseuid 375C450B035F */ swiatlo(stacja xxx, int xx, int yy) { STACJA=xxx; x=xx; y=yy; on=true; } /** @roseuid 375C450B0363 */ swiatlo(stacja xxx) { STACJA=xxx; } /** @roseuid 375C450B0365 */ public void zmien() { on= !on; } /** @roseuid 375C450B0366 */ public void rysuj(Graphics g) { if(on){ int wid=STACJA.sw_ziel.getWidth(STACJA); int hei=STACJA.sw_ziel.getHeight(STACJA); g.drawImage(STACJA.sw_ziel,x,y,wid,hei,STACJA); }else{ int wid=STACJA.sw_red.getWidth(STACJA); int hei=STACJA.sw_red.getHeight(STACJA); g.drawImage(STACJA.sw_red,x,y,wid,hei,STACJA); } } } //************************************************************ // Source file: Stacja/wyswietlacz.java package Stacja; import java.awt.Graphics; import java.awt.Image; public class wyswietlacz { private int liczba; int s; int tab[] = new int [6]; int x; int y; static stacja STACJA; /** @roseuid 375C450B03D2 */ wyswietlacz(stacja xxx, int xx, int yy) { liczba=0; STACJA=xxx; x=xx; y=yy; } /** @roseuid 375C450B03D6 */ wyswietlacz() { liczba=0; x=0; y=0; } /** @roseuid 375C450B03D7 */ wyswietlacz(stacja xxx, int xx, int yy, int a) { liczba=a; STACJA=xxx; x=xx; y=yy; } /** @roseuid 375C450C0017 */ public void setxy(int xx, int yy) { x=xx; y=yy; } /** @roseuid 375C450C001A */ public void maluj(Graphics g) { s=liczba; tab[0]=s%10; s/=10; tab[1]=s%10; s/=10; tab[2]=s%10; s/=10; tab[3]=s%10; s/=10; tab[4]=s%10; s/=10; tab[5]=s%10; s/=10; g.drawImage(STACJA.numerki,x ,y,x+10,y+14,tab[5]*10,0,(tab[5]+1)*10,14,STACJA); g.drawImage(STACJA.numerki,x+11,y,x+21,y+14,tab[4]*10,0,(tab[4]+1)*10,14,STACJA); g.drawImage(STACJA.numerki,x+22,y,x+32,y+14,tab[3]*10,0,(tab[3]+1)*10,14,STACJA); g.drawImage(STACJA.numerki,x+33,y,x+43,y+14,tab[2]*10,0,(tab[2]+1)*10,14,STACJA); g.drawImage(STACJA.numerki,x+44,y,x+54,y+14,tab[1]*10,0,(tab[1]+1)*10,14,STACJA); g.drawImage(STACJA.numerki,x+55,y,x+65,y+14,tab[0]*10,0,(tab[0]+1)*10,14,STACJA); } /** @roseuid 375C450C001C */ public void zmien(int a) { liczba=a; } } //************************************************************ // Source file: Stacja/zbiornik.java package Stacja; import java.awt.Graphics; public class zbiornik { private final int pojemnosc = 300; private int aktualnie = 30; int x; int y; public wyswietlacz WyswietlIle = new wyswietlacz (); public przycisk napel; /** @roseuid 375C450C0085 */ zbiornik(int xx, int yy) { x=xx; y=yy; WyswietlIle.setxy(x,y); napel=new przycisk(x+150,y); napel.zmienName("napelnij"); } /** @roseuid 375C450C0088 */ public synchronized void Napelnij() { aktualnie=pojemnosc; WyswietlIle.zmien(aktualnie); } /** @roseuid 375C450C0089 */ public synchronized boolean ZeZbiornika(int ile) { if( aktualnie>=ile ){ aktualnie-=ile; WyswietlIle.zmien(aktualnie); return true; }else{ return false; } } /** @roseuid 375C450C008B */ public void paint(Graphics g) { napel.rysuj(g); WyswietlIle.maluj(g); } } //************************************************************