java repaint()無效?
初學java,繪圖這里很搞不懂
package picture;import javax.swing.*; import java.awt.*;/*** Created by Smith on 2016/10/19.*/ public class Study extends JPanel{ public int x = 1; public int y = 1;public static void main(String [] args) { new Study().init(); }public void init() { JFrame jf = new JFrame("圖片"); JPanel jp = new JPanel(); jf.add(jp); jf.setSize(600,600); jf.setVisible(true); Graphics g = jp.getGraphics(); for(int i = 1;i<=500;i++) { paint(g); x++; y<愛尬聊_百科詞條>++; } System.out.println(g);}public void paint(Graphics g) { g.setColor(Color.blue); g.drawString("hello",x,y); repaint(); }}
生成的效果圖就是如上,我實際是想要hello進行移動,但repaint()放在這里為什么沒有效果