40 lines
1.2 KiB
Java
40 lines
1.2 KiB
Java
|
import java.awt.event.*;
|
||
|
import javax.swing.*;
|
||
|
import java.awt.*;
|
||
|
|
||
|
public class plusoumoins implements ActionListener {
|
||
|
private JTextField zone;
|
||
|
private int n;
|
||
|
private plateau plat;
|
||
|
public plusoumoins(JTextField zone0, int n0, plateau plat0){
|
||
|
this.zone=zone0;
|
||
|
this.n=n0;
|
||
|
this.plat=plat0;
|
||
|
}
|
||
|
@Override
|
||
|
public void actionPerformed(ActionEvent evenement){
|
||
|
int nombre=0;
|
||
|
try{
|
||
|
this.zone.setBackground(new Color(255,255,255));
|
||
|
nombre=Integer.parseInt(this.zone.getText())+this.n;
|
||
|
if(nombre<0){
|
||
|
nombre=0;
|
||
|
}
|
||
|
if(this.plat.getLigne()!=-1 && this.plat.getCollonne()!=-1){
|
||
|
if(nombre>this.plat.getLigne()*this.plat.getCollonne()){
|
||
|
nombre=this.plat.getLigne()*this.plat.getCollonne();
|
||
|
}
|
||
|
this.zone.setText(String.valueOf(nombre));
|
||
|
}else{
|
||
|
this.zone.setBackground(Color.red);
|
||
|
this.zone.setText("Selectionner Ligne et Collonne Avant");
|
||
|
this.plat.setBombe(-1);
|
||
|
}
|
||
|
this.plat.setBombe(nombre);
|
||
|
}catch(NumberFormatException e1){
|
||
|
this.zone.setBackground(Color.red);
|
||
|
this.zone.setText("rentrer un nombre valide");
|
||
|
this.plat.setBombe(-1);
|
||
|
}
|
||
|
}
|
||
|
}
|