speeditem = new jradiobuttonmenuitem[speeditem_name.length];
for( int i = 0; i < speeditem_name.length; i++ )
{
speeditem[i] = new jradiobuttonmenuitem( speeditem_name[i] );
inner_menu[0].add( speeditem[i] );
speeditem[i].setfont( new font( "courier", font.plain, 12 ) );
speeditem[i].additemlistener( new itemhandler() );
temp1.add( speeditem[i] );
}
buttongroup temp2 = new buttongroup();
string[] modelitem_name = { "linux", "mac", "windows" };
modelitem = new jradiobuttonmenuitem[modelitem_name.length];
for( int i = 0; i < modelitem_name.length; i++ )
{
modelitem[i] = new jradiobuttonmenuitem( modelitem_name[i] );
inner_menu[1].add( modelitem[i] );
modelitem[i].setfont( new font( "courier", font.plain, 12 ) );
modelitem[i].additemlistener( new itemhandler() );
temp2.add( modelitem[i] );
}
buttongroup temp3 = new buttongroup();
string[] standarditem_name = { "60 * 40", "45 * 30", "30 * 20" };
standarditem = new jradiobuttonmenuitem[standarditem_name.length];
for( int i = 0; i < standarditem_name.length; i++ )
{
standarditem[i] = new jradiobuttonmenuitem( standarditem_name[i] );
inner_menu[2].add( standarditem[i] );
standarditem[i].setfont( new font( "courier", font.plain, 12 ) );
standarditem[i].additemlistener( new itemhandler() );
temp3.add( standarditem[i] );
}
looks = uimanager.getinstalledlookandfeels();
}
private class actionhandler implements actionlistener
{
public void actionperformed( actionevent e )
{
if( e.getsource() == menuitem[0] )
{
owner.resetgame();
configmenu.this.setvisible( false );
}
else if( e.getsource() == menuitem[1] )
{
owner.stopgame();
configmenu.this.setvisible( true );
configmenu.this.setmenuenable( true );
}
else if( e.getsource() == menuitem[2] )
{
system.exit( 0 );
}
else if( e.getsource() == menuitem[3] )
{
configdialog temp = new configdialog( owner );
temp.setvisible( true );
}
else if( e.getsource() == menuitem[4] )
{
joptionpane.showmessagedialog( null, "sanke game 2.0 version!\n\n" +
"author: finalcore\n\n" );
}
}
}
private class itemhandler implements itemlistener
{
public void itemstatechanged( itemevent e )
{
for( int i = 0; i < speeditem.length; i++ )
{
if( e.getsource() == speeditem[i] )
{
owner.snaketimer.setdelay( 150 - 30 * i );
}
}
if( e.getsource() == standarditem[0] )
{
owner.setgrid( 60, 40, 5 );
}
else if( e.getsource() == standarditem[1] )
{
owner.setgrid( 45, 30, 10 );
}
else if( e.getsource() == standarditem[2] )
{
owner.setgrid( 30, 20, 15 );
}
for( int i = 0; i < modelitem.length; i++ )
{
if( e.getsource() == modelitem[i] )
{
try
{
uimanager.setlookandfeel( looks[i].getclassname() );
}catch(exception ex){}
}
}
}
}
public void setmenuenable( boolean temp )
{
menu[1].setenabled( temp );
}
}
configdialog.java
package snakegame;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class configdialog extends jdialog
{
private container c;
private jframe owner;
private ownpanel[] panel = new ownpanel[4];
box box1, box2;
private jbutton commitbutton, cancelbutton;
color[] color = new color[4];
public configdialog( frame owner )
{
this.owner = (jframe) owner;
this.setsize( 400, 200 );
this.setresizable( false );
this.settitle( "config your game"