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

📄 window.java

📁 国外人写的操作感挺好的一款滑雪游戏.结构也比较清楚
💻 JAVA
字号:
// Copyright (c) 2004 Venan Entertainment, Inc. All rights reserved.
//
// Venan Entertainment, Inc.,  Middletown, Connecticut 06457
// http://www.venan.com
//

import javax.microedition.lcdui.Graphics;
import java.io.*;

public class Window extends Drawable
{
	public final static int CONTAINER_NORMAL = 0;
	public final static int CONTAINER_STACK = 1;
	public final static int CONTAINER_SHELF = 2;
	
	public final static int PAINT_FILL = 1;
	public final static int PAINT_FRAME = 2;
	public final static int PAINT_SHADOW = 4;

	protected final TorinoCanvas	m_canvas;
	
	private Drawable		m_listHead;
	private Drawable		m_listTail;
	int				m_iContainerType = CONTAINER_NORMAL;
	int				m_iPadding = 0;			// used for stacks and shelves
	int				m_iPaintFlags = 0;
	int				m_iFillColor = 0;
	int				m_iFrameColor = 0;
	int				m_iShadowColor = 0;

	public Window( TorinoCanvas canvas )
	{
		m_canvas = canvas;
	}

	public void setPadding( int iPadding )
	{
		if (m_iPadding != iPadding)
		{
			m_iPadding = iPadding;
			adjustSpacing();
		}		
	}
	
	public void addToFront( Drawable drawable )
	{
		if (drawable == null)
			return;
	
		drawable.m_next = m_listHead;
		drawable.m_prev = null;
	
		if( m_listHead != null )
			m_listHead.m_prev = drawable;
		m_listHead = drawable;
	
		if( m_listTail == null )
			m_listTail = drawable;
	
		drawable.setParent(this);
		
		adjustSpacing();
	}
	
	public void addToBack( Drawable drawable )
	{
		if (drawable == null)
			return;
	
		drawable.m_prev = m_listTail;
		drawable.m_next = null;
	
		if( m_listTail != null )
			m_listTail.m_next = drawable;
		m_listTail = drawable;
	
		if( m_listHead == null )
			m_listHead = drawable;
	
		drawable.setParent(this);
		
		adjustSpacing();
	}
	
	public void remove( Drawable drawable )
	{
		if (drawable == null)
			return;
	
		if( m_listHead == drawable )
			m_listHead = drawable.m_next;
	
		if( m_listTail == drawable )
			m_listTail = drawable.m_prev;
	
		if( drawable.m_prev != null )
			drawable.m_prev.m_next = drawable.m_next;
	
		if( drawable.m_next != null )
			drawable.m_next.m_prev = drawable.m_prev;
	
		drawable.setParent(null);
		
		adjustSpacing();
	}
	
	public void removeAll()
	{
		while (m_listHead != null)
		{
			Drawable d = m_listHead;
			m_listHead = d.m_next;
			d.m_prev = null;
			d.m_next = null;
		}
		m_listTail = null;
	}
	
	public void setDimensions( int iWidth, int iHeight )
	{
		m_iWidth = iWidth;
		m_iHeight = iHeight;
		for( Drawable d = m_listHead; d != null; d = d.m_next )
		{
			d.calculateAlignment();
		}

		adjustSpacing();
	}
	
	public void adjustSpacing()
	{
		int iCurrent;
		switch (m_iContainerType)
		{
		case CONTAINER_SHELF:
			iCurrent = 0;
			if (( m_iPaintFlags & PAINT_FRAME ) != 0 )
			{
				iCurrent++;
			}		
			for( Drawable d = m_listHead; d != null; d = d.m_next )
			{
				d.setPosition( iCurrent, d.m_iY );
				iCurrent += d.m_iWidth + m_iPadding;
			}
			break;
		case CONTAINER_STACK:
			iCurrent = 0;
			if (( m_iPaintFlags & PAINT_FRAME ) != 0 )
			{
				iCurrent++;
			}		
			for( Drawable d = m_listHead; d != null; d = d.m_next )
			{
				d.setPosition( d.m_iX, iCurrent );
				iCurrent += d.m_iHeight + m_iPadding;
			}
			break;
		}
	}
	
	public void sizeToChildren()
	{
		// Get the new upper left hand offset
		int iMinX = 5000, iMinY = 5000;
		for( Drawable d = m_listHead; d != null; d = d.m_next )
		{
			if (iMinX > d.m_iX)
				iMinX = d.m_iX;
			if (iMinY > d.m_iY)
				iMinY = d.m_iY;
		}

		if (( m_iPaintFlags & PAINT_FRAME ) != 0 )
		{
			iMinX--;
			iMinY--;
		}		
		// Move all the children
		if( iMinX != 0 || iMinY != 0 )
		{
			for( Drawable d = m_listHead; d != null; d = d.m_next )
			{
				d.m_iX -= iMinX;
				d.m_iY -= iMinY;
			}
		}

		// Get the new width and height
		int iWidth = 0;
		int iHeight = 0;
		for( Drawable d = m_listHead; d != null; d = d.m_next )
		{
			iWidth = Math.max( iWidth, d.m_iX + d.m_iWidth );
			iHeight = Math.max( iHeight, d.m_iY + d.m_iHeight );
		}
		if (( m_iPaintFlags & PAINT_FRAME ) != 0 )
		{
			iWidth++;
			iHeight++;
		}		
		if (( m_iPaintFlags & PAINT_SHADOW ) != 0 )
		{
			iWidth++;
			iHeight++;
		}

		setDimensions( iWidth, iHeight );
		calculateAlignment();
	}

	public void paint( Graphics g )
	{
		// fill if necessary
		if (( m_iPaintFlags & PAINT_FILL ) != 0 )
		{
			g.setColor( m_iFillColor );
			if (( m_iPaintFlags & PAINT_SHADOW ) != 0 )
				g.fillRect( m_iX, m_iY, m_iWidth-1, m_iHeight-1 );
			else
				g.fillRect( m_iX, m_iY, m_iWidth, m_iHeight );
		}		
		// draw frame if necessary
		if (( m_iPaintFlags & PAINT_FRAME ) != 0 )
		{
			g.setColor( m_iFrameColor );
			if (( m_iPaintFlags & PAINT_SHADOW ) != 0 )
				g.drawRect( m_iX, m_iY, m_iWidth-2, m_iHeight-2 );
			else
				g.drawRect( m_iX, m_iY, m_iWidth-1, m_iHeight-1 );
		}
		//draw shadow
		if (( m_iPaintFlags & PAINT_SHADOW ) != 0 )
		{
			g.setColor( m_iShadowColor );
			g.drawLine( m_iX+1, m_iY+m_iHeight-1, m_iX+m_iWidth-1, m_iY+m_iHeight-1 );
			g.drawLine( m_iX+m_iWidth-1, m_iY+1, m_iX+m_iWidth-1, m_iY+m_iHeight-1 );
		}
		paintChildren( g );
	}

	public void paintChildren( Graphics g )
	{
		//g.translate( m_iX, m_iY );

		for( Drawable d = m_listTail; d != null; d = d.m_prev )
		{
			if ( d.m_bVisible )
				d.translatePaint( g, m_iX, m_iY );
		}

		//g.translate( -m_iX, -m_iY );
	}

	public void onIdle() throws IOException
	{
	}

	public void keyPressed( int iKeyCode, int iGameAction ) throws IOException
	{
	}

	public void keyReleased( int iKeyCode, int iGameAction ) throws IOException
	{
	}

	public void unloadResources()
	{
	}	
}

⌨️ 快捷键说明

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