salut;
j'ai un probleme avec les actions sur les un thread lancer arreter ,Interompre,Redemarer
quelqu'un m'aider.
code source:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
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
92
93
94
95
96
97
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JLabel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.FlowLayout;
import java.awt.Polygon;
public class Tp2 {
 
 
    public Tp2() {
    }
 
 
    public static void main(String[] args) {
     Window w=new Window();
    }
}
class Window extends JFrame {
JPanel container=new JPanel();
JPanel p1=new JPanel();
JPanel pan=new JPanel();
JPanel pp=new JPanel();
JPanel p2=new JPanel();
JLabel l=new JLabel();
R  p=new R();
JButton b01=new JButton("Lancer");
JButton b02=new JButton("Arreter");
JButton b03=new JButton("Interompre");
JButton b04=new JButton("Redemarer");
    public Window() {
    	this.setTitle("Rotation des forme geometrique");
    	this.setSize(400,300);
    	this.setLocationRelativeTo(null);
    	this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	container.setLayout(new BorderLayout());
    	l.setForeground(Color.white);
    	l.setFont(new Font("Segoe Script",5,16));
    //	pp.setBackground(Color.black);
   // 	pp.add(l);
    	b01.addActionListener(new B1Listener() );
    	b02.addActionListener(new B2Listener());
    	b03.addActionListener(new B3Listener());
    	b04.addActionListener(new B4Listener());
   //  	b03.setEnabled(false);
    //	p1.setLayout(new GridLayout(2,2));
    	p1.setLayout(new FlowLayout());
    	pan.setLayout(new GridLayout(1,3));
    //	pan.setLayout(new FlowLayout());
    	p1.add(b01);
    	p1.add(b04);
      	p1.add(b03);
       	p1.add(b02);
      //p2.setBackground(Color.white);
    	pan.add(p);
    	//container.add(pp,BorderLayout.NORTH);
    	container.add(pan,BorderLayout.CENTER);
    	container.add(p1,BorderLayout.SOUTH);
    	this.setContentPane(container);
       	this.setVisible(true);
 
    }
    class B1Listener implements ActionListener{
    	public void actionPerformed(ActionEvent e){
    	p.start();
    	l.setText("Threads en Execution");
    		  	}
    }
    class B2Listener implements ActionListener{
    	public void actionPerformed(ActionEvent e){
 
 
    	}
    }
   class B3Listener implements ActionListener{
    	public void actionPerformed(ActionEvent e){
 
    	l.setText("Threads interompres");
 
       }
    }
  class B4Listener implements ActionListener{
    	public void actionPerformed(ActionEvent e){
    	l.setText("Threads en Execution");
    }
    }
 
}
////////////////
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
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
class R extends JPanel implements Runnable{
private int radians=0;
private Thread th=th = new Thread(this);
private boolean b=true;
 
    public void paintComponent(Graphics g) {
    		g.setColor(Color.white);
        	g.fillRect(0,0,this.getWidth(),this.getHeight());
        	g.setColor(Color.blue);
        	Graphics2D g2=(Graphics2D)g;
 
 
 
        Rectangle rct=new Rectangle(80,90,60,40);
        g2.rotate(Math.toRadians(radians), 110, 110);
 
      g2.fill(rct);
 
 
   }
  public void start() {
            th.start();
        }
 
 
   public void run() {
 
 
            while (b) {
 
            	 repaint();
            	 radians=radians+1%360;
                try {
                    th.sleep(5);
                } catch (InterruptedException e) {
 
                	break;
                	}
            }
 
        }
 
  }
///////