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

📄 objectchooser.java

📁 用java开发的一个实施策略游戏源码 值得学习一下
💻 JAVA
字号:
/*
 * ObjectChooser.java
 *
 * Created on March 6, 2002, 7:09 AM
 */

package netwar.mapper;

/** Dialog to choose a GameObject to load.
 * @author Kyle Kakligian
 */
public class ObjectChooser extends javax.swing.JDialog {
    
    /** Creates new form ObjectChooser
     * @param parent Owner of this dialog
     * @param modal whether or not the dialog is modal.
     */
    public ObjectChooser(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        setTitle("Object chooser");
        setLocation(200,150);
        initComponents();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {//GEN-BEGIN:initComponents
        jComboBox1 = new javax.swing.JComboBox();
        jPanel1 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                closeDialog(evt);
            }
        });

        jComboBox1.setMaximumRowCount(16);
        populateList();
        getContentPane().add(jComboBox1, java.awt.BorderLayout.NORTH);

        jButton1.setText("Okay");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                OK(evt);
            }
        });

        jPanel1.add(jButton1);

        jButton2.setText("Cancel");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Cancel(evt);
            }
        });

        jPanel1.add(jButton2);

        getContentPane().add(jPanel1, java.awt.BorderLayout.SOUTH);

        pack();
    }//GEN-END:initComponents

    private void Cancel(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Cancel
        setVisible(false);
        dispose();
    }//GEN-LAST:event_Cancel

    private void OK(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OK
        unitName = "netwar.game.object." + jComboBox1.getSelectedItem().toString();
        setVisible(false);
        dispose();
    }//GEN-LAST:event_OK
    private void populateList() {
        String list[] = netwar.utils.Dir.directoryList("game/object");
        if(list != null)
            for(int t = 0; t < list.length; t++)
                if(list[t].endsWith(".class"))
                    jComboBox1.addItem(list[t].substring(0,list[t].indexOf(".class")));
    }
    /** Closes the dialog */
    private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
        setVisible(false);
        dispose();
    }//GEN-LAST:event_closeDialog
    
    String unitName;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton1;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables
    
}

⌨️ 快捷键说明

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