I am trying to get pictures to appear on a JPanel and have previously tried using JLabels but that didn't work so now I am trying to use the paintComponent method. My code consists of making a window with a frame and adding a JPanel to the frame. Then in my actionPerformed method called by using a timer calls repaint I don't receive output from the System.out.println method. Any way I can get this working?
public void createWindow(){
frame.add(panel);
frame.addComponentListener(this);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.pack();
frame.setSize(xSize, ySize);
frame.setLocation(0, 0);
}
@Override
public void paintComponent(Graphics g) {
System.out.println("Method Called");
super.paintComponent(g);
g.drawString("Code has painted", 10, 100);
}