How to make simple Dice in JAVA using NetBeansIDE
How to make simple Dice in JAVA using NetBeansIDE
1: Make a netbeans java application project.
2: Make a jFrame form with JLabel and JButton.
3: Copy the required dice images to the default package(or any other package) of the project.
4: Right click on jButton and select Events>Action>actionPerfomed in the popup menu.
5: Write the code.
code for the image display on random:
Random rd=new Random();
int random=0;
random=rd.nextInt(6)+1;
switch(random){
case 1:
jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/dice1.gif")));
break;
case 2:
jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/dice2.gif")));
break;
case 3:
jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/dice3.gif")));
break;
case 4:
jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/dice4.gif")));
break;
case 5:
jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/dice5.gif")));
break;
case 6:
jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/dice6.gif")));
break;
}
6: Run the project.
7: Finish
Thank You :)
Like My Facebook Page for more video updates:
https://www.facebook.com/pages/Raks/335960303097841
Comments
Post a Comment