I created a class which is a "mirror" object. The class constructor has mirrors coordinates and direction. In this class also there is a paintComponent
method. I am trying to create a mirror object with this class in my frame and automatically paint a mirror with coordinates and direction. There is the "mirror" class. Can I do this like that?
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
@SuppressWarnings("serial")
class Mirror extends JComponent{
public static int xm, ym;
public static boolean direction;
public Mirror(int xmm, int ymm, boolean directionm){
xm=xmm;
ym=ymm;
direction=directionm;;
repaint();
}
public int getX(){
return xm;
}
public int getY(){
return ym;
}
public boolean getDirection(){
return direction;
}
public int getIntDirection(){
int a;
if(direction==true){
a=1;
}else{
a=0;
}
return a;
}
public void setDirection(boolean status){
direction=status;
}
@Override
public void paintComponent(Graphics g){
super.paintComponent(g);
switch(getIntDirection()){
case 0: ImageIcon mirrorr = new ImageIcon("imagess/mirrorrigt.jpg");
Image mirrorrImage = mirrorr.getImage();
g.drawImage(mirrorrImage,xm,ym,null);
break;
case 1: ImageIcon mirrorl = new ImageIcon("imagess/mirrorleft.jpg");
Image mirrorlImage = mirrorl.getImage();
g.drawImage(mirrorlImage,xm,ym,null);
break;
}
}
}