Bonjour à tous,
J'ai une interface graphique composé de plusieurs panneau, dans un de ces paneau j'affiche un trajet (ca ca fonctionne) et dans un un autre j'affiche des images (jPanelVisualisation), j'essai pour l'instant d'aficher juste un trait dans la jpanelTrajet et juste une image dans le jpanelVisualisation, si j'arrive à faire ca j'arriverais à faire la suite.
Pour le trait dans le panneau trajet ca fonctionne, par contre pour l'image je n'y arrive pas, je ne sait pas ce que je doit mettre au dernier paramètre de g.drawImage(img, 10,10,50,100,this);, par quoi remplacer le this?
voila mon code:
main:
InterfaceGraphique
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 package essai; public class Main { public Main() { } public static void main(String[] args) { Application appli= new Application(); } }
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 package essai; import java.awt.Graphics; public class InterfaceGraphique extends javax.swing.JFrame { private Graphics gTraj; private Graphics gVis; private int hauteur=0; private int largeur=0; private Application app=null; public InterfaceGraphique() { } public InterfaceGraphique(Application app) { initComponents(); this.setSize(1024,760); this.app=app; this.gTraj=jPanelTrajet.getGraphics(); this.gVis=jPanelVisualisation.getGraphics(); this.largeur=jPanelTrajet.getWidth(); this.hauteur=jPanelTrajet.getHeight(); } public Graphics getGTraj(){ return this.gTraj; } public Graphics getGVis(){ return this.gVis; } public int getLargeur(){ return this.largeur; } public int getHauteur(){ return this.hauteur; } public void paint(Graphics g){ super.paint(g); } private void initComponents() { //ici se trouve le code généré par netbeans pour l'interface que j'ai supprimer pour le forum } private void jButtonArreterActionPerformed(java.awt.event.ActionEvent evt) { app.arreterApplication(); // TODO add your handling code here: } private void jButtonDemarrerActionPerformed(java.awt.event.ActionEvent evt) { repaint(); app.demarrerApplication(); // TODO add your handling code here: } /* public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new InterfaceGraphique().setVisible(true); } }); }*/ // Variables declaration - do not modify private javax.swing.JButton jButtonArreter; private javax.swing.JButton jButtonAutomatique; private javax.swing.JButton jButtonDemarrer; private javax.swing.JButton jButtonManuel; private javax.swing.JButton jButtonOuvrir; private javax.swing.JButton jButtonSauvegarder; private javax.swing.JPanel jPanelApplication; private javax.swing.JPanel jPanelCommande; private javax.swing.JPanel jPanelFichier; private javax.swing.JPanel jPanelFonctionnement; private javax.swing.JPanel jPanelHistorique; private javax.swing.JPanel jPanelTrajet; private javax.swing.JPanel jPanelVisualisation; // End of variables declaration }
Application:
Trajet:
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 package essai; import java.awt.Graphics; public class Application { private InterfaceGraphique interGraph=null; private Trajet t=null; private Visualisation v=null; private Graphics g; public Application() { this.interGraph=new InterfaceGraphique(this); this.interGraph.setVisible(true); init(); } public void init(){ initObjects(); } public void initObjects(){ this.t=new Trajet(this.interGraph.getGTraj(),this.interGraph.getLargeur(),this.interGraph.getHauteur()); this.v=new Visualisation(this.interGraph.getGVis()); } public void demarrerApplication(){ this.interGraph.repaint(); t.start(); v.start(); } public void arreterApplication(){ t.stopTrajet(); } }
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 package essai; import java.awt.*; import java.awt.Graphics; import java.awt.Graphics2D; public class Trajet extends Thread{ private Graphics g; private boolean enCours=true; public Trajet() { } public Trajet(Graphics g,int largeur,int hauteur){ this.g=g; } public void manuel(){ traceTraj(this.g); } public void run(){ enCours=true; do{ manuel(); } while(enCours); } public void stopTrajet(){ this.enCours=false; } private void traceTraj(Graphics g) { Graphics2D g2D=(Graphics2D)g; g2D.setPaint(Color.GREEN); this.g.drawLine(0,0,200,100); } }
Visualisation:
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 package essai; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import java.awt.Toolkit; import java.io.File; public class Visualisation extends Thread { private Graphics g; public boolean enCours=true; InterfaceGraphique intergraph; File file; Image img; int a; public Visualisation() { } public Visualisation(Graphics g) { this.g=g; } public void run(){ enCours=true; do{ afficher(); } while(enCours); } public void afficher(){ afficherImage(this.g); } private void afficherImage(Graphics g) { file=new File("Q:\\photos\\Canard1.jpg"); String name=file.getName(); img=Toolkit.getDefaultToolkit().getImage(name) ; g.drawImage(img, 10,10,50,100,this); System.out.println("image"); } }
Partager