Re: wants more options in choosing the name and type of image
On Jun 29, 10:41 am, "Andrew Thompson" <u32984@uwe> wrote:
bH wrote:
..
My present java programming practice ..
The current code snippet suggests you are in over
your head..*
... is to write a program that
specifies a folderlocation/fileName.jpg within the program, such as
"image/cak.jpg" inside the program.
A JFileChooser might be what you are after.
...Now I use ...
public ShoImage() {
this.setLayout(new BorderLayout());
imagePanel = new JPanel() {
protected void paintComponent(Graphics g) {
super.paintComponent(g);
ImageIcon myImage = new ImageIcon("image/cak.jpg");
g.drawImage(myImage.getImage(), 0, 0, Color.white,
(java.awt.image.ImageObserver) imagePanel);
}
};
this.add(imagePanel, BorderLayout.CENTER);
}
* That code is horrid. I cannot tell quite how horrid,
since it is not compilable, and the finer details are
not clear to me. If you post an SSCCE, I (or others)
might go through it step-by-step.
--
Andrew Thompsonhttp://www.athompson.info/andrew/
Message posted via JavaKB.comhttp://www.javakb.com/Uwe/Forums.aspx/java-setup/200706/1- Hide quoted text -
- Show quoted text -
My code example:
import javax.swing.*;
import java.awt.*;
import javax.swing.border.BevelBorder;
public class ImageOnPanel
extends JPanel {
private static final String title = "Image On Panel";
private static final int width = 510;
private static final int height = 330;
JPanel imagePanel = new JPanel();
// Constructor
public ImageOnPanel() {
this.setLayout(new BorderLayout());
imagePanel = new JPanel() {
protected void paintComponent(Graphics g) {
ImageIcon myImage = new ImageIcon("image/MSNButterfly.jpg");
super.paintComponent(g);
g.drawImage(myImage.getImage(), 0, 0, Color.white,
(java.awt.image.ImageObserver) imagePanel);
}
};
this.add(imagePanel, BorderLayout.CENTER);
// added this border stuff in 8/06/04
BevelBorder loweredBevelBorder =
(BevelBorder)BorderFactory.createLoweredBevelBorder();
this.setBorder(loweredBevelBorder);
}
public void showFrame() {
JFrame myFrame = new JFrame(title);
myFrame.getContentPane().add(this, BorderLayout.CENTER);
myFrame.pack();
myFrame.setSize(new Dimension(width, height));
myFrame.setVisible(true);
}
public static void main(String[] args) {
ImageOnPanel ImageOnPanel = new ImageOnPanel();
ImageOnPanel.showFrame();
}
}
bH