i'm trying create simple card class extends bufferedimage can draw card directly on screen. card has 2 faces. front, , back. including flip(boolean faceup) method want change image 1 side next, seems since class extends bufferedimage, it's final? i'm not sure, that's impression. doesn't change original image drawn in constructor. there way around can still paint card directly on-screen? have far...
public card(int rank, int suit) { super(50,70,type_int_argb); this.rank = rank; this.suit = suit; try{bi = imageio.read(getclass().getresource(tostring()+".png")); = imageio.read(getclass().getresource("back.png"));} catch(ioexception e){e.printstacktrace();} graphics2d g = creategraphics(); g.drawimage(back,0,0,null); g.dispose(); } public void flip(boolean faceup) { this.faceup = faceup; graphics2d g = creategraphics(); if(faceup)g.drawimage(bi,0,0,null); else g.drawimage(back,0,0,null); g.dispose(); }
don't extend bufferedimage.
instead class can contain 2 bufferedimages:
- the front
- the back
then painting method paint front or depending on "flip" property.
Comments
Post a Comment