📄 optionswindow.java
字号:
/* * JCollapse - Java Collapse Game * Copyright (C) 2005 Erico Gon鏰lves Rimoli * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */package sourceforge.net.projects.jcollapse.game;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Dimension;import java.awt.FlowLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import javax.swing.JCheckBox;import javax.swing.JFrame;import javax.swing.JOptionPane;import sourceforge.net.projects.jcollapse.game.components.JCButton;import sourceforge.net.projects.jcollapse.game.components.JCPanel;import sourceforge.net.projects.jcollapse.game.components.SoundControl;public class OptionsWindow extends JFrame { private SoundControl m_SoundControl; private JCButton m_ButtonOk; private JCButton m_ButtonCancel; private JCheckBox m_JCheckBox; private JCPanel m_JCPanelSouth; private JCPanel m_JCPanelCenter; public OptionsWindow( SoundControl soundControl ) { m_SoundControl = soundControl; initializeComponents(); loadOptions(); } public void setVisible( boolean visible ) { if( isVisible() != visible && visible ) loadOptions(); super.setVisible( visible ); } private void initializeComponents() { //ButtonOk //---------------------------------------------------------------------------------------------------------------------------------------------------------------------- m_ButtonOk = new JCButton( "Ok" ); m_ButtonOk.setPreferredSize( new Dimension( 45, 20 ) ); m_ButtonOk.setMnemonic( 'O' ); m_ButtonOk.addActionListener( new ActionListener() { public void actionPerformed( ActionEvent e ) { exitOptions(); if( m_JCheckBox.isSelected() ) if( m_SoundControl.isAllReady() ) m_SoundControl.setEnabled( true ); else if( m_SoundControl.initialize() ) m_SoundControl.setEnabled( true ); else JOptionPane.showMessageDialog( OptionsWindow.this, "Error initializing sound engine!", "Error", JOptionPane.ERROR_MESSAGE ); else m_SoundControl.setEnabled( false ); } }); //ButtonCancel //---------------------------------------------------------------------------------------------------------------------------------------------------------------------- m_ButtonCancel = new JCButton( "Cancel" ); m_ButtonCancel.setPreferredSize( new Dimension( 45, 20 ) ); m_ButtonCancel.setMnemonic( 'C' ); m_ButtonCancel.addActionListener( new ActionListener() { public void actionPerformed( ActionEvent e ) { exitOptions(); } }); //CheckBoxEnableSound //---------------------------------------------------------------------------------------------------------------------------------------------------------------------- m_JCheckBox = new JCheckBox( "Enable Sound" ); m_JCheckBox.setOpaque( false ); m_JCheckBox.setForeground( Color.BLACK ); //JPanelCenter //---------------------------------------------------------------------------------------------------------------------------------------------------------------------- m_JCPanelCenter = new JCPanel( ); m_JCPanelCenter.setPreferredSize( new Dimension( 315, 100 ) ); m_JCPanelCenter.add( m_JCheckBox ); //JPanelSouth //---------------------------------------------------------------------------------------------------------------------------------------------------------------------- m_JCPanelSouth = new JCPanel( new FlowLayout( FlowLayout.RIGHT ) ); m_JCPanelSouth.add( m_ButtonOk ); m_JCPanelSouth.add( m_ButtonCancel ); //this //---------------------------------------------------------------------------------------------------------------------------------------------------------------------- addWindowListener( new WindowAdapter() { public void windowClosing( WindowEvent e ) { exitOptions(); } }); setResizable( false ); setTitle( "Options" ); setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE ); getContentPane().add( m_JCPanelCenter, BorderLayout.CENTER ); getContentPane().add( m_JCPanelSouth, BorderLayout.SOUTH ); pack(); setLocationRelativeTo( null ); } private void loadOptions() { m_JCheckBox.setSelected( m_SoundControl.isEnabled() ); } private void exitOptions() { dispose(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -