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

📄 banner2.java

📁 文字信息巡回显示Java小程序
💻 JAVA
字号:
import java.awt.*;
import java.net.*;


public class Banner2 extends java.applet.Applet implements Runnable 
{	

/****************************/
/*public integer variables  */
/****************************/
	public int width; 
	public int height;
	public int y = 0; //current position y
	public int j = 0; //counter
	public int i = 0; //counter
	
	public int fheight = 0; //font height
	public int xstart = 0;  //position at which x starts
	public int ystart = 0;  //position at which y starts
	public int xstop = 0;   //position at which x stops
	public int ystop = 0;   //position at which y stops
	public int msgwidth;    //width of msg window
	
/***********************/
/*public integer arrays*/
/***********************/

	public int[] catfwidth; //integer array of font widths for the category strings
	public int[] msgfwidth; //integer array of font widths for the message strings
	public int[] msgx;      //integer array of the center of message
	public int[] catx;      //integer array of the center of category
	
	boolean slept = false;
	// Other control variables
	
/*************************/
/*static object variables*/
/*************************/
	static FontMetrics metrics;
	static Graphics gc = null;
	static Graphics g;
	static Image offscreen;
	static Rectangle apprect;
	

/********************************************/
/*static variables parsed in ParseArgs class*/
/********************************************/
	static String fontname;
	static int fontsize;
	static int fontstyle;
	static Font font;
   
	static Color msgbgcolor; 	//message area backgroud color
	static Color catbgcolor; 	//category area background color
   static Color tempColor;    
	static Color linkColor;		//color of msgtext when mouse enter
	static Color msgtextcolor;	//message text color
	static Color cattextcolor;	//category text color
	
	static int totalmessages;	//total number of messages
	static String[] msgtext;	//array of message strings
	static String[] cattext;	//array of category strings
	static String[] textURL;	//array of URL strings
   
	static String valign;
	static String align;
	static String direction;
   
	static int delay;			//what does this do?
	int speed;			//what does this do?
	static int catwidth;		//width of the category space
	static int pauseDelay;		//amount of time of delay(milliseconds)
	static int xdelta;			//change in x
	static int ydelta;			//change in y

	private Thread juicer;		//our thread


/*************/
/*init method*/
/*************/
	public void init() 
	{	ParseArgs2 pa = new ParseArgs2(this);

		g = getGraphics();
          
      tempColor = msgtextcolor;
		
		//initialize the arrays
		msgfwidth = new int [totalmessages];
		msgx = new int[totalmessages];
		msgfwidth = new int[totalmessages];

		//get the width and height of the applet
		apprect = bounds();
		width = apprect.width;
		height = apprect.height;
		resize(width, height);

		offscreen = createImage(width, height);
		
		//instantiate the font object
		font = new Font(fontname, fontstyle, fontsize);

		metrics = g.getFontMetrics(font);
		fheight = metrics.getMaxAscent() - metrics.getMaxDescent() + 2;
	  
		msgwidth = width;
	  
		for( i=0; i < totalmessages; i++) 
		{	
			msgfwidth[i] = metrics.stringWidth(msgtext[i]);
			msgx[i] = ( (msgwidth - msgfwidth[i]) / 2);
		}
		i=0;

		try 
		{	if(direction.equalsIgnoreCase("BottomTop")) 
			{	ystart = y = height + fheight;
				ystop = -fheight;
				int dist = Math.abs(ystop - ystart);
				if(dist % ydelta != 0)
				ystop -= ydelta - (dist % ydelta);
				xstart = msgx[0];
				xstop = xdelta = 0;
				ydelta = -ydelta;
			}
			
			else if(direction.equalsIgnoreCase("TopBottom")) 
			{	ystart = y = -fheight;
				ystop = height + fheight;
				int dist = Math.abs(ystop - ystart);
				if(dist % ydelta != 0) 
					ystop += ydelta - (dist % ydelta);
				xstart = msgx[0];
				xstop = xdelta = 0;
			}
		}
		catch (Exception e) 
		{	ystart = y = -fheight;
				ystop = height + fheight;
				int dist = Math.abs(ystop - ystart);
				if(dist % ydelta != 0) 
					ystop += ydelta - (dist % ydelta);
				xstart = msgx[0];
				xstop = xdelta = 0;
		}
	}

/**************/
/*start method*/
/**************/
	public void start() 
	{	if(juicer == null) 
		{	juicer = new Thread(this);
			juicer.start();
		}
	}
   
/*************/
/*stop method*/
/*************/
	public void stop() 
	{	if ( (juicer != null) && (juicer.isAlive()) ) 
		{	juicer.stop();
			juicer = null;
		}
	}

/************/
/*run method*/
/************/
	public void run() 
	{
		while (juicer != null) 
		{	update(g);
			try
			{	juicer.sleep(1); 
			} 
			catch (InterruptedException e) 
			{	System.out.println("something wrong with juicer");
			}

			//test for middle
			if ((y == (height - fheight) / 2 + fheight - 1)
				&& slept == false) 
			{	try 
				{	juicer.sleep(pauseDelay);
				}	
				catch (InterruptedException e)
				{	System.out.println("juicer pauseDelay");
				} 
				slept = true;
			}
				
			// haven't reached the top
			if(y != ystop) y += ydelta; 
			
			// have reached the top
			else 
			{	y = ystart;  // reset y
				
            // go back to first message if necessary
				if (i == (totalmessages - 1) ) 
				{	i = 0; 
					slept = false; 
				}
				
            // go to next message
				else
				{	i++;
				slept = false;
				} 
			 }
		  }
	   }
	   
	   
/*****************/
/*update method  */
/*****************/
	public void update(Graphics g)
	{	paint(g); 
	}

/**************/
/*paint method*/
/**************/
	public void paint(Graphics g) 
	{	gc = offscreen.getGraphics();
	
		gc.setFont(font);
	
		//draw and fill the message rectangle
		gc.setColor(msgbgcolor);
		gc.fillRect(0, 0, width, height);
		
		//draw the message text centered at msgx
      gc.setColor(tempColor);
		gc.drawString(msgtext[i], msgx[i], y);
		
		g.drawImage(offscreen, 0, 0, null);
		gc.dispose();
	}

	public boolean mouseUp( Event evt, int x , int y ) 
	{	try {	URL thingee = new URL(textURL[i]);
				getAppletContext().showDocument(thingee);
			}
		catch (MalformedURLException e)
		{	System.out.println("hey I caught it!!!"); 
		}
		return true;
	}

	public boolean mouseEnter (Event evt, int x, int y) 
   {  showStatus(textURL[i]);
      tempColor = linkColor;
		update(g);
		return true;
	}

	public boolean mouseExit (Event evt, int x, int y) 
   {  tempColor = msgtextcolor;
		update(g);
		return true;
	}
}

⌨️ 快捷键说明

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