1 16 package net.sf.jftp.gui.tasks; 17 18 import net.sf.jftp.config.Settings; 19 import net.sf.jftp.gui.*; 20 import net.sf.jftp.gui.framework.*; 21 import net.sf.jftp.util.*; 22 23 import java.awt.*; 24 25 import java.io.*; 26 27 import java.net.*; 28 29 import java.util.*; 30 31 import javax.swing.*; 32 33 34 public class ImageViewer extends JInternalFrame 35 { 36 public ImageViewer(String img) 37 { 38 super(img, true, true, true, true); 39 setLocation(150, 50); 40 setSize(400, 300); 41 42 setLayout(new BorderLayout(2, 2)); 43 44 ImagePanel p = new ImagePanel(img); 45 JScrollPane scroll = new JScrollPane(p); 46 47 getContentPane().add("Center", scroll); 48 49 p.setMinimumSize(new Dimension(1500, 1500)); 50 p.setPreferredSize(new Dimension(1500, 1500)); 51 p.setMaximumSize(new Dimension(1500, 1500)); 52 53 setVisible(true); 54 55 } 60 } 61 62 63 class ImagePanel extends JPanel 64 { 65 private Image img; 66 67 public ImagePanel(String url) 68 { 69 try 70 { 71 setBackground(Color.white); 72 73 img = Toolkit.getDefaultToolkit().getImage(new URL(url)); 74 75 MediaTracker mt = new MediaTracker(this); 76 mt.addImage(img, 1); 77 mt.waitForAll(); 78 79 repaint(); 82 83 } 85 catch(Exception ex) 86 { 87 ex.printStackTrace(); 88 } 89 } 90 91 public void paintComponent(Graphics g) 92 { 93 g.setColor(Color.white); 94 g.fillRect(0, 0, 1500, 1500); 95 g.drawImage(img, 0, 0, null); 96 } 97 98 public void update(Graphics g) 99 { 100 paintComponent(g); 101 } 102 } 103 | Popular Tags |