mimi1255
Messages postés80Date d'inscriptionmardi 22 janvier 2008StatutMembreDernière intervention15 février 2022
-
7 mars 2008 à 14:37
mimi1255
Messages postés80Date d'inscriptionmardi 22 janvier 2008StatutMembreDernière intervention15 février 2022
-
10 mars 2008 à 20:45
Bonjour, je voudrais rajouter un JSlider dans mon panel, mais j'ai des erreurs, pouvez-vous regarder ?
Merci d'avance.
voici mon code:
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.*;
//import java.lang.Object;
/**********************************************/
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=352x240";
public String mjpgURL="http://10.104.100.101/axis-cgi/mjpg/video.cgi?resolution=352x240";
DataInputStream dis;
private Image image=null;
public Dimension imageSize = null;
public boolean connected = false;
private boolean initCompleted = false;
HttpURLConnection huc=null;
Component parent;
/** Creates a new instance of AxisCamera */
public AxisCamera (Component parent_) {
parent = parent_;
initComponents();
}
@SuppressWarnings("empty-statement")
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){ //incase no connection exists wait and try again, instead of printing the error
try{
huc.disconnect();
Thread.sleep(60);
}catch(InterruptedException ie){huc.disconnect();connect();}
connect();
}catch(Exception e){;}
}
public void initDisplay(){ //setup the display
if (useMJPGStream)readMJPGStream();
else {readJPG();disconnect();}
imageSize = new Dimension(image.getWidth(this), image.getHeight(this));
setPreferredSize(imageSize);
parent.setSize(imageSize);
parent.validate();
initCompleted = true;
}
@SuppressWarnings("empty-statement")
public void disconnect(){
try{
if(connected){
dis.close();
connected = false;
}
}catch(Exception e){;}
}
@Override
public void paint(Graphics g) { //used to set the image on the panel
if (image != null)
g.drawImage(image, 0, 0, this);
}
@SuppressWarnings("empty-statement")
public void readStream(){ //the basic method to continuously read the stream
try{
if (useMJPGStream){
while(true){
readMJPGStream();
parent.repaint();
}
}
else{
while(true){
connect();
readJPG();
parent.repaint();
disconnect();
}
}
}catch(Exception e){;}
}
public void readMJPGStream(){ //preprocess the mjpg stream to remove the mjpg encapsulation
readLine(3,dis); //discard the first 3 lines
readJPG();
readLine(2,dis); //discard the last two lines
}
public void readJPG(){ //read the embedded jpeg image
try{
JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(dis);
image = decoder.decodeAsBufferedImage();
}catch(Exception e){e.printStackTrace();disconnect();}
}
public void readLine(int n, DataInputStream dis){ //used to strip out the header lines
for (int i=0; i<n;i++){
readLine(dis);
}
}
public void readLine(DataInputStream dis){
try{
boolean end = false;
String lineEnd = "\n"; //assumes that the end of the line is marked with this
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); //uncomment if you want to see what the lines actually look like
if(t.equals(lineEnd)) end=true;
}
}catch(Exception e){e.printStackTrace();}
}
public void run() {
connect();
readStream();
}
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jSliderGaucheDroite = new javax.swing.JSlider();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(91, 91, 91)
.add(jSliderGaucheDroite, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap(109, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.addContainerGap(210, Short.MAX_VALUE)
.add(jSliderGaucheDroite, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(65, 65, 65))
);
pack();
}// </editor-fold>
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);
}
});*/
}
private javax.swing.JSlider jSliderGaucheDroite;
}
cs_DARKSIDIOUS
Messages postés15814Date d'inscriptionjeudi 8 août 2002StatutMembreDernière intervention 4 mars 2013130 7 mars 2008 à 18:35
Salut,
Si tu nous disais au moins où est-ce que tu as ton erreur, ca nous éviterais de devoir debugguer tout ton code !
______________________________________
DarK Sidious
mimi1255
Messages postés80Date d'inscriptionmardi 22 janvier 2008StatutMembreDernière intervention15 février 2022 10 mars 2008 à 20:45
j'ai cette erreur là qui me pose problème:
C:\Documents and Settings\Jérémy GRESLON\Bureau\projet\Camera_Test\src\Test\AxisCamera.java:153: cannot find symbol
symbol : method getContentPane()
location: class Test.AxisCamera
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());