⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 renderselection.java

📁 Java 3D Game SDK.老外做的.
💻 JAVA
字号:
/*
 * RenderSelection.java
 */

package org.java3dgamesdk.core.util;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;

import org.java3dgamesdk.core.*;

/**
 * This class supplies a simple dialog for choosing the render mode.
 * It also gathers all possible render configurations for the given hardware.
 *
 * @author  Norbert Nopper
 */
public class RenderSelection extends JDialog {

    /**
     * Panel for grouping the items.
     */
    private JPanel                          renderingPanel;

    /**
     * Group for the radio buttons.
     */    
    private ButtonGroup                     buttonGroup;

    /**
     * Radio button for window mode.
     */        
    private JRadioButton                    windowModeButton;

    /**
     * Radio button for fullscreen mode.
     */        
    private JRadioButton                    fullScreenModeButton;

    /**
     * Drop down list with all rendering modes.
     */        
    private JComboBox                       displayModeList;

    /**
     * Ok button.
     */        
    private JButton                         okButton;

    /**
     * Cancel button.
     */        
    private JButton                         cancelButton;

    /**
     * Array with all possible rendering modes.
     */        
    private DisplayMode                     displayModes[];
    
    /**
     * Reference to the game frame to automatically start up the frame.
     */        
    private GameFrame                       gameFrame;
    
    /**
     * Constructor for creating the dialog.
     *
     * @param gameFrame a reference to the game frame
     */        
    public RenderSelection(GameFrame gameFrame) {
        // create the dialog
        super(new JFrame(), "Select rendering mode", true);
        
        // save the reference
        this.gameFrame = gameFrame;
        
        // init the componenets
        initComponents();
        
        // gather all rendering modes
        gatherDisplayModes();
    }

    /**
     * Method for initializing and arranging all items on the screen.
     */
    private void initComponents() {
        renderingPanel = new JPanel();
        buttonGroup = new ButtonGroup();
        windowModeButton = new JRadioButton();
        fullScreenModeButton = new JRadioButton();
        displayModeList = new JComboBox();
        okButton = new JButton();
        cancelButton = new JButton();

        // listen to window event to recognize when it is closed
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent event) {
                closeDialog(event);
            }
        });
                
        // absolute layout ...
        getContentPane().setLayout(null);

        // ... everywhere
        renderingPanel.setLayout(null);
        renderingPanel.setBorder(new TitledBorder("Rendering mode"));
                
        buttonGroup.add(windowModeButton);
        buttonGroup.add(fullScreenModeButton);
                
        windowModeButton.setSelected(true);
        windowModeButton.setText("Use desktop window");
        renderingPanel.add(windowModeButton);
        windowModeButton.setBounds(10, 20, 150, 20);
        
        fullScreenModeButton.setText("Fullscreen mode:");
        renderingPanel.add(fullScreenModeButton);
        fullScreenModeButton.setBounds(10, 50, 130, 20);
                        
        renderingPanel.add(displayModeList);
        displayModeList.setBounds(150, 50, 180, 20);        

        okButton.setText("OK");
        okButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                okButtonActionPerformed(event);
            }
        });        
        getContentPane().add(okButton);
        okButton.setBounds(350, 20, 80, 20);
        
        cancelButton.setText("Cancel");
        cancelButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                cancelButtonActionPerformed(event);
            }
        });        
        getContentPane().add(cancelButton);
        cancelButton.setBounds(350, 60, 80, 20);
                
        getContentPane().add(renderingPanel);
        renderingPanel.setBounds(0, 10, 340, 80);        
        
        setSize(440, 120);
        
        setResizable(false);
    }
    
    /**
     * This methods gathers all display modes of the graphic card.
     */
    private void gatherDisplayModes() {
        displayModes = gameFrame.getGraphicsDevice().getDisplayModes();

        for(int i = 0; i < displayModes.length; i++) {
            String mode = "" + 
                displayModes[i].getWidth() + " x " + 
                displayModes[i].getHeight() + "  " +
                displayModes[i].getBitDepth() + " Bit  " +
                displayModes[i].getRefreshRate() + " Hz";
                
            displayModeList.addItem(mode);                
        }        
    }

    /**
     * Exits the dialog.
     */
    private void exit() {
        setVisible(false);
        dispose();
        
        System.exit(0);        
    }
    
    /**
     * If the cancel button is pressed, the application quits.
     *
     * @param event the action event from the button listener
     */
    private void cancelButtonActionPerformed(ActionEvent event) {
        exit();
    }

    /**
     * If the ok button is pressed, the gaem frame is set up.
     *
     * @param event the action event from the button listener
     */
    private void okButtonActionPerformed(ActionEvent event) {
        // remove the dialog
        setVisible(false);
        dispose();

        if(windowModeButton.isSelected()) {
            // set window mode
            
            gameFrame.makeWindowScreen(800, 600);            
            
        } else {
            // set full-screen mode
            int i = displayModeList.getSelectedIndex();
            
            gameFrame.makeFullScreen(displayModes[i].getWidth(), displayModes[i].getHeight(), displayModes[i].getBitDepth(), displayModes[i].getRefreshRate());
            
            displayModes = null;
        }                
    }

    /**
     * This method is automatically called, if the users closes the dialog.
     *
     * @param event the window event from the window listener
     */
    private void closeDialog(WindowEvent event) {
        exit();
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -