⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gui.java

📁 Reader Writer Problem to solve synchronization issues
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
// Methods to control the Gui thru Reader and Writer threads./*---------------------------------------------*/public synchronized void   start_to_mutex_db(int tnum){	tn=tnum;        Currentimg = RWimg[tn];	Currentpos[tn][0]=init[tn][0];	Currentpos[tn][1]=init[tn][1]; object_move(init[tnum][0],init[tnum][1],		mutexdb[tn][0],mutexdb[tn][1],move[3]);}public synchronized void   db_to_start(int tnum){   	tn=tnum;        Currentimg = RWimg[tn];	Currentpos[tn][0]=dbtop[0];	Currentpos[tn][1]=dbtop[1]; object_move(Currentpos[tn][0],Currentpos[tn][1],                init[tn][0],init[tn][1],move[2]);}/*---------------------------------------------*/public synchronized void   mutex_lock(int tnum){   	tn=tnum;        Currentimg = RWimg[tn];	Current_mutexlock=mutexlock; 	Graphics g=getGraphics();        g.clearRect(Currentpos[tn][0],Currentpos[tn][1],                Currentimg.getWidth(this),Currentimg.getHeight(this));	Currentpos[tn][0]=mutexbottom[0];	Currentpos[tn][1]=mutexbottom[1];        g.drawImage(Currentimg,mutexbottom[0],mutexbottom[1],this);        g.clearRect(mutex[0],mutex[1],                Current_mutexlock.getWidth(this),			Current_mutexlock.getHeight(this));        g.drawImage(mutexlock,mutex[0],mutex[1],this);        g.dispose();}public synchronized void   mutex_unlock(int tnum, int num){	int abc; 	Graphics g=getGraphics();   	tn=tnum;	abc=num;        Currentimg = RWimg[tn];	Current_mutexlock=mutexunlock;        	g.clearRect(mutex[0],mutex[1],                	Current_mutexlock.getWidth(this),				Current_mutexlock.getHeight(this));        	g.drawImage(mutexunlock,mutex[0],mutex[1],this);	if (num==1)	{        	g.dispose();        	object_move(mutexbottom[0],mutexbottom[1],			mutexright[tn][0],mutexright[tn][1],move[0]);	}	else if(num==2)	{        	g.clearRect(Currentpos[tn][0],Currentpos[tn][1],	                Currentimg.getWidth(this),Currentimg.getHeight(this));		Currentpos[tn][0]=mutexdb[tn][0];		Currentpos[tn][1]=mutexdb[tn][1];	       g.drawImage(Currentimg,Currentpos[tn][0],Currentpos[tn][1],this);		g.dispose();                object_move(mutexdb[tn][0],mutexdb[tn][1],				init[tn][0],init[tn][1],move[3]);	}}/*---------------------------------------------*/public synchronized void   db_lock(int tnum){        tn=tnum;        Currentimg = RWimg[tn];	Current_dblock=dblock; 	Graphics g=getGraphics();        g.clearRect(Currentpos[tn][0],Currentpos[tn][1],	             Currentimg.getWidth(this),Currentimg.getHeight(this));        g.clearRect(db[0],db[1],               	Current_dblock.getWidth(this),			Current_dblock.getHeight(this));        g.drawImage(dblock,db[0],db[1],this);	Currentpos[tn][0]=dbbottom[0];	Currentpos[tn][1]=dbbottom[1];        g.drawImage(Currentimg,Currentpos[tn][0],Currentpos[tn][1],this);        g.dispose();}public synchronized void   db_unlock(int tnum){	Graphics g=getGraphics();        tn=tnum;        Currentimg = RWimg[tn];	Current_dblock=dbunlock;        g.clearRect(Currentpos[tn][0],Currentpos[tn][1],               	Currentimg.getWidth(this),			Currentimg.getHeight(this));	Currentpos[tn][0]=dbtop[0];	Currentpos[tn][1]=dbtop[1];        g.drawImage(Currentimg,Currentpos[tn][0],Currentpos[tn][1],this);        g.clearRect(db[0],db[1],               	Current_dblock.getWidth(this),			Current_dblock.getHeight(this));        g.drawImage(dbunlock,db[0],db[1],this);        g.dispose();}/*---------------------------------------------*/public synchronized void   db_down_to_mutex(int tnum){        tn=tnum;        Currentimg = RWimg[tn];	object_move(dbbottom[0],dbbottom[1],			mutexbottom[0],mutexbottom[1],move[0]);}public synchronized void   db_up_to_mutex(int tnum){        tn=tnum;        Currentimg = RWimg[tn];	object_move(dbtop[0],dbtop[1],			mutexbottom[0],mutexbottom[1],move[0]);}public synchronized void   dbase_to_mutex(int tnum){  	tn=tnum;	Currentimg = RWimg[tn];        object_move(dbasepos[tn][0],dbasepos[tn][1],                        mutexdb[tn][0],mutexdb[tn][1],move[1]);}public synchronized void   dbase_to_db(int tnum){  	tn=tnum; 	Currentimg = RWimg[tn];        object_move(dbasepos[tn][0],dbasepos[tn][1],                        dbbottom[0],dbbottom[1],move[3]);}/*---------------------------------------------*/public synchronized void   dbase_data(int tnum, int val){	Graphics g=getGraphics();        tn=tnum;	readval[tn]=val;	 g.clearRect(datapos[tn][0],datapos[tn][1],                textbox.getWidth(this),textbox.getHeight(this));	g.drawImage(textbox,datapos[tn][0],datapos[tn][1],this); 	if((tn==0)||(tn==3))        g.setColor(Color.red);        else if((tn==2)||(tn==4))        g.setColor(Color.blue);        else        g.setColor(Color.green);   	g.setFont(new Font("Helvetica",Font.BOLD,14));	g.drawString(String.valueOf(readval[tn]),datapos[tn][0]+15,datapos[tn][1]+18);	g.dispose();}public synchronized void   read_dbase(int tnum){// code to move from mutexright to dbase;	tn=tnum; 	Currentimg = RWimg[tn];	object_move(mutexright[tn][0],mutexright[tn][1],                        dbasepos[tn][0],dbasepos[tn][1],move[2]);}public synchronized void   db_to_dbase(int tnum){// code to move from dbbottom to dbase;	tn=tnum;	 Currentimg = RWimg[tn];	object_move(dbbottom[0],dbbottom[1],                        dbasepos[tn][0],dbasepos[tn][1],move[2]);}public synchronized void   write_dbase(int tnum, int val){	writeval=val;	Graphics g=getGraphics();  	g.clearRect(writebox[0],writebox[1],                textbox.getWidth(this),textbox.getHeight(this));        g.drawImage(textbox,writebox[0],writebox[1],this);		g.setFont(new Font("Helvetica",Font.BOLD,14));        g.drawString(String.valueOf(writeval),writebox[0]+15,writebox[1]+18);	g.dispose();}/*---------------------------------------------*/public synchronized void   rc_plus_minus(int tnum, int val1){	rcval=val1;	tn=tnum;	Currentimg=RWimg[tn];        object_move(mutexbottom[0],mutexbottom[1],			mutexright[tn][0],mutexright[tn][1],move[0]);	Graphics g=getGraphics();        tn=tnum;         g.clearRect(rcpos[0],rcpos[1],                textbox.getWidth(this),textbox.getHeight(this));        g.drawImage(textbox,rcpos[0],rcpos[1],this);   	g.setFont(new Font("Helvetica",Font.BOLD,14));        g.drawString(String.valueOf(rcval),rcpos[0]+15,rcpos[1]+18);        g.dispose();}public synchronized void   rc_one_db(int tnum){  	tn=tnum;        Currentimg=RWimg[tn];        object_move(mutexright[tn][0],mutexright[tn][1],                        dbleft[0],dbleft[1],move[0]);}public synchronized void   rc_zero_db(int tnum){	tn=tnum;	Currentimg=RWimg[tn];	object_move(mutexright[tn][0],mutexright[tn][1],			dbbottom[0],dbbottom[1],move[0]);}public synchronized void   rc_not_one_zero(int tnum){  	tn=tnum;        Currentimg=RWimg[tn];        object_move(mutexright[tn][0],mutexright[tn][1],                        mutexbottom[0],mutexbottom[1],move[0]);}public synchronized void   rc_one_zero(int tnum,int cas){	int cases;// add rc=1,0 flashing code; flash only when rc=0,1;       	tn=tnum;	cases=cas;	Color color[]= {Color.red,Color.green,Color.blue};	Graphics g=getGraphics();	if(cases==1)	{	 blinkerflag=true;	 while(blinkerflag==true)	  {	  for(int i=0;i<3;i++)	   {        	g.clearRect(rcpos[0],rcpos[1],	                textbox.getWidth(this),textbox.getHeight(this));        	g.drawImage(textbox,rcpos[0],rcpos[1],this);		g.setColor(color[i]);        	g.setFont(new Font("Helvetica",Font.BOLD,14));        	g.drawString(String.valueOf(rcval),rcpos[0]+15,rcpos[1]+18);		pause(100);	    }	   }  	}	else if (cases==2)		   for (int j= 0; j<5; j++)	   {	      for(int i=0;i<3;i++)	      {        	g.clearRect(rcpos[0],rcpos[1],	                textbox.getWidth(this),textbox.getHeight(this));        	g.drawImage(textbox,rcpos[0],rcpos[1],this);		g.setColor(color[i]);        	g.setFont(new Font("Helvetica",Font.BOLD,14));        	g.drawString(String.valueOf(rcval),rcpos[0]+15,rcpos[1]+18);		pause(100);	      }	    }	  	        g.dispose();}/*---------------------------------------------*/public final void updatescale(int scal){	scale=scal;// 	System.out.println("New Scale : "+scale);}	public final void rc_reset(){	blinkerflag=false;	Graphics g=getGraphics();		g.clearRect(rcpos[0],rcpos[1],                        textbox.getWidth(this),textbox.getHeight(this));                g.drawImage(textbox,rcpos[0],rcpos[1],this);	 	g.setColor(Color.black);                g.setFont(new Font("Helvetica",Font.BOLD,14));                g.drawString(String.valueOf(rcval),rcpos[0]+15,rcpos[1]+18);	g.dispose();		}}// end public class Gui

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -