JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java 新手區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
作者 誰能幫看 為什麼會錯在getContentPane 幫指點
mb773016





發文: 80
積分: 0
於 2009-05-17 14:07 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
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
286
287
288
289
290
291
292
import java.io.*;
//import java.lang.*;
import java.util.*;
import javax.media.*;
import javax.media.util.*;
import javax.media.control.*;
import javax.media.format.*;
import javax.media.protocol.*;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
 
import jp.sourceforge.qrcode.example.*;//***
 
import java.io.*;
 
import java.net.URL;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.imageio.*;
import jp.sourceforge.qrcode.*;
import jp.sourceforge.qrcode.data.QRCodeImage;
import jp.sourceforge.qrcode.exception.DecodingFailedException;
import jp.sourceforge.qrcode.util.*;
 
import jp.sourceforge.qrcode.geom.Line;
import jp.sourceforge.qrcode.geom.Point;
 
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;//***
import jp.sourceforge.qrcode.example.QRCodeDecoderGUIExample.J2SEImage;
import java.awt.Container;
 
public class webcamCapture extends Frame
{
  private final String JPGfileName="0000";
 
  private BufferedImage imageOrg;
  private BufferedImage imageExe;
  private BufferedImage photo;
  private FrameGrabber webcam;
  private int threshold = 200;
  private Color on = Color.white;
  private Color off = Color.black;
    public   QRCodeDecoderGUIExample QRCodeDecoderGUIExample;//***
    public JLabel sourceImageLabel;//**
    public J2SEDebugCanvas canvas;//** 
    public JTextArea decodedText; //***
  private difference diffImage;
  public  J2SEImage J2SEImage;//***
  public webcamCapture(String[] args) //****
  {
 
    decodevideo(imageOrg);//***
  }//***
  public static void main(String[] args)
  {
    new webcamCapture();
  //  new QRCodeDecoderGUIExample(args);
 
    
  }
  public String decodevideo(BufferedImage g) {
    
      if (sourceImageLabel != null)
        getContentPane().remove(sourceImageLabel);
      //½T»{¦pªG sourceImageLabel ¨S¦³°Ñ¦Ò¨ìª«¥ó(JLabel)¡A¦³ªº¸Ü§â¥¦²¾°£
 
    /*±NŪ¤Jªº¹ÏÀɫإ߬° ImageIcon ª«¥ó¡A¦A¥H ImageIcon ª«¥ó«Ø¥ßJLabel ª«¥ó
    ³Ì«á¦A©ñ¤JsourceImageLabel ÅܼÆ*/
      sourceImageLabel = new JLabel(new ImageIcon(imageOrg));
      getContentPane().add(sourceImageLabel, BorderLayout.EAST);
      //BorderLayout.EAST«h¬O¦bLayout¤W§âsourceImageLabel©ñ¦bªF¤è°Ï¶ô¡C
 
      QRCodeDecoder dd = new QRCodeDecoder();
      
 
      if (canvas != null) {
        getContentPane().remove(canvas);
      ////½T»{ canvas ¨S¦³°Ñ¦Ò¨ìª«¥ó(J2SEDebugCanvas)¡A¦³ªº¸Ü§â¥¦²¾°£
      }
      
      canvas = new J2SEDebugCanvas();
      //QRCodeDecoder.setCanvas(canvas);
      //«Ø¥ß J2SEDebugCanvas ª«¥ó¡A¦A¥æ¥Ñ QRCodeDecoder Ãþ§O
      getContentPane().add(canvas, BorderLayout.EAST);
      //Layout«á¥X¨Ó§âCanvas©ñ¦b¥kÃä°Ï¶ô¡C
      
      String decodedString = null;
      try {
        byte[] decodedBytes = dd.decode(new J2SEImage(g));
        decodedString = new String(decodedBytes);
      } catch (Exception e) {
       e.printStackTrace();
 
      } 
      decodedString = ContentConverter.convert(decodedString);
      canvas.println("\nDecode result:"); 
      canvas.println(decodedString);
      canvas.println("--------");
      if (decodedText != null)
        getContentPane().remove(decodedText);
      decodedText = new JTextArea(decodedString);
      decodedText.setLineWrap(true);//³]¸m¬° true¡A«h·í¦æªºªø«×¤j©ó©Ò¤À¬£ªº¼e«×®É¡A±N´«¦æ
      decodedText.setRows(decodedString.length() / 20 + 1);//³]¸m¦¹ TextArea ªº¦æ¼Æ
      if (decodedString.length() < 20)
        decodedText.setColumns(decodedString.length());//³]¸m¦¹ TextArea ¤¤ªº¦C¼Æ
      else
        decodedText.setColumns(20);
      //decodedText.setSize(sourceImageLabel.getSize().width,100);
      getContentPane().add(decodedText, BorderLayout.SOUTH);
 
      pack();
      return decodedString;  
      
    }
//*********************************************************************************  
  class J2SEDebugCanvas extends Canvas implements DebugCanvas {
    BufferedImage image;
 
