java小游戏-贪吃蛇__教程 |
|
日期:2007-5-20 1:28:10 人气:294 [大 中 小] |
|
|
|
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 ) |
|
出处:本站原创 作者:佚名 |
|
|