0

i have a Jframe.in order to paint it i not using paintComponent but ordinary function containing g.drawstring("sd",0,0).

when ever i click the mouse the string should appear at that point and it should move with the cursor until another click appears.

my problem after clicking the string is not appearing immediately it appears only after the mouse moves

iam calling paint method in both mouseclicked and mousemoved

anyone help me

Edited by jbalaji87: n/a

3
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by jbalaji87
0

Answer my question, if the mouse stops moving, text disappears?
if yes, you need use paintComponent method

0

Answer my question, if the mouse stops moving, text disappears?
if yes, you need use paintComponent method

when i click its not appearing but when mouse start to move text appear

0

addMouseListener(this);
addMouseMotionListener(this);
//
use repaint(); inside mouse methods

public class MyPanel extends JPanel implements MouseListener, MouseMotionListener {

    private Point p;

    public MyPanel() {
        super();
        p = new Point(0, 50);
        setBackground(Color.red);
        addMouseListener(this);
        addMouseMotionListener(this);
    }

    public void paint(Graphics g) {
        //super.paint(g); //UNCOMMENT THIS
        g.drawString("Error: Can't move!", p.x, p.y);
    }

    public void mousePressed(MouseEvent e) {
        p = e.getPoint();
        repaint();
    }
...

Edited by quuba: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.