Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think The <code>repaint()</code> in your <code>paintComponent()</code> code causes an endless recursion.</p> <p>repaint --> paintComponent --> repaint -->...</p> <p>This is messing up the Graphics object.</p> <p><strong>edit:</strong></p> <p>There is another error in your code, your calling super.paintComponent <strong>s</strong> (g) instead of <code>super.paintComponent(g)</code>. Try to use the method without the <strong>s</strong>.</p> <p>Here is a simple example of a class that moves the string according to the position of the last click:</p> <hr> <pre class="lang-java prettyprint-override"> public class Test extends JPanel implements MouseListener { private int x = 100; private int y = 100; public static void main(String[] args) { JFrame jFrame = new JFrame(); Test test = new Test(); jFrame.add(test); jFrame.setBounds(0, 0, 800, 600); jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jFrame.setVisible(true); jFrame.addMouseListener(test); } @Override public void paintComponent(Graphics g) { super.paintComponent(g); g.drawString("blub", x, y); } @Override public void mouseClicked(MouseEvent e) { this.x = e.getX(); this.y = e.getY(); repaint(); } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseEntered(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseExited(MouseEvent e) { // TODO Auto-generated method stub } } </pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload