Eclipse Jpanel无法显示颜色 20
下面是源码,制作了一个简单的动画,但是结果只有一个Frame显示,什么都没有[如图所示]。请高手解答importjavax.swing.*;importjava.awt....
下面是源码,制作了一个简单的动画,但是结果只有一个Frame显示,什么都没有[如图所示]。请高手解答
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class animation {
int x=70;
int y=70;
public static void main(String args[])
{
animation gui=new animation();
gui.go();
}
public void go()
{
JFrame frame=new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
MyDrawPanel drawpanel=new MyDrawPanel();
frame.getContentPane().add(drawpanel);
frame.setSize(300, 300);
frame.setVisible(true);
for(int i=0;i<130;i++)
{
x++;
y++;
drawpanel.repaint();
try{
Thread.sleep(50);
}
catch(Exception ex){
}
}
}
class MyDrawPanel extends JPanel
{
public void paintCompanent(Graphics g)
{
super.paintComponent(g);
g.setColor(Color.green);
g.fillOval(x,y,40,40);
}
}
} 展开
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class animation {
int x=70;
int y=70;
public static void main(String args[])
{
animation gui=new animation();
gui.go();
}
public void go()
{
JFrame frame=new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
MyDrawPanel drawpanel=new MyDrawPanel();
frame.getContentPane().add(drawpanel);
frame.setSize(300, 300);
frame.setVisible(true);
for(int i=0;i<130;i++)
{
x++;
y++;
drawpanel.repaint();
try{
Thread.sleep(50);
}
catch(Exception ex){
}
}
}
class MyDrawPanel extends JPanel
{
public void paintCompanent(Graphics g)
{
super.paintComponent(g);
g.setColor(Color.green);
g.fillOval(x,y,40,40);
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询