0

I have these functions that display a group of chairs, seated and empty, that changes in order every 2 minutes, however, every time I call removeSeats() and then displaySeats(), all the seat components seem to disappear, but I know they're their because I have another function that views the information each chair has.

private void removeSeats(){ for(int i = 0; i < c.getClassroom().size(); i++) pnlGame.remove(c.getClassroom().get(i).getSprite()); for(int i = 0; i < emptySeats.size(); i++) pnlGame.remove(emptySeats.get(i).getSprite()); pnlGame.repaint(); } private void displaySeats(){ // GAME SCREEN (pnlGame) Components emptySeats = new ArrayList<Sprite>(); Sprite temp; int x = 25, y = 70, xS = 0, yS = 0, eI = 0, cI = 0; for(int i = 0; i < 64; i++){ if(i % 8 == 0 && i != 0){ x = 25; y += 80; } temp = new Sprite(); temp.setName("Empty Seat"); temp.getSprite().setBorder(BorderFactory.createLineBorder(Color.black)); temp.setSprite(new JLabel(new ImageIcon("src\\seat.png"))); temp.setOrigin(x, y); temp.setDimensions(40, 60); if(c.search(xS, yS) != null){ if(c.getClassroom().get(cI).isPresent()){ c.getClassroom().get(cI).getSprite().setBorder(BorderFactory.createLineBorder(Color.white)); c.getClassroom().get(cI).setOrigin(x, y); c.getClassroom().get(cI).setDimensions(40, 60); pnlGame.add(c.getClassroom().get(cI).getSprite()); }else{ emptySeats.add(temp); pnlGame.add(emptySeats.get(eI).getSprite()); eI++; } cI++; }else{ emptySeats.add(temp); pnlGame.paintComponents(temp.getSprite().getGraphics()); pnlGame.add(emptySeats.get(eI).getSprite()); eI++; } xS++; if(xS >= 8){ xS = 0; yS++; } x += 80; } pnlGame.revalidate(); } 
0

1 Answer 1

0

I think that you need add this line in your removeSeats method.

pnlGame.revalidate(); pnlGame.repaint(); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.