Bonjour, j'ai deux fichiers. L'un "AxisCamera" (c'est un java class) et l'autre "Integration" (c'est un JFrame). Je souhaiterai intégrer l'affichage de ma caméra (AxisCamera) dans mon panel JPanelPhoto qui se trouve dans le fichier Integration. Mais je ne sais pas comment faire.

Pouvez-vous m'aider ?

Merci d'avance.

AxisCamera:
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
 
package Test;
 
 
import java.net.*; 
import com.sun.image.codec.jpeg.*; 
import java.io.*; 
import java.awt.*; 
import java.awt.event.*; 
import java.awt.image.*; 
import javax.swing.*; 
 
/**********************************************/
 
public class AxisCamera extends JPanel implements Runnable { 
 
    public boolean useMJPGStream = true; 
    public String jpgURL="http://10.104.100.101/axis-cgi/jpg/image.cgi?resolution=704x480"; 
    public String mjpgURL="http://10.104.100.101/axis-cgi/mjpg/video.cgi?resolution=704x480";  //URL de connexion
    DataInputStream dis;    //flux de données d'éntrée 
    private Image image=null;   
    public Dimension imageSize = null; 
    public boolean connected = false; 
    private boolean initCompleted = false; 
    HttpURLConnection huc=null;     
    Component parent;
 
 
    /** Crée une nouvelle instance de AxisCamera */ 
    AxisCamera (Component parent_) { 
        parent = parent_; 
        //initComponents();     
    }
 
 
 
 
    public void connect(){ 
        try{ 
            URL u = new URL(useMJPGStream?mjpgURL:jpgURL); 
            huc = (HttpURLConnection) u.openConnection(); 
            //System.out.println(huc.getContentType()); 
            InputStream is = huc.getInputStream(); 
            connected = true; 
            BufferedInputStream bis = new BufferedInputStream(is); 
            dis= new DataInputStream(bis); 
            if (!initCompleted) initDisplay(); 
        }catch(IOException e){ //Si aucune connexion n'existe, on attend pour se reconnecter à nouveau 
            try{ 
                huc.disconnect(); 
                Thread.sleep(60); 
            }catch(InterruptedException ie){huc.disconnect();connect();} 
                connect(); 
        }catch(Exception e){;} 
    } 
 
    public void initDisplay(){ //Configuration de l'affichage
        if (useMJPGStream)readMJPGStream(); 
        else {readJPG();disconnect();} 
        imageSize = new Dimension(image.getWidth(this), image.getHeight(this)); 
          //centrage de la fenêtre
        Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        this.setLocation((screenSize.width-this.getWidth())/2, (screenSize.height-this.getHeight())/2);
        setPreferredSize(imageSize); 
        parent.setSize(imageSize); 
 
        parent.validate(); 
        initCompleted = true; 
    } 
 
    public void disconnect(){ 
    try{ 
        if(connected){ 
        dis.close(); 
        connected = false; 
    } 
    }catch(Exception e){;} 
    } 
 
 
    public void paint(Graphics g) { //On fixe l'image dans le Panel
        if (image != null) 
        g.drawImage(image, 0, 0, this); 
    } 
 
 
    public void readStream(){ //Lecture des flux continu
    try{ 
        if (useMJPGStream){ 
        while(true){ 
        readMJPGStream(); 
        parent.repaint(); 
        } 
    } 
    else{ 
        while(true){ 
        connect(); 
        readJPG(); 
        parent.repaint(); 
        disconnect(); 
 
        } 
    } 
 
    }catch(Exception e){;} 
    } 
 
 
    public void readMJPGStream(){ //lecture du flux mjpg 
        readLine(3,dis); //Lecture à partir de la 3ème ligne
        readJPG(); 
        readLine(2,dis); //on retire les 2 dernières lignes
    }
 
    public void readJPG(){ //Lecture de l'image jpeg incorporée 
    try{ 
        JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(dis); 
        image = decoder.decodeAsBufferedImage(); 
        }catch(Exception e){e.printStackTrace();disconnect();} 
    } 
 
    public void readLine(int n, DataInputStream dis){ //utilisée pour sauter les lignes d'en-tête
    for (int i=0; i<n;i++){ 
        readLine(dis); 
    } 
    } 
    public void readLine(DataInputStream dis){ 
    try{ 
        boolean end = false; 
        String lineEnd = "\n"; //On suppose que la fin de la ligne est marqué
        byte[] lineEndBytes = lineEnd.getBytes(); 
        byte[] byteBuf = new byte[lineEndBytes.length]; 
 
        while(!end){ 
        dis.read(byteBuf,0,lineEndBytes.length); 
        String t = new String(byteBuf); 
        //System.out.print(t); //décommenter pour voir à quoi ressemble les lignes
        if(t.equals(lineEnd)) end=true; 
    } 
    }catch(Exception e){e.printStackTrace();} 
 
 
    } 
    public void run() { 
        connect(); 
        readStream(); 
    } 
 
 
 
    public static void main(String[] args) { 
        JFrame jframe = new JFrame(); 
        jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
        AxisCamera axPanel = new AxisCamera(jframe); 
        new Thread(axPanel).start(); 
        jframe.getContentPane().add(axPanel); 
        jframe.pack(); 
        jframe.show(); 
        /* java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new JFrame().setVisible(true);
            }
        });*/
    } 
 
 
 
}
Integration:
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
 
package Test;
 
import java.awt.Dimension;
import javax.swing.*;
 
/**
 *
 * @author  GRESLON Jérémy
 */
public class Integration extends javax.swing.JFrame {
 
    /** Creates new form Integration */
    public Integration() {
        initComponents();
 
        /*AxisCamera cam = new AxisCamera();
        cam.run();*/
 
         //centrage de la fenêtre
        Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        this.pack();
        this.setLocation((screenSize.width - this.getWidth()) / 2, (screenSize.height - this.getHeight()) / 2);
    }
 
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {
 
        jPanelPhoto = new javax.swing.JPanel();
        jButtonBadge = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jPanelAlarme = new javax.swing.JPanel();
        jButtonAlarme = new javax.swing.JButton();
        jLabelAutorisation = new javax.swing.JLabel();
        jToggleButtonPorte = new javax.swing.JToggleButton();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel4 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jTextFieldAutorisation = new javax.swing.JTextField();
        jTextFieldNumBadge = new javax.swing.JTextField();
 
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
 
        jPanelPhoto.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
 
        javax.swing.GroupLayout jPanelPhotoLayout = new javax.swing.GroupLayout(jPanelPhoto);
        jPanelPhoto.setLayout(jPanelPhotoLayout);
        jPanelPhotoLayout.setHorizontalGroup(
            jPanelPhotoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 294, Short.MAX_VALUE)
        );
        jPanelPhotoLayout.setVerticalGroup(
            jPanelPhotoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 276, Short.MAX_VALUE)
        );
 
        jButtonBadge.setText("Passage du badge");
        jButtonBadge.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonBadgeActionPerformed(evt);
            }
        });
 
        jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
 
        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 297, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 276, Short.MAX_VALUE)
        );
 
        jLabel1.setText("Caméra extérieure:");
 
        jLabel2.setText("Photo de l'utilisateur:");
 
        jPanelAlarme.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
 
        javax.swing.GroupLayout jPanelAlarmeLayout = new javax.swing.GroupLayout(jPanelAlarme);
        jPanelAlarme.setLayout(jPanelAlarmeLayout);
        jPanelAlarmeLayout.setHorizontalGroup(
            jPanelAlarmeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 105, Short.MAX_VALUE)
        );
        jPanelAlarmeLayout.setVerticalGroup(
            jPanelAlarmeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
 
        jButtonAlarme.setText("Alarme");
        jButtonAlarme.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAlarmeActionPerformed(evt);
            }
        });
 
        jLabelAutorisation.setText("La porte est fermée");
 
        jToggleButtonPorte.setText("Ouverture/Fermeture porte");
        jToggleButtonPorte.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButtonPorteActionPerformed(evt);
            }
        });
 
        jLabel4.setText("Simulation de la porte d'entrée:");
 
        jLabel3.setText("Intervention de la sécurité:");
 
        jTextFieldNumBadge.setEditable(false);
        jTextFieldNumBadge.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldNumBadgeActionPerformed(evt);
            }
        });
 
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(122, 122, 122)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jTextFieldNumBadge, javax.swing.GroupLayout.DEFAULT_SIZE, 347, Short.MAX_VALUE)
                        .addComponent(jTextFieldAutorisation, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 347, Short.MAX_VALUE)
                        .addComponent(jLabel1)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(63, 63, 63)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jPanelPhoto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(80, 80, 80)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jPanelAlarme, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addGroup(layout.createSequentialGroup()
                                                .addGap(10, 10, 10)
                                                .addComponent(jButtonAlarme, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                        .addGap(66, 66, 66))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 54, Short.MAX_VALUE)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                            .addComponent(jToggleButtonPorte, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(jSeparator1)
                                            .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabelAutorisation, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(36, 36, 36)))
                                .addContainerGap(19, Short.MAX_VALUE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 264, Short.MAX_VALUE)
                                .addComponent(jLabel3)
                                .addGap(76, 76, 76))))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(140, 140, 140)
                        .addComponent(jButtonBadge, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(340, 340, 340))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(42, 42, 42)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanelAlarme, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonAlarme, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel4)
                        .addGap(18, 18, 18)
                        .addComponent(jLabelAutorisation, javax.swing.GroupLayout.DEFAULT_SIZE, 67, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jToggleButtonPorte))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanelPhoto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 30, Short.MAX_VALUE)
                        .addComponent(jTextFieldNumBadge, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(3, 3, 3)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonBadge)
                    .addComponent(jTextFieldAutorisation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
 
        pack();
    }// </editor-fold>                        
 
    private void jButtonBadgeActionPerformed(java.awt.event.ActionEvent evt) {                                             
        // TODO add your handling code here:
 
         //Connexion FTP
        TestFTP test = new TestFTP();
        test.Connexion("127.0.0.1", 21); //hôte + port auquel on veut se connecter
 
        //Affichage de la photo dans le panel          
        ImageIcon icone = new ImageIcon("C:\\Documents and Settings\\GRESLON Jérémy\\Mes documents\\Photos_telechargees\\25.jpg");
        JLabel photo = new JLabel (icone);  
        photo.setSize(jPanelPhoto.getWidth(), jPanelPhoto.getHeight());
        jPanelPhoto.add(photo);
        jPanelPhoto.repaint();
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
 
        /*Autorisation aut = new Autorisation();
        aut.Connection();*/
}                                            
 
    private void jButtonAlarmeActionPerformed(java.awt.event.ActionEvent evt) {                                              
        // TODO add your handling code here:
 
}                                             
 
    private void jToggleButtonPorteActionPerformed(java.awt.event.ActionEvent evt) {                                                   
        // TODO add your handling code here:
 
        Porte porte = new Porte();
        AbstractButton bouton = (AbstractButton) evt.getSource();
        boolean selected = bouton.getModel().isSelected();
        if (selected) {
            porte.PorteOuverte();
        } else {
            porte.PorteFermee();
        }
    }                                                  
 
    private void jTextFieldNumBadgeActionPerformed(java.awt.event.ActionEvent evt) {                                                   
        // TODO add your handling code here:
    }                                                  
 
 
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Integration().setVisible(true);
            }
        });
    }
 
    // Variables declaration - do not modify                     
    private javax.swing.JButton jButtonAlarme;
    private javax.swing.JButton jButtonBadge;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    public static javax.swing.JLabel jLabelAutorisation;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanelAlarme;
    private javax.swing.JPanel jPanelPhoto;
    private javax.swing.JSeparator jSeparator1;
    public static javax.swing.JTextField jTextFieldAutorisation;
    public static javax.swing.JTextField jTextFieldNumBadge;
    private javax.swing.JToggleButton jToggleButtonPorte;
    // End of variables declaration                   
 
}