求大神解答 是repaint方法没有调用吗
java吧
全部回复
仅看楼主
level 2
冲锋之岛 楼主
程序是显示文字并且可以通过一直按着鼠标的方法移动文字的位置,就是文字总是出现在鼠标的位置,但是不知道为什么实际运行却不能移动,是不是repaint方法没有被调用还是怎么的啊,求大神帮忙解答一下,谢谢。程序代码见二楼
2014年09月12日 10点09分 1
level 2
冲锋之岛 楼主
public class demo9 extends JFrame{
public demo9(){
JPanel panel = new newpanel("ni hao");
setLayout(new BorderLayout());
add(panel);
}
public static void main(String[] args){
demo9 frame = new demo9();
frame.setTitle("demo9");
frame.setSize(200,200);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
static class newpanel extends JPanel{
private String message = "ni hao";
private int x = 20;
private int y = 20;
public newpanel(String s){
addMouseMotionListener(new MouseMotionAdapter(){
public void MouseDragged(MouseEvent e){
x = e.getX();
y = e.getY();
repaint();
}
});
}
public void paint(Graphics g){
super.paint(g);
g.drawString(message,x ,y);
}
}
}
2014年09月12日 10点09分 2
level 2
冲锋之岛 楼主
大神来留个脚印可好[汗][汗]
2014年09月12日 12点09分 3
level 11
没用过[惆怅~]
2014年09月12日 12点09分 4
level 11
没用过[咦]
2014年09月12日 12点09分 5
level 11
不好意思 没有用过·····帮你顶一顶,,亲 可以粉我吗
2014年09月12日 12点09分 6
level 8
应该自动调用吧
2014年09月12日 12点09分 7
1