mirror of
https://github.com/jokerx3/HeatUp
synced 2026-07-27 09:49:45 +02:00
78 lines
1.8 KiB
Java
78 lines
1.8 KiB
Java
package de.heatup.objects;
|
|
|
|
import java.awt.BasicStroke;
|
|
import java.awt.Graphics;
|
|
import java.awt.Graphics2D;
|
|
import java.awt.RenderingHints;
|
|
import java.awt.image.BufferedImage;
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
|
|
import javax.imageio.ImageIO;
|
|
import javax.swing.JComponent;
|
|
|
|
/*
|
|
* Draft for dynamic objects
|
|
*/
|
|
public class DynamicObject extends JComponent{
|
|
private static final long serialVersionUID = 1L;
|
|
//private Image image;
|
|
private BufferedImage bf1;
|
|
private Graphics2D g2d;
|
|
|
|
private boolean doRescale = false;
|
|
private double rescaleFactorX = 0.0;
|
|
private double rescaleFactorY = 0.0;
|
|
|
|
public DynamicObject() {
|
|
}
|
|
|
|
public void paintComponent(Graphics g) {
|
|
g2d = (Graphics2D)g;
|
|
//this.image = Toolkit.getDefaultToolkit().getImage("src/de/heatup/resources/images/little_green_guy.png");
|
|
if ( bf1 == null ) {
|
|
loadBufferedImage();
|
|
}
|
|
|
|
//g2d.rotate(0.3, 10, 10);
|
|
if ( doRescale ) {
|
|
g2d.scale(rescaleFactorX, rescaleFactorY);
|
|
}
|
|
|
|
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
|
|
g2d.drawImage(bf1, 0, 0, this);
|
|
g2d.setStroke(new BasicStroke(8.0f));
|
|
g2d.finalize();
|
|
}
|
|
|
|
private void loadBufferedImage() {
|
|
try {
|
|
this.bf1 = ImageIO.read(new File("src/de/heatup/resources/images/little_green_guy.png"));
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
public void setImage(BufferedImage image) {
|
|
this.bf1 = image;
|
|
}
|
|
|
|
public void setRescale(double rescaleFactorX, double rescaleFactorY) {
|
|
this.rescaleFactorX = rescaleFactorX;
|
|
this.rescaleFactorY = rescaleFactorY;
|
|
this.doRescale = true;
|
|
}
|
|
|
|
public void unsetRescale() {
|
|
this.rescaleFactorX = 0.0;
|
|
this.rescaleFactorY = 0.0;
|
|
this.doRescale = false;
|
|
}
|
|
|
|
public void setAutoBounds(int x, int y) {
|
|
this.setBounds(x, y, this.bf1.getWidth(), this.bf1.getHeight());
|
|
}
|
|
|
|
|
|
}
|