java小游戏-贪吃蛇__教程 |
|
日期:2007-5-20 1:28:10 人气:294 [大 中 小] |
|
|
|
{ this.owner = (JFrame) owner; this.setSize( 400, 200 ); this.setResizable( false ); this.setTitle( "Config Your Game" ); this.c = this.getContentPane(); this.c.setBackground( Color.WHITE ); this.c.setLayout( new FlowLayout() ); this.box1 = Box.createVerticalBox(); for( int i = 0; i < panel.length; i++ ) { panel[i] = new OwnPanel(); panel[i].addActionListener( new ActionHandler() ); this.box1.add( panel[i] ); this.box1.add( Box.createVerticalStrut( 4 ) ); } this.panel[0].setText( " Background" ); this.panel[1].setText( " Snake" ); this.panel[2].setText( " Bean" ); this.panel[3].setText( " EatedBean" ); this.panel[0].setBack( ColorGroup.COLOR_BACK ); this.panel[1].setBack( ColorGroup.COLOR_SNAKE ); this.panel[2].setBack( ColorGroup.COLOR_BEAN ); this.panel[3].setBack( ColorGroup.COLOR_EATEDBEAN ); this.box2 = Box.createHorizontalBox(); this.commitButton = new JButton( "确定" ); this.commitButton.setFont( Font.getFont( "Fixedsys" ) ); this.commitButton.addActionListener( new ActionHandler() ); this.cancelButton = new JButton( "取消" ); this.cancelButton.setFont( Font.getFont( "Fixedsys" ) ); this.cancelButton.addActionListener( new ActionHandler() ); this.box2.add( this.commitButton ); this.box2.add( Box.createHorizontalStrut( 20 ) ); this.box2.add( this.cancelButton ); this.box1.add( this.box2 ); this.c.add( this.box1, BorderLayout.NORTH ); this.setLocation( ( this.getToolkit().getScreenSize().width - this.getWidth() )/2, ( this.getToolkit().getScreenSize().height - this.getHeight() )/2 ); this.setVisible( true ); } public void setOwnerColor( Color temp ) { this.owner.getContentPane().setBackground( temp ); } private class ActionHandler implements ActionListener { public void actionPerformed( ActionEvent e ) { for( int i = 0; i < color.length; i++ ) { if( e.getSource() == panel[i].reButton() ) { color[i] = JColorChooser.showDialog( ConfigDialog.this, "Choose BackGround Color", Color.WHITE ); if( color[i] != null ) { panel[i].setBack( color[i] ); } } } if( e.getSource() == commitButton ) { color[0] = (color[0]==null?ColorGroup.COLOR_BACK:color[0]); color[1] = (color[1]==null?ColorGroup.COLOR_SNAKE:color[1]); color[2] = (color[2]==null?ColorGroup.COLOR_BEAN:color[2]); color[3] = (color[3]==null?ColorGroup.COLOR_EATEDBEAN:color[3]); ConfigDialog.this.setVisible( false ); ColorGroup.setCOLOR_BACK( color[0] ); owner.getContentPane().setBackground( color[0] ); ColorGroup.setCOLOR_SNAKE( color[1] ); ColorGroup.setCOLOR_BEAN( color[2] ); ColorGroup.setCOLOR_EATEDBEAN( color[3] ); ConfigDialog.this.dispose(); } else if( e.getSource() == cancelButton ) { ConfigDialog.this.setVisible( false ); ConfigDialog.this.dispose(); }
} |
|
出处:本站原创 作者:佚名 |
|
|