| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 
 | package jeuallumette.parts;
 
import javax.annotation.PostConstruct;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
 
public class SamplePart {
 
	public  static  int compteur = 25;  
	@PostConstruct
	public void createComposite(Composite parent) {
		Button btn;
		Text text;
		Label label;
 
		GridData btnLayoutData = (new GridData(SWT.FILL, SWT.CENTER, true, false,3,1));
		parent.setLayout(new GridLayout(3, false));
 
		text = new Text(parent, SWT.BORDER|SWT.READ_ONLY);
		text.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false,3,1));
		text.setText("Bienvenue dans le jeu des allumettes");
 
		btn = new Button(parent, SWT.PUSH);
		btn.setLayoutData(btnLayoutData);
		btn.setText("bouton 1");
		btn.addSelectionListener(new SelectionListener() {
 
			@Override
			public void widgetSelected(SelectionEvent e) {
				if(compteur > 0) {
					compteur = compteur-1;
				} else if(compteur < 1) {
					System.out.println("perdu !");
				}
				System.out.println(compteur);
			}
 
			@Override
			public void widgetDefaultSelected(SelectionEvent e) {}
		});
 
		btn = new Button(parent, SWT.PUSH);
		btn.setLayoutData(btnLayoutData);
		btn.setText("bouton 2");
		btn.addSelectionListener(new SelectionListener() {
 
			@Override
			public void widgetSelected(SelectionEvent e) {
				if(compteur > 0) {
					compteur = compteur-2;
				} else if(compteur < 1) {
					System.out.println("perdu !");
				}
				System.out.println(compteur);
			}
 
			@Override
			public void widgetDefaultSelected(SelectionEvent e) {}
		});
 
		btn = new Button(parent, SWT.PUSH);
		btn.setLayoutData(btnLayoutData);
		btn.setText("bouton 3");
		btn.addSelectionListener(new SelectionListener() {
 
			@Override
			public void widgetSelected(SelectionEvent e) {
				if(compteur > 0) {
					compteur =compteur-3;
				}else if(compteur < 1){
					System.out.println("perdu !");
				}
				System.out.println(compteur);
			}
 
			@Override
			public void widgetDefaultSelected(SelectionEvent e) {}
		});
 
		label = new Label(parent, SWT.LEFT); 
		label.setText("Restant :");
 
	}
} | 
Partager