Hi, I’ve split logic from drawing ;D with controller view model.
so in the class of my JPanel ControlPanel
I have
Game_Interface :
LEFT_MARGIN = 10;
CONTROL_PANEL_WEIGHT = 250;
PANEL_HEIGHT = 150;
public class ControlPanel extends JPanel implements Game_Interface {
protected void paintComponent(Graphics g) {
// paint frame contents first...
super.paintComponent(g);
// then, make sure lightweight children paint
g.drawString("Next Piece:", LEFT_MARGIN,18);
g.drawString("Move with the ArrowKeys", LEFT_MARGIN, 300);
g.drawString("Drop: Down ArrowKey", LEFT_MARGIN, 320);
g.drawString("Glide: Spacebar", LEFT_MARGIN, 340);
g.drawString("Pauze: P", LEFT_MARGIN, 360);
}
public Dimension getPreferredSize() {
return new Dimension(CONTROL_PANEL_WEIGHT, PANEL_HEIGHT);
}
and the problem occurs here:
public void draw_Score(int score, Graphics2D g) {
g.setColor(Color.BLACK);
repaint(LEFT_MARGIN, 150,150,80);
g.drawString("Score: " + score, LEFT_MARGIN, 150);
}
- I’m trying to repaint (erase to default background) a pixel rectangle
- draw a text (the score)
at the moment the second score overlaps the first score. It’s Ignoring my repaint request!
I alsoo would like to add the draw_Score into the paintComponent BUT then i need to store the score and the JPanel shouldn’t know what the score is?
I’m thinking/ Doing something wrong?


