Cook book written in Java
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

85 lines
2.1 KiB

package db;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
public class Recipe {
private int id;
private String name;
private String ingredients;
private String description;
private String tags;
private ImageIcon img;
public int getId() {
return id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getIngredients() {
return ingredients;
}
public void setIngredients(String ingredients) {
this.ingredients = ingredients;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getTags() {
return tags;
}
public void setTags(String tags) {
this.tags = tags;
}
public ImageIcon getImage() {
return img;
}
public void setImage(ImageIcon img) {
this.img = img;
}
public byte[] getImageArr() {
try {
//przekształcam ImageIcon -> BufferedImage
BufferedImage bImg = new BufferedImage(img.getIconWidth(), img.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
bImg.getGraphics().drawImage(img.getImage(), 0,0, null);
ByteArrayOutputStream bStream = new ByteArrayOutputStream();
//Buffered Image -> Byte Stream
ImageIO.write( bImg, "png", bStream );
bStream.flush();
//Byte Stream -> Byte Array
byte [] arr = bStream.toByteArray();
bStream.close();
return arr;
}
catch (IOException e) {
System.err.println("Blad przy wstawianiu przepisu");
e.printStackTrace();
return null;
}
}
public Recipe() {}
public Recipe(int id, String name, String ingredients, String description, String tags, ImageIcon img) {
this.id = id;
this.name = name;
this.ingredients = ingredients;
this.description = description;
this.tags = tags;
this.img = img;
}
}