📄 cstartui.java
字号:
package chiidanceapp;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Image;
import javax.swing.JPanel;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.Color;
import java.awt.Font;
import java.util.GregorianCalendar;
import java.util.Calendar;
import java.util.ResourceBundle;
public class CStartUI implements Runnable{
///////////////////////////////////////////////////////////////////////////
static ResourceBundle res = ResourceBundle.getBundle("chiidanceapp.Res1");
private Dimension D;
private int Imagewidth;
private int Imageheight;
private int MenuIndex;
private int Score;
private int xPalm = 285;
private int yPalm = 360;
private int xRecordPanel = 801;
private int xSpeed;
private int Interval = 500;
private int xLogo = 250;
private int yLogo = 360;
private String MenuItem[] = {
"START GAME",
"EXIT",
"RECORD"
};
private boolean isPaint = true;
private boolean isMenuVisible = false;
private boolean isPalmFront = true;
private boolean isLoaded = false;
private boolean canRun = false;
private Image OpeningImage;
private Image ShowPressEnter;
private Image SelectPanel;
private Image Palm;
private Image Logo;
private Image RecordPanel;
private Image Chii;
Thread aThread;
CMidiThread MidiThread;
CLoad Load;
///////////////////////////////////////////////////////////////////////////
public CStartUI() {
MidiThread = new CMidiThread( 1,true );
Load();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Imagewidth = ShowPressEnter.getWidth( null );
Imageheight = ShowPressEnter.getHeight( null );
Load = new CLoad();
this.Score = Load.loadScore();
aThread = new Thread( this );
canRun = true;
aThread.start();
}
////////////////////////////////////////////////////////////////////////////
public void Load()
{
CImage initImage = new CImage();
OpeningImage = initImage.LoadImage( "Resource/img/g8.jpg" );
ShowPressEnter = initImage.LoadImage( "Resource/img/pressenter.png" );
SelectPanel = initImage.LoadImage( "Resource/images/diologframe.png" );
Palm = initImage.LoadImage( "Resource/img/arrow.png" );
Logo = initImage.LoadImage( "Resource/img/logo.png" );
RecordPanel = initImage.LoadImage( "Resource/img/RecordPanel.png" );
Chii = initImage.LoadImage( "Resource/images/chii[1].gif" );
isLoaded = true;
}
public void destruct()
{
OpeningImage = null;
ShowPressEnter = null;
SelectPanel = null;
Palm = null;
Logo = null;
RecordPanel = null;
Chii = null;
canRun = false;
isLoaded = false;
MidiThread.MidiPlayer.close();
System.gc();
}
public void restartThread()
{
this.canRun = true;
aThread = new Thread( this );
aThread.start();
}
public void addMenuIndex()
{
if( MenuIndex < 2 )
MenuIndex++;
}
public void setScore( int Score )
{
this.Score = Score;
}
public void subMenuIndex()
{
if( MenuIndex > 0 )
MenuIndex --;
}
public void dragLogo( int xMouse,int yMouse )
{
this.xLogo = xMouse - 150;
this.yLogo = yMouse - 50;
}
public int getMenuIndex()
{
return MenuIndex;
}
public boolean isMenuVisible()
{
return this.isMenuVisible;
}
public boolean isLoaded()
{
return isLoaded;
}
public void setMenuVisible( boolean isMenuVisible )
{
this.isMenuVisible = isMenuVisible;
}
///////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////
public void paint( Graphics g,JPanel GamePanel )
{
if( isLoaded )
{
g.drawImage( OpeningImage,0,0,GamePanel );
}
if( g instanceof Graphics2D )
{
Graphics2D g2 = ( Graphics2D )g;
g2.setRenderingHint(
RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON );
}
if( !isMenuVisible )
{
if ( isPaint )
{
g.drawImage(ShowPressEnter, 250, 500, GamePanel);
}
g.drawImage( Logo, xLogo, yLogo, GamePanel );
}
else if( isMenuVisible )
{
g.drawImage( SelectPanel,300,350,200,100,GamePanel );
g.setFont( new Font( "Monospaced",Font.BOLD,25 ) );
g.drawString( MenuItem[ 0 ],325,380 );
g.drawString( MenuItem[ 1 ],370,410 );
g.drawString( MenuItem[ 2 ],355,440 );
if( MenuIndex == 0)
{
g.setColor( Color.magenta );
g.drawString( MenuItem[ 0 ],325,380 );
g.drawImage( Palm,xPalm,yPalm,GamePanel );
xRecordPanel = 801;
}
else if( MenuIndex == 1 )
{
g.setColor( Color.magenta );
g.drawString( MenuItem[ 1 ],370,410 );
g.drawImage( Palm,xPalm,yPalm+30,GamePanel );
xRecordPanel = 801;
}
else if( MenuIndex == 2 )
{
g.setColor( Color.magenta );
g.drawString( MenuItem[ 2 ],355,440 );
g.drawImage( Palm,xPalm,yPalm+60,GamePanel );
g.drawImage( RecordPanel,xRecordPanel,100,GamePanel );
g.setColor( Color.black );
if( xRecordPanel == 240 )
{
g.drawString( "Chii:",310,140 );
g.setFont( new Font( "Monospaced",Font.PLAIN,17 ) );
GregorianCalendar now = new GregorianCalendar();
int Hour = now.get(Calendar.HOUR_OF_DAY);
if( Hour >= 5 && Hour < 12 )
{
g.drawString( "早上好",310,160 );
}
else if( Hour >= 12 && Hour < 13 )
{
g.drawString( "中午好",310,160 );
}
else if( Hour >= 13 && Hour < 18 )
{
g.drawString( "下午好",310,160 );
}else if( Hour >= 18 && Hour < 23 )
{
g.drawString( "晚上好",310,160 );
}else if( Hour >= 0 && Hour < 5 )
{
g.drawString( "现在是凌晨,请早点休息。",310,160 );
}
else
{
g.drawString( "晚上好",310,160 );
}
g.drawImage( Chii,250,110 ,GamePanel );
g.setFont( new Font( "Monospaced",Font.PLAIN,20 ) );
g.drawString( "目前最高分:",250,190 );
g.setColor( Color.black );
g.setFont( new Font( "Monospaced",Font.BOLD,20 ) );
g.drawString( ""+Score+"分",350,220 );
}
}
}
g.setColor( Color.gray );
g.setFont( new Font( "Monospaced",Font.PLAIN,17 ) );
g.drawString( "http://truecolor.gameres.com",500,590 );
g.dispose();
}
////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
public void run() {
while ( canRun ) {
if ( isPaint )
{
isPaint = false;
}
else if ( !isPaint ) {
isPaint = true;
}
if( isMenuVisible && isPalmFront )
{
isPalmFront = false;
xPalm += 5;
}
else if( isMenuVisible && !isPalmFront )
{
isPalmFront = true;
xPalm -= 5;
}
if( xRecordPanel > 240 && MenuIndex == 2 )
{
Interval = 10;
xRecordPanel -= ( ++xSpeed );
if( xSpeed > 60 )
xSpeed = 60;
}
if( xRecordPanel <= 240 )
{
xRecordPanel = 240;
Interval = 500;
}
if( MenuIndex == 0 || MenuIndex == 1 )
{
Interval = 500;
}
try {
aThread.sleep( Interval );
}
catch ( Exception ex ) {}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -