Join 132,603 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 936 people online right now. Registration is fast and FREE... Join Now!
// paint background super.paintComponent(g); //Draw image at its natural size g.drawImage(image, 0, 0, this); //85x62 image
}
As you say yourself in the comments you draw it "at its natural size" so if if does not fit in the panel it will be truncated If you want to resize the image to fit you'll have to use
One more question is there a way to do the read with a while loop to make sure it's all there.
Would be easier with a JLabel... they you just create a ImageIcon and the coinstructor of ImageIcon(URL) will returned only when to read is complete. No neeed to use ToolKit and ImageIO.read();
The picture is cut off abnormally. There is a place for the picture to fit but the picture is unfinished. Like it didn't finish downloading. Is there a way to make sure that the whole picture is transferred.
The picture is cut off abnormally. There is a place for the picture to fit but the picture is unfinished. Like it didn't finish downloading. Is there a way to make sure that the whole picture is transferred.
MediaTracker should do that... thsi why it was created Did you try to System.out.println("Error: " + e); in your catch() statements ? Did you try to resize() your Applet so see if a second repaint() does the job ? You should also test isErrorAny() on the meia tracker.
This post has been edited by pbl: 30 Jun, 2008 - 10:58 AM
InputStream in = url.openStream(); BufferedReader bf = new BufferedReader(new InputStreamReader(in)); strBuff = new StringBuffer(); while((line = bf.readLine()) != null){ strBuff.append(line + "\n"); } System.out.println(strBuff.toString()); txtArea.append(strBuff.toString()); } catch(IOException e){ e.printStackTrace(); }
// --------------------------------------------------------------------- // Now get the Image (graphic) from the given URL // --------------------------------------------------------------------- try { url2 = new URL("xxxxxxxxxxxxxxxxxxxxxxx");
// --------------------------------------------------------------------- // Finally create a ImagePanel to display the image and exit button // ---------------------------------------------------------------------
ImagePanel i = new ImagePanel(image); txtArea.setSize(5, 5); contentPane.add(i, BorderLayout.CENTER); contentPane.add(exitButton, BorderLayout.SOUTH); contentPane.add(txtArea, BorderLayout.NORTH); i.setAlignmentY(JLabel.CENTER_ALIGNMENT); repaint(); // ------------------------------------------------------------ // Window listener to close application when Window gets closed // ------------------------------------------------------------
};
/** * The action listener for user events like buttons. * @param ae Event that was performed by the user */ public void actionPerformed(ActionEvent ae) {
I'm running it as an applet. What do I need in init()?
In a previous program I had to do something like this. Are there comparable commands for my situation.
CODE
InputStream in = new FileInputStream(files.elementAt(x)); OutputStream out = new FileOutputStream(temp2); byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } out.flush(); in.close(); out.close();
This post has been edited by nombre: 30 Jun, 2008 - 01:07 PM
I'm running it as an applet. What do I need in init()?
Applet don't have a constructor they have an init() method I replaced your constructor of applet() by void init() I remove the double creation of your JButton and it worked well
// --------------------------------------------------------------------- // Now get the Image (graphic) from the given URL // --------------------------------------------------------------------- try { url2 = new URL("http://www.pblinc.ca/images/pbl_bourse.jpg");
// --------------------------------------------------------------------- // Finally create a ImagePanel to display the image and exit button // ---------------------------------------------------------------------
ImagePanel i = new ImagePanel(image); // txtArea.setSize(5, 5); contentPane.add(i, BorderLayout.CENTER); contentPane.add(exitButton, BorderLayout.SOUTH); contentPane.add(new JScrollPane(txtArea), BorderLayout.NORTH); // i.setAlignmentY(JLabel.CENTER_ALIGNMENT); repaint(); // ------------------------------------------------------------ // Window listener to close application when Window gets closed // ------------------------------------------------------------
};
/** * The action listener for user events like buttons. * @param ae Event that was performed by the user */ public void actionPerformed(ActionEvent ae) {