I am making an application of the game of roulette, where to bet the player must press buttons.
I can not get the number of bets placed on a JLabel calculated.
What the JLabel must return is contador
+ (JLabelname.getText())-->INT
Here I leave the class:
public class Chip extends JButton implements MouseListener {
public int contador=0;
int suma=0;
public String ap;
public JLabel apuesta=new JLabel();
public Chip(JLabel a) {
setEnabled(true);
setVisible(true);
apuesta=a;
setContentAreaFilled(true);
setBorderPainted(true);
setBorder(new LineBorder(Color.BLACK, 2));
setText(null);
this.addMouseListener(this);
}
public void setMostrarFichas()// Si ficha >0 Se muestra
{
setText(""+contador);
if(contador<=0){
setOpaque(false);
setContentAreaFilled(false);
setBorderPainted(false);
}else{
setOpaque(true);
setContentAreaFilled(true);
setBorderPainted(true);
}
}
@Override
public void mouseClicked(MouseEvent e) {
//suma=getIntLabel(suma); **AQUI ESTARIA EL PROBLEMA**
if((e.getModifiers() & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK){
contador++;
}else{
if(contador>0){
contador--;}
}
suma=suma+contador;
setMostrarFichas();
apuesta.setText(""+suma);
}
public int getIntLabel(int x)
{
if(apuesta.getText() != null){
x= Integer.parseInt(apuesta.getText());
}
return x;
}
The error:
at java.lang.NumberFormatException.forInputString(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at Chip.getIntLabel(Chip.java:80) at Chip.mouseClicked(Chip.java:59)