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

📄 win.java

📁 game for basketball. Midlet,support MIDP2.0
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		releaseFocus(this);
		deleteWindow();
		System.gc();
		repaintWin();
		return;
	}
	public int getDlgItemFocus()
	{
		if(null != curControl)
			return curControl.ID;
		else
			return 0;
	}
	public win getDlgItem(int _ID)
	{
		for(Enumeration e = childWinList.elements(); e.hasMoreElements();)
		{
			win cur =(win)e.nextElement();
			if(cur.ID == _ID)
				return cur;
		}
		return null;
	}
	public void setFocusID(int _ID)
	{
		win tmp = getDlgItem(_ID);
		if(null != tmp)
			changeCurrentControl(tmp);
		return;
	}
	public int sendDlgItemMessage(int _ID, int msg, int p1, int p2)
	{
		win tmp = getDlgItem(_ID);
		if(null != tmp)
			return tmp.message(msg, p1, p2);
		return 0;
	}
	win(win _parent, String szFile, String szName, boolean prog)
	{
		InitWin(_parent, szFile, szName, prog);
	}
	public void InitWin(win _parent, String szFile, String szName, boolean prog)
	{
		if(szName.equals("Splash3"))
		{
			win.autoScroll = true;
		}
		else
		{
			win.autoScroll = false;
		}
		parent = _parent;
		ID = 1;
		curControl = null;
		backColor = 0;
		DataInputStream fpIn;
		if(null !=(fpIn = OpenResourceFile(szFile, szName)))
		{
			int numControls;
			try
			{
				style = 0x0200 | fpIn.readInt();
				numControls = fpIn.readInt();
				x = 0xFF &(int)fpIn.readByte();
				y = 0xFF &(int)fpIn.readByte();
				wid = 0xFF &(int)fpIn.readByte();
				hgt = 0xFF &(int)fpIn.readByte();
				if(wid > Basketball.myCanvas.getWidth())
					wid = Basketball.myCanvas.getWidth();
				if(hgt > Basketball.myCanvas.getHeight())
					hgt = Basketball.myCanvas.getHeight();
				if(prog)
				{
					prog = true;
					Basketball.myCanvas.maxProgress = numControls + 1;
					Basketball.myCanvas.incrementProgress();
				}
				for(int i = 0; i < numControls; i++)
				{
					int _id, _style, _fore, _back, _type, _x, _y, _wid, _hgt;
					String str;
					_id = fpIn.readInt();
					_style = fpIn.readInt();
					_fore = fpIn.readInt();
					_back = fpIn.readInt();
					_type =(int)fpIn.readByte();
					_x = 0xFF &(int)fpIn.readByte();
					_y = 0xFF &(int)fpIn.readByte();
					_wid = 0xFF &(int)fpIn.readByte();
					_hgt = 0xFF &(int)fpIn.readByte();
					//System.out.println("_type= "+_type);
					switch(_type)
					{
						case 0 :
							str = fpIn.readUTF();
							//System.out.println("str0="+str);
							new win(this, _id, _x, _y, _wid, _hgt, _style, _fore, _back, buttonHighColor, str);
							break;
						case 1 :
							str=fpIn.readUTF();
							//System.out.println("str1="+str);
						    new win(this, _id, _x, _y, _wid, _hgt, _style, _fore, _back, str);
							break;
						case 2 :
						{
							new win(this, _id, _x, _y, _wid, _hgt, _style, Basketball.getImage(fpIn.readUTF()), _back);
							break;
						}
					}
					if(prog)
						Basketball.myCanvas.incrementProgress();
				}
				fpIn.close();
			}
			catch(java.io.IOException e)
			{
				x = y = wid = hgt = style = 0;
				return;
			}
		}
		else
		{
			x = y = wid = hgt = style = 0;
		}
		if(prog)
			Basketball.myCanvas.progress = 0;
		return;
	}
	private int gWordWrapText(bhFont font, String text, int results[], int MaxWid,
	int MaxRows, boolean isEdit)
	{
		int orgIndex = 0;
		int curIndex = 0;
		int lastBreak = -1;
		int TildeCnt = 0;
		int iRows = 0;
		int CurWid = 0;
		int LastBreakWid = 0;
		int LastTildeCnt = 0;
		int CRLF;
		int Wid;
		Wid = 0;
		while(curIndex < text.length())
		{
			char chr = text.charAt(curIndex);
			int NewWid = CurWid + font.getCharWidth(chr);
			if(('\r' == chr)||('\n' == chr)||(NewWid > MaxWid))
			{
				if(('\r' != chr)&&('\n' != chr)&&
					(' ' != chr || isEdit))
				{
					if(lastBreak >= 0)
					{
						curIndex = lastBreak;
						CurWid = LastBreakWid;
						TildeCnt = LastTildeCnt;
					}
				}
				if(null != results)
				{
					results[2 * iRows]= orgIndex;
					results[2 * iRows + 1]= curIndex;
				}
				if(CurWid > Wid)
					Wid = CurWid;
				final int CR_FLAG = 1;
				final int LF_FLAG = 2;
				CRLF = 0;
				int start = chr;
				do
				{
					chr = text.charAt(curIndex);
					if('\r' == chr)
					{
						if(0 !=(CR_FLAG & CRLF))
							break;
						CRLF |= CR_FLAG;
					}
					else if('\n' == chr)
					{
						if(0 !=(LF_FLAG & CRLF))
							break;
						CRLF |= LF_FLAG;
					}
					else if(' ' != chr || isEdit || start != chr)
						break;
					curIndex++;
				} while(curIndex < text.length());
				iRows++;
				if(iRows == MaxRows)
					return iRows;
				orgIndex = curIndex;
				lastBreak = -1;
				LastBreakWid = CurWid = 0;
				LastTildeCnt = TildeCnt = 0;
			}
			else
			{
				if('~' == chr)
					TildeCnt++;
				else
				{
					CurWid = NewWid;
					if(' ' == chr)
					{
						lastBreak = curIndex + 1;
						LastBreakWid = CurWid;
						LastTildeCnt = TildeCnt;
					}
				}
				curIndex++;
			}
		}
		if(curIndex != orgIndex)
		{
			if(null != results)
			{
				results[2 * iRows]= orgIndex;
				results[2 * iRows + 1]= curIndex;
			}
			if(CurWid > Wid)
				Wid = CurWid;
			iRows++;
		}
		if(null != results)
		{
			results[2 * iRows]= Wid;
			results[2 * iRows + 1]= 0;
		}
		return iRows;
	}
	public static void drawBorderNotchRect(Graphics g, int x, int y, int w, int h, int color, int bcolor)
	{
		g.setClip(x, y, w, h);
		g.setColor(color);
		g.fillRect(x + 1, y + 1, w - 2, h - 2);
		g.setColor(bcolor);
		g.fillRect(x, y + 2, 1, h - 4);
		g.fillRect(x + w - 1, y + 2, 1, h - 4);
		g.fillRect(x + 2, y, w - 4, 1);
		g.fillRect(x + 2, y + h - 1, w - 4, 1);
		g.fillRect(x + 1, y + 1, 1, 1);
		g.fillRect(x + w - 2, y + 1, 1, 1);
		g.fillRect(x + 1, y + h - 2, 1, 1);
		g.fillRect(x + w - 2, y + h - 2, 1, 1);
		return;
	}
	private static RecordStore m_rs;
	private static int m_iStorePos;
	private static int m_iRecordPos;
	private static int m_iSize;
	public static boolean BufferOpen(String sRecordStore, boolean bCreate)
	{
		try
		{
			m_rs = RecordStore.openRecordStore(sRecordStore, bCreate);
			m_iSize = m_rs.getSize();
		}
		catch(RecordStoreException e1)
		{
			doAlert("1: " + e1.getMessage());
			return false;
		}
		m_iStorePos = 1;
		m_iRecordPos = 0;
		return true;
	}
	public static void doAlert(String msg)
	{
	}
	public static void BufferClose()
	{
		try
		{
			if(m_rs != null)
				m_rs.closeRecordStore();
			m_rs = null;
		}
		catch(Exception e)
		{
			doAlert("2: " + e.getMessage());
		}
	}
	public static void BufferSeek(int iOrigin, int iOffset)
	{
		int iNumRecords;
		int iLastRecordSize;
		try
		{
			iNumRecords = m_rs.getNumRecords();
			iLastRecordSize = m_rs.getRecordSize(iNumRecords);
		}
		catch(Exception e)
		{
			doAlert("3: " + e.getMessage());
			try
			{
				byte pDataBlock[]= new byte[5000];
				m_rs.addRecord(pDataBlock, 0, 5000);
				iNumRecords = m_rs.getNumRecords();
				iLastRecordSize = m_rs.getRecordSize(iNumRecords);
				m_iSize = m_rs.getSize();
			}
			catch(Exception e1)
			{
				doAlert("4: " + e1.getMessage());
				return;
			}
		}
		int iRemainingRecordSize = 5000 - m_iRecordPos;
		switch(iOrigin)
		{
			case 0 :
				m_iStorePos = 1 +(iOffset / 5000);
				m_iRecordPos = iOffset % 5000;
				break;
			case 2 :
				if(iOffset > iLastRecordSize)
				{
					m_iStorePos =(iNumRecords - 1)-((iOffset - iLastRecordSize)/ 5000);
					m_iRecordPos = 5000 -((iOffset - iLastRecordSize)% 5000)- 1;
				}
				else
				{
					m_iStorePos = iNumRecords;
					m_iRecordPos = iLastRecordSize - iOffset;
				}
				break;
			case 1 :
				if(iOffset > iRemainingRecordSize)
				{
					m_iStorePos +=(iOffset - iRemainingRecordSize)/ 5000;
					m_iRecordPos +=(iOffset - iRemainingRecordSize)% 5000;
				}
				else
				{
					m_iRecordPos += iOffset;
				}
				break;
			default :
				break;
		}
		if(((m_iStorePos - 1)* 5000)+ m_iRecordPos > m_iSize)
		{
			m_iStorePos = iNumRecords;
			m_iRecordPos = iLastRecordSize;
		}
	}
	public static int BufferWrite(byte pData[], int iSize)
	{
		byte pDataBlock[]= new byte[5000];
		int iBytesWritten = 0;
		int iBytesLeft = iSize;
		int iNumRecords;
		try
		{
			iNumRecords = m_rs.getNumRecords();
		}
		catch(Exception e)
		{
			doAlert("5: " + e.getMessage());
			return 0;
		}
		int i;
		while(iBytesLeft > 0)
		{
			if(m_iStorePos > iNumRecords)
			{
				for(i = 0; i < 5000 && i < iBytesLeft; i++)
				{
					pDataBlock[i]= pData[iBytesWritten + i];
				}
				try
				{
					m_rs.addRecord(pDataBlock, 0, i);
					iNumRecords++;
				}
				catch(Exception e)
				{
				}
			}
			else
			{
				try
				{
					m_rs.getRecord(m_iStorePos, pDataBlock, 0);
				}
				catch(Exception e)
				{
					doAlert("6: " + e.getMessage());
				}
				for(i = 0; m_iRecordPos + i < 5000 && i < iBytesLeft; i++)
				{
					pDataBlock[m_iRecordPos + i]= pData[iBytesWritten + i];
				}
				try
				{
					m_rs.setRecord(m_iStorePos, pDataBlock, 0, 5000);
					m_iRecordPos += i;
				}
				catch(Exception e)
				{
					doAlert("7: " + e.getMessage());
				}
			}
			if(i == 5000)
			{
				m_iStorePos++;
				m_iRecordPos = 0;
			}
			iBytesWritten += i;
			iBytesLeft -= i;
		}
		try
		{
			m_iSize = m_rs.getSize();
		}
		catch(Exception e)
		{
			doAlert("8: " + e.getMessage());
		}
		return iBytesWritten;
	}
	public static int BufferRead(byte pData[], int iSize)
	{
		int iBytesWritten = 0;
		int iBytesLeft = iSize;
		byte pDataBlock[]= new byte[5000];
		int iNumRecords;
		try
		{
			iNumRecords = m_rs.getNumRecords();
		}
		catch(Exception e)
		{
			doAlert("9: " + e.getMessage());
			return 0;
		}
		while(iBytesLeft > 0)
		{
			if(m_iStorePos > iNumRecords)
			{
				BufferSeek(2, 0);
				return iBytesWritten;
			}
			try
			{
				m_rs.getRecord(m_iStorePos, pDataBlock, 0);
			}
			catch(Exception e)
			{
				doAlert("10: " + e.getMessage());
			}
			int i;
			for(i = 0; i + m_iRecordPos < 5000 && i < iBytesLeft; i++)
			{
				pData[iBytesWritten + i]= pDataBlock[m_iRecordPos + i];
			}
			if((i + m_iRecordPos)== 5000)
			{
				iBytesWritten += 5000 - m_iRecordPos;
				iBytesLeft -= i;
				m_iStorePos++;
				m_iRecordPos = 0;
			}
			else
			{
				iBytesWritten += i;
				m_iRecordPos += i;
				iBytesLeft -= iBytesWritten;
			}
		}
		return iBytesWritten;
	}
}

⌨️ 快捷键说明

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