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

📄 win.java

📁 game for basketball. Midlet,support MIDP2.0
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import java.util.*;
import java.io.*;
import javax.microedition.rms.*;
public class win extends Object
{
	static protected Vector topWinList = new Vector();
	//static private win focusWin;
	static public win focusWin;
	public int winState=-1;
	static private Stack oldFocusList = new Stack();
	static private Vector fontList = new Vector();
	static private Vector fontListB = new Vector();
	static private String fontFile = null;
	static private String fontFileB = null;
	static private int fontWidth;
	static private int fontWidthB;
	static private int fontHeight;
	static private int fontHeightB;
	static private int fontKern;
	static private int fontKernB;
	static private byte fontSizes[];
	static private byte fontSizesB[];
	static public int buttonHighColor = 0xFFFFFF;
	protected win parent;
	public int ID;
	public int x;
	public int y;
	public int wid;
	public int hgt;
	public int style;
	protected Vector childWinList = new Vector();
	private Image image = null;
	private String string = null;
	private bhFont foreFont = null;
	private bhFont highFont = null;
	private int foreColor;
	protected int backColor = 0xFF00FF;
	protected int highColor;
	private int wordWrap[];
	public int maxLines, txtLines = 0;
	private win curControl = null;
	private win scrollable = null;
	public int backID = -1;
	private boolean CurState;
	protected boolean ready = false;
	private int scrollhgt, scrolly, scrolling;
	public static boolean autoScroll = false;
	public static int pageNum = 0;
	private void setBasics(win _parent, int _ID, int _x, int _y, int _wid, int _hgt, int _style)
	{
		parent = _parent;
		ID = _ID;
		x = _x;
		y = _y;
		wid = _wid;
		hgt = _hgt;
		style = _style;
		scrolly = 0;
		scrollhgt = hgt;
		scrolling = 0;
		if(null == parent)
			topWinList.addElement((Object)this);
		else
			parent.addChild(this);
		return;
	}
	win()
	{
		return;
	}
	win(win _parent, int _ID, int _x, int _y, int _wid, int _hgt, int _style)
	{
		setBasics(_parent, _ID, _x, _y, _wid, _hgt, _style);
		return;
	}
	private win(win _parent, int _ID, int _x, int _y, int _wid, int _hgt, int _style, Image _image, int offY)
	{
		image = _image;
		txtLines = offY;
		if(image != null)
		{
			if(image.getWidth()< _wid)
			{
				_x +=(_wid - image.getWidth())/ 2;
				_wid = image.getWidth();
			}
			if(image.getHeight()< _hgt)
			{
				_y +=(_hgt - image.getHeight())/ 2;
				_hgt = image.getHeight();
			}
		}
		setBasics(_parent, _ID, _x, _y, _wid, _hgt, _style | 0x8000);
		ready = true;
		return;
	}
	win(win _parent, int _ID, int _x, int _y, int _wid, int _hgt, int _style, int _foreColor, int _backColor, String _string)
	{
		foreColor = _foreColor;
		backColor = _backColor;
		foreFont = getColoredFont(foreColor, 0x0800 ==(0x0800 & _style));
		if(0 ==(0x0004 & style))
		{
			maxLines = _hgt / foreFont.getHeight();
			if(maxLines <= 0)
				maxLines = 1;
			wordWrap = new int[2 + 2 * maxLines];
		}
		else
			wordWrap = null;
		wid = _wid;
		style = _style;
		setBasics(_parent, _ID, _x, _y, _wid, _hgt, _style | 0x8000);
		setText(_string);
		ready = true;
		return;
	}
	private win(win _parent, int _ID, int _x, int _y, int _wid, int _hgt, int _style, int _foreColor, int _backColor, int _highColor, String _string)
	{
		string = _string;
		foreColor = _foreColor;
		backColor = _backColor;
		highColor = _highColor;
		CurState = false;
		foreFont = getColoredFont(foreColor, 0x0800 ==(0x0800 & style));
		highFont = getColoredFont(foreColor, 0x0800 ==(0x0800 & style));
		setBasics(_parent, _ID, _x, _y, _wid, _hgt, _style | 0x0100);
		ready = true;
		return;
	}
	static public void deleteAllWindows()
	{
		if(null == topWinList)
			return;
		while(!topWinList.isEmpty())
		{
			win delme =(win)topWinList.firstElement();
			delme.deleteWindow();
		}
		return;
	}
	public void deleteWindow()
	{
		win child;
		image = null;
		string = null;
		wordWrap = null;
		oldFocusList.removeElement(this);
		while(null != childWinList && !childWinList.isEmpty())
		{
			child =(win)childWinList.firstElement();
			child.deleteWindow();
		}
		childWinList = null;
		if(null == parent)
		{
			topWinList.removeElement(this);
		}
		else if(parent != null)
		{
			parent.removeChild(this);
		}
		parent = null;
		foreFont = highFont = null;
		bhCanvas.killTimers(this);
		System.gc();
		System.out.println("GC DeleteWindow()");
		return;
	}
	public void addChild(win w)
	{
		childWinList.addElement(w);
		return;
	}
	public boolean removeChild(win w)
	{
		return childWinList.removeElement(w);
	}
	public void setImage(Image i)
	{
		image = i;
		return;
	}
	public void setText(String s)
	{
		string = s;
		if(null == string ||(0x0100 ==(0x0100 & style)))
		{
			txtLines = 0;
		}
		else if(0x0004 ==(0x0004 & style))
		{
			maxLines = gWordWrapText(foreFont, string, null, wid, 0x7FFF, false);
			if(maxLines <= 0)
				maxLines = 1;
			wordWrap = new int[2 + 2 * maxLines];
			txtLines = gWordWrapText(foreFont, string, wordWrap, wid, maxLines, false);
			scrollhgt = 2 + foreFont.getHeight()* txtLines;
			if(scrollhgt < hgt)
				scrollhgt = hgt;
			else
			{
				if(win.autoScroll)
					scrolling = 1;
				else
					scrolling = 0;
			}
			Basketball.myCanvas.killTimers(this);
			Basketball.myCanvas.addTimer(this, 125);
			scrolly = hgt / -4;
		}
		else if(0x0008 ==(0x0008 & style))
		{
			txtLines = gWordWrapText(foreFont, string, wordWrap, wid, maxLines, false);
		}
		else
		{
			txtLines = gWordWrapText(foreFont, string, wordWrap, wid, maxLines, false);
		}
		return;
	}
	public void setScroll(int sc)
	{
		scrolling = sc;
	}
	public void setColors(int _foreColor, int _backColor)
	{
		foreColor = _foreColor;
		backColor = _backColor;
		if(0xFF00FF != backColor)
			foreFont = getColoredFont(foreColor, 0x0800 ==(0x0800 & style));
		return;
	}
	static public void paintAllWindows(Graphics g)
	{
		try
		{
			int size = topWinList.size();
			for(int i = 0; i < size; i++)
			{
				((win)topWinList.elementAt(i)).paintWin(g);
			}
		}
		catch(RuntimeException e)
		{
		}
		return;
	}
	public void paintWin(Graphics g)
	{
		if(0 !=(style & 0x1000)|| null == childWinList || !ready)
			return;
		g.setClip(x, y, wid, hgt);
		paint(g);
		try
		{
			int size = childWinList.size();
			for(int i = 0; i < size; i++)
			{
				((win)childWinList.elementAt(i)).paintWin(g);
			}
		}
		catch(RuntimeException e)
		{
		}
		return;
	}
	public void paint(Graphics g)
	{
		if(!ready)
			return;
		if(0x0100 ==(style & 0x0100))
			Basketball.userButtonWinPaint(g, this);
		if(null != image)
		{
			g.drawImage(image, x, y - txtLines, Graphics.LEFT | Graphics.TOP);
			return;
		}
		int back;
		bhFont font;
		if((0x2000 | 0x0100)==(style &(0x2000 | 0x0100)))
		{
			back = highColor;
			font = highFont;
		}
		else
		{
			back = backColor;
			font = foreFont;
		}
		if(0xFF00FF != back)
		{
			if(0 !=(style & 0x4000))
			{
				back =(back & 0x00FEFEFE)>> 1;
			}
			g.setColor(back);
			g.fillRect(x, y, wid, hgt);
			if(0x0200 ==(style & 0x0200))
				return;
			if((0x2000 | 0x0100)==(style &(0x2000 | 0x0100)))
			{
				g.setColor(0x000099);
				g.fillRect(x, y, wid, 1);
				g.setColor(0xFFFFFF);
				g.fillRect(x, y + hgt - 1, wid, 1);
			}
		}
		if(null != string && null != font)
		{
			if(0 != txtLines)
			{
				int xpos;
				int ypos;
				int flags;
				if(0 !=(style & 0x0001))
				{
					xpos = x + wid;
					flags = 0x04;
				}
				else if(0 !=(style & 0x0002))
				{
					xpos = x + 2;
					flags = 0x00;
				}
				else
				{
					xpos = x + wid / 2;
					flags = 0x02;
				}
				if(scrollhgt <= hgt)
					ypos = y +(hgt - txtLines * font.getHeight())/ 2;
				else
					ypos = y - scrolly;
				for(int i = 0; i < txtLines; i++)
				{
					if(wordWrap[i * 2 + 1]> 0)
						font.stringChar(g, xpos, ypos, string.substring(wordWrap[i * 2], wordWrap[i * 2 + 1]), - 1, flags | 0x00);
					ypos += font.getHeight();
				}
			}
			else
			    font.stringChar(g, x + wid / 2, y + hgt / 2-3, string, - 1, 0x02 | 0x08);
//			    font.stringChar(g, x + wid / 2, y + hgt / 2, string, - 1, 0x02 | 0x08);
		}
	/*	g.setColor(0xff0000);
		g.drawString("temp= "+FrontEnd.temp,0,0,g.TOP|g.LEFT);*/
		return;
	}
	public void repaintWin()
	{
		Basketball.myCanvas.repaint(x, y, wid, hgt);
		if(scrolling != 0)
		{
			Basketball.myCanvas.serviceRepaints();
		}
		else
			Thread.yield();
		return;
	}
	public int message(int msg, int param1, int param2)
	{
		if(0x0200 ==(style & 0x0200))
		{
			if(msg == 0x0201 ||
				msg == 0x0202 ||
				msg == 0x0203 ||
				msg == 0x0205 ||
				msg == 0x0206)
			{
				if(!ready)
					return 1;
				if((null != scrollable)&&
					((msg == 0x0201)||(msg == 0x0202))&&
					(0 != scrollable.message(msg, param1, param2)))
				{
					return 1;
				}
				if(msg == 0x0201)
				{
					if(0 !=(style & 0x0001))
					{
						if(param1 == bhCanvas.UP || param2 == Canvas.KEY_NUM2)
						{
							arrowFocus(0, - 1);
							return 1;
						}
						else if(param1 == bhCanvas.DOWN || param2 == Canvas.KEY_NUM8)
						{
							arrowFocus(0, 1);
							return 1;
						}
					}
					if(0 !=(style & 0x0002))
					{
						if(param1 == bhCanvas.LEFT || param2 == Canvas.KEY_NUM4)
						{
							arrowFocus(- 1, 0);
							return 1;
						}
						else if(param1 == bhCanvas.RIGHT || param2 == Canvas.KEY_NUM6)
						{
							arrowFocus(1, 0);
							return 1;
						}
					}
				}
				else if(msg == 0x0205 && -1 != backID)
				{
					return message(0x0109, backID, 0);
				}
				if(null != curControl)
					return curControl.message(msg, param1, param2);
			}
		}
		switch(msg)
		{
			case 0x0107 :
			{
				CurState = false;
				return 1;
			}
			case 0x0100 :
			{
				style |=(0x8000 | 0x4000);
				if(0 == param1)
					repaintWin();
				return 1;
			}
			case 0x0101 :
			{
				style &= ~(0x8000 | 0x4000);
				if(0 == param1)
					repaintWin();
				return 1;
			}
			case 0x0102 :
			{
				if(0 ==(style & 0x2000))
				{
					style |= 0x2000;
					if(null != curControl)
						curControl.message(msg, param1, param2);
					repaintWin();
				}
				return 1;
			}
			case 0x0103 :
			{
				CurState = false;
				if(0 !=(style & 0x2000))
				{
					style &= ~0x2000;
					if(null != curControl)
						curControl.message(msg, param1, param2);
					repaintWin();
				}
				return 1;
			}
			case 0x0104 :
			{
				if(0 != param1)
				{
					if(0 !=(style & 0x1000))
					{
						style &= ~0x1000;
						repaintWin();
					}
				}
				else
				{
					if(0 ==(style & 0x1000))
					{
						style |= 0x1000;
						repaintWin();

⌨️ 快捷键说明

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