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

📄 mainjframe.java

📁 九宫问题(八数码)的一个小软件
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                setGame();
                break;
        }
    }
    
    private javax.swing.JFrame getThis(){
        return this;
    }
    
    private void okButActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButActionPerformed
        new Thread(){
            public void run(){
                int[] init=new int[9];
                if(jb1.isSelected()){
                    curGame=EightGame.connectTo(j0.getText(),userId.getText());
                    if(curGame==null){
                        JOptionPane.showMessageDialog(getThis(),"Connect Failed!","Error",JOptionPane.ERROR_MESSAGE);
                        connectDialog.setVisible(false);
                        return;
                    }else{
                        newDialog.dispose();
                        updateconnect.start();
                    }
                }else{
                    if(jb3.isSelected()){
                        curGame=EightGame.createInstance(userId.getText());
                    }else{
                        try{
                            init[0]=Integer.parseInt(j1.getText());
                            init[1]=Integer.parseInt(j2.getText());
                            init[2]=Integer.parseInt(j3.getText());
                            init[3]=Integer.parseInt(j4.getText());
                            init[4]=Integer.parseInt(j5.getText());
                            init[5]=Integer.parseInt(j6.getText());
                            init[6]=Integer.parseInt(j7.getText());
                            init[7]=Integer.parseInt(j8.getText());
                            init[8]=Integer.parseInt(j9.getText());
                            curGame=EightGame.createInstance(init,userId.getText());
                        }catch(Exception e){
                            curGame=null;
                        }
                    }
                    if(curGame!=null){
                        if(cb.isSelected()){
                            curGame.asServer();
                            updateconnect.start();
                        }else{
                            connectDialog.setVisible(false);
                            time.start();
                            curGame.startGame();
                            curGame.goon();
                        }
                    }else{
                        JOptionPane.showMessageDialog(getThis(),"Initialize error! Perhaps your inputs has no solution.","Error",JOptionPane.ERROR_MESSAGE);
                        connectDialog.setVisible(false);
                        return;
                    }
                }
                analyse.setAnalyse(0,curGame.eight);
                analyse.setAnalyse(1,curGame.eightdt);
                analyse.setAnalyse(2,curGame.eightas);
                newDialog.dispose();
                startItem.setEnabled(false);
                pauseItem.setEnabled(true);
                setGame();
                stopItem.setEnabled(true);
                userInfo.setSelectedIndex(0);
                userInfo.setEnabled(true);
            }
        }.start();
        if(cb.isSelected() && cb.isEnabled()){
            connectStart.setEnabled(true);
        }else{
            connectStart.setEnabled(false);
        }
        connectDialog.setVisible(true);
    }//GEN-LAST:event_okButActionPerformed
    
    private void js1StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_js1StateChanged
        levelLabel.setText(ResourceBundle.getBundle("org/ray/ninegrid/frame").getString("level"+js1.getValue()));
    }//GEN-LAST:event_js1StateChanged
    
    private void analyseMActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_analyseMActionPerformed
// TODO add your handling code here:
    }//GEN-LAST:event_analyseMActionPerformed
    
    private void jb4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jb4ActionPerformed
        refreshDialog();
    }//GEN-LAST:event_jb4ActionPerformed
    
    private void jb3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jb3ActionPerformed
        refreshDialog();
    }//GEN-LAST:event_jb3ActionPerformed
    
    private void refreshDialog(){
        ciplabel.setEnabled(jb1.isSelected());
        j0.setEnabled(jb1.isSelected());
        cb.setEnabled(jb2.isSelected());
        
        jb3.setEnabled(jb2.isSelected());
        jb4.setEnabled(jb2.isSelected());
        
        js1.setEnabled(jb3.isSelected() & jb3.isEnabled());
        levelLabel.setEnabled(jb3.isSelected() & jb3.isEnabled());
        
        j1.setEnabled(jb4.isSelected() & jb4.isEnabled());
        j2.setEnabled(jb4.isSelected() & jb4.isEnabled());
        j3.setEnabled(jb4.isSelected() & jb4.isEnabled());
        j4.setEnabled(jb4.isSelected() & jb4.isEnabled());
        j5.setEnabled(jb4.isSelected() & jb4.isEnabled());
        j6.setEnabled(jb4.isSelected() & jb4.isEnabled());
        j7.setEnabled(jb4.isSelected() & jb4.isEnabled());
        j8.setEnabled(jb4.isSelected() & jb4.isEnabled());
        j9.setEnabled(jb4.isSelected() & jb4.isEnabled());
    }
    
    private void jb2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jb2ActionPerformed
        refreshDialog();
    }//GEN-LAST:event_jb2ActionPerformed
    
    private void jb1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jb1ActionPerformed
        refreshDialog();
    }//GEN-LAST:event_jb1ActionPerformed
    
    private void startItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startItemActionPerformed
        newDialog.setVisible(true);
    }//GEN-LAST:event_startItemActionPerformed
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JDialog aboutDialog;
    private javax.swing.JMenu analyseM;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.JCheckBox cb;
    private javax.swing.JLabel ciplabel;
    private javax.swing.JDialog connectDialog;
    private javax.swing.JButton connectStart;
    private javax.swing.JMenuItem exitItem;
    private javax.swing.JMenu gameM;
    private javax.swing.JMenu helpM;
    private javax.swing.JTextField j0;
    private javax.swing.JTextField j1;
    private javax.swing.JTextField j2;
    private javax.swing.JTextField j3;
    private javax.swing.JTextField j4;
    private javax.swing.JTextField j5;
    private javax.swing.JTextField j6;
    private javax.swing.JTextField j7;
    private javax.swing.JTextField j8;
    private javax.swing.JTextField j9;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JProgressBar jProgressBar1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JRadioButton jb1;
    private javax.swing.JRadioButton jb2;
    private javax.swing.JRadioButton jb3;
    private javax.swing.JRadioButton jb4;
    private javax.swing.JSlider js1;
    private javax.swing.JLabel levelLabel;
    private javax.swing.JDialog newDialog;
    private javax.swing.JLabel numOfPlayer;
    private javax.swing.JButton okBut;
    private javax.swing.JLabel otherStepsLabel;
    private javax.swing.JMenuItem pauseItem;
    private javax.swing.JLabel scoreLabel;
    private javax.swing.JMenuItem startItem;
    private javax.swing.JLabel stepsLabel;
    private javax.swing.JMenuItem stopItem;
    private javax.swing.JLabel timeLabel;
    private javax.swing.JTextField userId;
    private javax.swing.JComboBox userInfo;
    private javax.swing.JLabel userLabel;
    // End of variables declaration//GEN-END:variables
    
    public void setGame(){
        int[] game=curGame.getCurStatus();
        for(int i=0;i<9;i++){
            jb[i].setIcon(EightUtil.getInstance().getImage("icon"+game[i]));
            jb[i].setEnabled(true);
        }
        userLabel.setText(curGame.getUserid());
        stepsLabel.setText(String.valueOf(curGame.getSteps()));
        Vector<EightGame.Info> group=curGame.others;
        userInfo.removeAllItems();
        for(EightGame.Info i:group){
            userInfo.addItem(i);
        }
        this.repaint();
    }
    
    public void updateUserNum(){
        int num=curGame.getConnects();
        if(num<=0){
            connectDialog.dispose();
            curGame.startGame();
            curGame.goon();
            numOfPlayer.setText("1");
            setGame();
            time.start();
            updateconnect.stop();
        }else{
            numOfPlayer.setText(String.valueOf(num));
            numOfPlayer.repaint();
        }
    }
}

⌨️ 快捷键说明

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