lblDisplay.setIcon(新的javax.swing.ImageIcon(“lion.PNG”); String names=JOptionPane.showInputDialog(“您看到的动物是什么”); if(“lion.equalsIg

lblDisplay.setIcon(新的javax.swing.ImageIcon(“lion.PNG”); String names=JOptionPane.showInputDialog(“您看到的动物是什么”); if(“lion.equalsIg,java,image,random,Java,Image,Random,lblDisplay.setIcon(新的javax.swing.ImageIcon(“lion.PNG”); String names=JOptionPane.showInputDialog(“您看到的动物是什么”); if(“lion.equalsIgnoreCase(名称)) { showMessageDialog(空,名称); 分数=分数+10; lblScore.setText(“您的分数=”+分数); } 其他的 { showMessageDialog(null,“不正确”); 得分

lblDisplay.setIcon(新的javax.swing.ImageIcon(“lion.PNG”); String names=JOptionPane.showInputDialog(“您看到的动物是什么”); if(“lion.equalsIgnoreCase(名称)) { showMessageDialog(空,名称); 分数=分数+10; lblScore.setText(“您的分数=”+分数); } 其他的 { showMessageDialog(null,“不正确”); 得分=得分-5分; lblScore.setText(“您的分数=”+分数); } } 如果(计数=4) { lblDisplay.setIcon(新的javax.swing.ImageIcon(“tiger101.PNG”); String name=JOptionPane.showInputDialog(“您看到的动物是什么”); 如果(“老虎”。相等信号案例(名称)) { showMessageDialog(null,名称); 分数=分数+10; lblScore.setText(“您的分数=”+分数); } 其他的 { showMessageDialog(null,“不正确”); 得分=得分-5分; lblScore.setText(“您的分数=”+分数); } } 如果(计数=5) { lblDisplay.setIcon(新的javax.swing.ImageIcon(“elephant.PNG”); String name=JOptionPane.showInputDialog(“您看到的动物是什么”); 如果(“大象”。相等信号案例(名称)) { showMessageDialog(null,名称); 分数=分数+10; lblScore.setText(“您的分数=”+分数); } 其他的 { showMessageDialog(null,“不正确”); 得分=得分-5分; lblScore.setText(“您的分数=”+分数); } } 如果(计数=6) { lblDisplay.setIcon(新的javax.swing.ImageIcon(“impala.PNG”); String name=JOptionPane.showInputDialog(“您看到的动物是什么”); if(“黑斑羚”。相等信号案例(名称)) { showMessageDialog(null,名称); 分数=分数+10; lblScore.setText(“您的分数=”+分数); } 其他的 { showMessageDialog(null,“不正确”); 得分=得分-5分; lblScore.setText(“您的分数=”+分数); } } 计数=计数+1; //TODO在此处添加您的处理代码: } /** *@param指定命令行参数 */ 公共静态void main(字符串参数[]){ /*设置Nimbus的外观和感觉*/ // /*如果Nimbus(在JavaSE6中引入)不可用,请使用默认的外观。 *详情请参阅http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ 试一试{ for(javax.swing.UIManager.LookAndFeelInfo:javax.swing.UIManager.getInstalledLookAndFeels()){ if(“Nimbus”.equals(info.getName())){ setLookAndFeel(info.getClassName()); 打破 } } }捕获(ClassNotFoundException ex){ getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE,null,ex); }catch(实例化异常){ getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE,null,ex); }捕获(非法访问例外){ getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE,null,ex); }catch(javax.swing.UnsupportedLookAndFeelException ex){ getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE,null,ex); } // /*创建并显示表单*/ invokeLater(new Runnable()){ 公开募捐{ new Main().setVisible(true); } }); } //变量声明-不修改 私有javax.swing.JButton btnShow; 私有javax.swing.JLabel jLabel1; 私有javax.swing.JLabel jLabel2; 私有javax.swing.JLabel lblDisplay; 私有javax.swing.JLabel lblScore; //变量结束声明 }
为什么不使用列表或集合。无序移动?知道原因将帮助我们给出一个有用的答案that@grexter89谢谢你的注意。固定的为什么不同的语言必须如此不同……你真的应该到处交换
START
END
JLabel MyImage = new JLabel(new ImageIcon("image1.png"));
Random rand = new Random();
int randomNum = rand.nextInt((max - min) + 1) + min;
JLabel MyImage = new JLabel(new ImageIcon("image"+randomNum+".png"));
private static int START = 1;
private static int END = 4;

Random rand = new SecureRandom();
String imagePath = String.format( //
    "image%d.png", //
    rand.nextInt(Math.abs(START - END) + 1) + END //
);

JLabel MyImage = new JLabel(new ImageIcon(imagePath));
String[] images = new String[]{"image1.png", "image2.png", "image3.png", "image4.png"};
int index = (int) (Math.random() * (images.length - 1));
JLabel MyImage = new JLabel(new ImageIcon(images[index]));
String[] images = new String[]{"image1.png","image2.png","image3.png"};
JLabel MyImage = new JLabel(new ImageIcon(
    images[(int)Math.floor(Math.random()*images.length)]));
int imagecount = 5;
JLabel MyImage = new JLabel(new ImageIcon("image" + (int)(Math.floor(Math.random()*imagescount)) + ".png"));
package Pictures;

import javax.swing.JOptionPane;


/**
 *
 * @author denc18
 */
public class Main extends javax.swing.JFrame {

    /**
     * Creates new form Main
     */
    public Main() {
        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.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        lblDisplay = new javax.swing.JLabel();
        btnShow = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        lblScore = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        btnShow.setFont(new java.awt.Font("Yu Gothic UI", 1, 18)); // NOI18N
        btnShow.setText("show");
        btnShow.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnShowActionPerformed(evt);
            }
        });

        jLabel2.setText("impala elephant lion tiger cat dog");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(145, 145, 145)
                        .addComponent(btnShow))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(108, 108, 108)
                        .addComponent(lblDisplay, javax.swing.GroupLayout.PREFERRED_SIZE, 149, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(44, 44, 44)
                                .addComponent(jLabel1))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(15, 15, 15)
                                .addComponent(lblScore, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(33, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 232, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(71, 71, 71))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addGap(36, 36, 36)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lblDisplay, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(43, 43, 43)
                        .addComponent(lblScore, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(31, 31, 31)
                .addComponent(btnShow)
                .addContainerGap(34, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>                        
    int count = (int)(Math.random()*7);
    int score = 0;

    private void btnShowActionPerformed(java.awt.event.ActionEvent evt) {                                        
    if (count == 1)
    {
        lblDisplay.setIcon( new javax.swing.ImageIcon("dog.PNG")); 
        String name = JOptionPane.showInputDialog("what is the Animal you see");

        if("dog".equalsIgnoreCase(name))
        {
           JOptionPane.showMessageDialog(null, name);
           score = score + 10;
           lblScore.setText("your score =" + score);
        }
        else
        {
            JOptionPane.showMessageDialog(null,"incorrect");
            score = score - 5;
           lblScore.setText("your score =" + score);
        }
    }
    if (count == 2)
    {
        lblDisplay.setIcon( new javax.swing.ImageIcon("cat.PNG"));
        String names = JOptionPane.showInputDialog("what is the Animal you see");

        if("cat".equalsIgnoreCase(names))
        {
           JOptionPane.showMessageDialog(null, names);
           score = score + 10;
           lblScore.setText("your score =" + score);
        }
        else
        {
            JOptionPane.showMessageDialog(null,"incorrect");
            score = score - 5;
           lblScore.setText("your score =" + score);
        }
    }
     if (count == 3)
    {
        lblDisplay.setIcon( new javax.swing.ImageIcon("lion.PNG"));
        String names = JOptionPane.showInputDialog("what is the Animal you see");

        if("lion".equalsIgnoreCase(names))
        {
           JOptionPane.showMessageDialog(null, names);
           score = score + 10;
           lblScore.setText("your score =" + score);
        }
        else
        {
            JOptionPane.showMessageDialog(null,"incorrect");
            score = score - 5;
           lblScore.setText("your score =" + score);
        }
    }
     if (count == 4)
    {
        lblDisplay.setIcon( new javax.swing.ImageIcon("tiger101.PNG")); 
        String name = JOptionPane.showInputDialog("what is the Animal you see");

        if("tiger".equalsIgnoreCase(name))
        {
           JOptionPane.showMessageDialog(null, name);
           score = score + 10;
           lblScore.setText("your score =" + score);
        }
        else
        {
            JOptionPane.showMessageDialog(null,"incorrect");
            score = score - 5;
           lblScore.setText("your score =" + score);
        }
    }
      if (count == 5)
    {
        lblDisplay.setIcon( new javax.swing.ImageIcon("elephant.PNG")); 
        String name = JOptionPane.showInputDialog("what is the Animal you see");

        if("elephant".equalsIgnoreCase(name))
        {
           JOptionPane.showMessageDialog(null, name);
           score = score + 10;
           lblScore.setText("your score =" + score);
        }
        else
        {
            JOptionPane.showMessageDialog(null,"incorrect");
            score = score - 5;
           lblScore.setText("your score =" + score);
        }
    }
        if (count == 6 )
    {
        lblDisplay.setIcon( new javax.swing.ImageIcon("impala.PNG")); 
        String name = JOptionPane.showInputDialog("what is the Animal you see");

        if("impala".equalsIgnoreCase(name))
        {
           JOptionPane.showMessageDialog(null, name);
           score = score + 10;
           lblScore.setText("your score =" + score );

        }
        else
        {
            JOptionPane.showMessageDialog(null,"incorrect");
            score = score - 5;
           lblScore.setText("your score =" + score);
        }
    }
    count = count + 1;
// TODO add your handling code here:
    }                                       

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Main().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JButton btnShow;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel lblDisplay;
    private javax.swing.JLabel lblScore;
    // End of variables declaration                   
}