I am doing a project like a car gallery system and need to ask for help...
Suppose I want to create a class call "Brand", it is basically just to store the brand name, a brief description, and also need to give it a picture.
Says: Toyota, it is a Japanese car blah blah blah, then plus an image.
So inside the class, how do I store the attribute of Image?
I've wrote 2 separate class which is "Brand" + "LoadImage", how do I link them together? or possibly to combine them into a single class...
Here my code...
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import javax.swing.*;
public class LoadImage extends Component {
private static final long serialVersionUID = 1L;
BufferedImage img;
public void paint(Graphics g) {
g.drawImage(img, 0, 0, null);
}
public LoadImage() {
try {
img = ImageIO.read(new File("logo.png"));
} catch (IOException e) {
}
}
public Dimension getPreferredSize() {
if (img == null) {
return new Dimension(100, 100);
} else {
return new Dimension(img.getWidth(null), img.getHeight(null));
}
}
}
// public static void main(String[] args) {
//
// JFrame f = new JFrame("Load Image Sample");
//
// f.addWindowListener(new WindowAdapter() {
//
// @Override
// public void windowClosing(WindowEvent e) {
// System.exit(0);
// }
// });
//
// f.add(new LoadImage());
// f.pack();
// f.setVisible(true);
// }
//}
public class Brand {
private String brandName;
private String description;
// possible just do -> "LoadImage loadImg = new LoadImage()" ?
public Brand(String b, String d) {
setBrand(b);
setDescription(d);
// how to pass Image param to here also ?
}
public void setBrand(String b) {
brandName = b;
}
public String getBrand() {
return brandName;
}
public void setDescription(String d) {
description = d;
}
public String getDescription() {
return description;
}
}
Appreciate for any helps, thanks... =)