    public void paint(Graphics g){
      if (image != null)
        g.drawImage(image, 0, 0, java.awt.Color.WHITE, null);
      
    }
    
    public  void println(String string){
      System.out.println(string);
    }
    
    public  void drawMatrix(boolean[][] matrix) {
      if (image == null) {
        image = new BufferedImage(matrix.length, matrix[0].length, BufferedImage.TYPE_INT_ARGB);
        setSize(matrix.length, matrix[0].length);
      }
      Graphics2D g2d = image.createGraphics();
      g2d.setColor(java.awt.Color.WHITE);
      int width = getWidth();
      for (int x = 0; x < matrix.length; x++) {
        g2d.drawLine(x, 0, x, width);
      }
      g2d.setColor(java.awt.Color.BLACK);
      for (int x = 0; x < matrix.length; x++) {
        for (int y = 0; y < matrix[0].length; y++) {
          if (matrix[x][y] == true)
            g2d.drawLine(x, y, x, y);
        }
      }
      repaint();
    }
 
    public  void drawLine(Line line, int color){
      Graphics2D g2d = image.createGraphics();
      g2d.setColor(new Color(color));
      g2d.drawLine(line.getP1().getX(), line.getP1().getY(),
            line.getP2().getX(), line.getP2().getY());
      repaint();
    }
 
    public  void drawLines(Line[] lines, int color){
      Graphics2D g2d = image.createGraphics();
      g2d.setColor(new Color(color));
      for (int i = 0; i < lines.length; i++) {
        g2d.drawLine(lines[i].getP1().getX(), lines[i].getP1().getY(),
            lines[i].getP2().getX(), lines[i].getP2().getY());
      }
      repaint();
    }
    
    public  void drawPolygon(Point[] points, int color){
      Graphics2D g2d = image.createGraphics();
      g2d.setColor(new Color(color));
      int numPoints = points.length;
      int[] polygonX = new int[numPoints];
      int[] polygonY = new int[numPoints];
      for (int i = 0; i < numPoints; i++) {
        polygonX[i] = points[i].getX();
        polygonY[i] = points[i].getY();
      }
      g2d.drawPolygon(polygonX, polygonY, numPoints);
      repaint();
    }
 
    public  void drawPoints(Point[] points, int color){
      Graphics2D g2d = image.createGraphics();
      g2d.setColor(new Color(color));
      for (int i = 0; i < points.length; i++)
        g2d.drawLine(points[i].getX(), points[i].getY(),points[i].getX(), points[i].getY());
      repaint();
 
    }
 
    public  void drawPoint(Point point, int color){
      Graphics2D g2d = image.createGraphics();
      g2d.setColor(new Color(color));
      g2d.drawLine(point.getX(), point.getY(),point.getX(), point.getY());
      repaint();
 
    }
 
    public  void drawCross(Point point, int color){
      int x = point.getX();
      int y = point.getY();
 
      Line[] lines = {
        new Line(x - 5, y, x + 5, y),new Line(x, y - 5, x ,y + 5)
      };
      drawLines(lines, color);
    }
    public BufferedImage getImage() {
      return image;
    }
    public void setImage(BufferedImage image) {
      this.image = image;
    }
  }
//*********************************************************************************  
  public webcamCapture()
  {
    addWindowListener(new WindowListener());
    setTitle("Webcam Capture");
 
    webcam = new FrameGrabber();
    webcam.start();
 
    imageOrg = webcam.getBufferedImage();
    
    
    setSize(imageOrg.getWidth(this)+8,imageOrg.getHeight(this)+34);
    setLocation(500,200);    //��X�{��m
    setVisible(true);
    setBackground(Color.white);
//    difference diffImage=new difference(imageOrg);
    diffImage=new difference(imageOrg);
 
//    getContentPane().setLayout(null);
 
//    show();
 
    while(true)
    {
      imageOrg = webcam.getBufferedImage();
//      diffImage.doProcess(imageOrg);
      imageExe=diffImage.doProcess(imageOrg);
      
      //string des = decodeVideo(imageOrg);
      
      repaint();
 
      if(diffImage.movementWarning(5))
      {
        fileSave save=new fileSave(imageOrg);
      }
 
      try
      {
        Thread.sleep(50);
      } catch(Exception e)
      {
        System.out.println("Error");
      }
    }
  }
 
  public void update(Graphics g)
  {
    if (imageExe != null)
    {
      g.drawImage(imageExe,4,30,this);
 
    }
  }
 
  class WindowListener extends WindowAdapter
  {
    public void windowClosing(WindowEvent e)
    {
      System.exit(0);
    }
  }
 
}
 


75 89 97 123 行的 getContentPane 顯下方顯示紅線 有錯 請大大幫指點 我也有import 幫指點


reply to postreply to post
作者 Re:誰能幫看 為什麼會錯在getContentPane 幫指點 [Re:mb773016]
keung2640





發文: 19
積分: 0
於 2009-05-18 10:01 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
public class webcamCapture extends JFrame?

reply to postreply to post
» JWorld@TW »  Java 新手區

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8