So I have this code:
Java Code:
package com.cjburkey.games.war.g;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
import com.cjburkey.games.war.Card;
public class GamePanel extends JPanel {
private static final long serialVersionUID = 4043466625982871282L;
/////----------\\\\\
BufferedImage topCard = null;
BufferedImage pickedCard = null;
BufferedImage computCard = null;
Point click;
int topCardx = 200;
int topCardy = 117;
int topCardWidth = 81;
int topCardHeight = 117;
Rectangle clickPoint = new Rectangle(topCardx, topCardy, topCardWidth, topCardHeight);
public GamePanel() {
try {
topCard = ImageIO.read(new File("img/Cards/top-card.png"));
} catch (IOException e) {
e.printStackTrace();
}
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
this.setBackground(new Color(232, 223, 174));
g.setColor(Color.BLUE);
g.drawImage(topCard, topCardx, topCardy, topCardWidth, topCardHeight, null);
g.drawImage(computCard, 50, 10, 81, 117, null);
g.drawImage(pickedCard, 50, 227, 81, 117, null);
System.out.println("Thang");
}
private void getCard() {
System.out.println("Java: getCard();");
Card yourCard = new Card();
Card compCard = new Card();
pickedCard = yourCard.getImage();
computCard = compCard.getImage();
repaint();
}
public void click(int x, int y) {
click = new Point(x, y);
if(clickPoint.contains(click)) {
System.out.println("Contains");
getCard();
}
}
}
Why is paintComponent not being called by repaint();?
Also, paintComponent is called twice when the program starts, that works, repaint is the thing that doesn't work.
No comments:
Post a Comment