private void initComponents() {
title = new javax.swing.JLabel();
number = new javax.swing.JLabel();
roll = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);
title.setFont(new java.awt.Font("Tahoma", 0, 24));
title.setText("Virtual Dice");
title.setHorizontalTextPosition(javax.swing.SwingC onstants.CENTER);
number.setFont(new java.awt.Font("Tahoma", 0, 36));
number.setText("0");
roll.setText("Roll!");
roll.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
rollActionPerformed(evt);
}
});
First of all, what is that parenthesis at the end? It shouldn't be there, neither should the semicolon, they will probably give you problems later. ALSO make sure you replace it with a bracket ( } ), you are one short.
EDIT: I'm sorry, that parenthesis and semi-colon are required, my apologies.
And for the dereferencing, you tried to use toString() on an int, and not on an Integer object. You see, int is a primitive data type, like boolean, or double, or byte.
Integer is a class file, like String, or JFrame, or virtualDice (btw, you should rename it to VirtualDice, class names are just supposed to start with a capital, you named everything else right).
Integer actually has a method called toString() for you to use, not the int data type. So you need to do this
private void rollActionPerformed(java.awt.event.ActionEvent evt) {
Random dice = new Random();
Integer numb = new Integer(dice.nextInt(6) + 1);
number.setText(numb.toString());
}
That part should work perfectly
