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

» JWorld@TW » Java SE 討論區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友   
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 Re:圖片顯示的問題 [Re:ChiHua]
atticcat

There is no cookie



發文: 702
積分: 4
於 2005-10-28 19:57 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
import java.awt.Frame;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.URL;
 
import javax.swing.ImageIcon;
import javax.swing.JLabel;
 
public class Picture extends Frame
{
    JLabel PictureLabel = new JLabel("顯示圖片", JLabel.CENTER);
 
    PictureChangeThread driver = new PictureChangeThread();
 
    public Picture() {
        super("顯示圖片");
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent we) {
                System.exit(0);
            }
        });
        initialize();
    }
 
    private void initialize() {
        setSize(250, 300);
        setLayout(null);
        PictureLabel.setBounds(0, 10, 250, 300);
        add(PictureLabel);
        setVisible(true);
        driver.start();
    }
 
    public static void main(String args[]) {
        new Picture();
    }
 
    class PictureChangeThread extends Thread
    {
        public void run() {
            while (true) {
 
                try {
                    URL imageURL = new URL("http://www.tsmc.com/img/img_title_a.jpg");
                    InputStream content = (InputStream) imageURL.openStream();
                    ByteArrayOutputStream baos = new ByteArrayOutputStream(50000);
                    byte[] buf = new byte[10000];
                    int n = 0;
                    while ((n = content.read(buf)) != -1)
                        baos.write(buf, 0, n);
                    content.close();
                    Image img = (Image) Toolkit.getDefaultToolkit().createImage(baos.toByteArray());
                    /*Graphics2D g = (Graphics2D) PictureLabel.getGraphics();
                    g.scale((double) 250 / 375, (double) 300 / 86);
                    g.drawImage(img, 0, 0, 250, 300, PictureLabel);*/
                    PictureLabel.setIcon(new ImageIcon(img));
                    
                    baos.close();
                    Thread.sleep(1000);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
 

while(true)是為了作動畫嗎?


reply to postreply to post
話題樹型展開
人氣 標題 作者 字數 發文時間
1978 圖片顯示的問題 ChiHua 1948 2005-10-27 22:56
1314 Re:圖片顯示的問題 atticcat 2321 2005-10-28 19:57
1325 Re:圖片顯示的問題 ChiHua 2170 2005-10-28 22:25
1303 Re:圖片顯示的問題 Duncan 1997 2005-10-29 00:22
1277 Re:圖片顯示的問題 ChiHua 7 2005-10-29 07:32
» JWorld@TW »  Java SE 討論區

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

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8