Hi everyone. I wonder why the following code doesn't draw anything.
package AssProgLang;
import java.awt.*;
import javax.swing.*;
import java.util.*;
public class AssOutput extends JPanel {
public AssOutput(Queue translatedQueue) {
this.translatedQueue = translatedQueue;
outputFrame = new JFrame();
outputFrame.getContentPane().add(this);
// outputPanel attributes
outputFrame.setLocationRelativeTo(null);
outputFrame.setPreferredSize(new Dimension(640, 480));
//this.setPreferredSize(new Dimension(640, 480));
outputFrame.pack();
outputFrame.setTitle("ASS™ Output Window");
outputFrame.setResizable(false);
outputFrame.setVisible(true);
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
int functionNb, thingNb, attribNb;
while(translatedQueue.peek() != null) {
functionNb = (Integer)translatedQueue.poll();
thingNb = (Integer)translatedQueue.poll();
attribNb = (Integer)translatedQueue.poll();
switch(functionNb) {
case AssConsts.DISPLAY: // display
switch(thingNb) {
case AssConsts.DOT: // dot
switch(attribNb) {
case 0: color = Color.BLACK; break;
case 1: color = Color.BLUE; break;
case 2: color = Color.CYAN; break;
case 3: color = Color.DARK_GRAY; break;
case 4: color = Color.GRAY; break;
case 5: color = Color.GREEN; break;
case 6: color = Color.LIGHT_GRAY; break;
case 7: color = Color.MAGENTA; break;
case 8: color = Color.ORANGE; break;
case 9: color = Color.PINK; break;
case 10: color = Color.RED; break;
case 11: color = Color.WHITE; break;
case 12: color = Color.YELLOW; break;
} // end attribNb switch
} // end thingNb switch
g.setColor(color); // <-- doesn't draw here
g.fillRect(xpos, ypos, 5, 5); // <-- doesn't draw here
break; // end display case
case 2: // move
switch(thingNb) {
case 3: // cursor
switch(attribNb) {
case 16: xpos += 5; break;
case 17: xpos -= 5; break;
case 18: ypos -= 5; break;
case 19: ypos += 5; break;
}
} // end
break; // end move case
} // end functionNb switch
}
}
// field
private JFrame outputFrame;
private Color color = Color.BLACK;
private int xpos = 0, ypos = 0;
private Queue translatedQueue;
}
Please help me. Thank you.
There is a display when the
g.setColor(color); // <-- doesn't draw here
g.fillRect(xpos, ypos, 5, 5); // <-- doesn't draw here
are placed outside the while loop