import java.awt.*;import javax.swing.*;
public class CreatBall extends JPanel {
public static Balls ball[];
int x,y,radius;
Color c;
public static void main(String args[]){
JFrame f = new JFrame("ceshi");
f.add(new CreatBall());
f.setSize(300,200);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
public CreatBall(){
super();
ball[0] = new Balls(10,10,20,Color.black);
ball[1] = new Balls(40,40,20,Color.blue);
}
public void paint(Graphics g){
super.paint(g);
this.drawBall(x, y, radius, g, c);
}
public void drawBall(int x,int y,int radius,Graphics g,Color c){
for(int i = 0;i<=1;i++){
g.setColor(ball[i].getColor());
g.fillOval(ball[i].getX(), ball[i].getY(), ball[i].getRadius(), ball[i].getRadius());
}
}
}
import java.awt.*;
import javax.swing.*;
public class Balls {
private int x,y,radius;
private Color color;
Balls(int x,int y,int radius,Color color){
this.x = x;
this.y = y;
this.radius = radius;
this.color = color;
}
public int getX(){
return x;
}
public int getY(){
return y;
}
public int getRadius(){
return radius;
}
public Color getColor(){
return color;
}
}
为什么无法运行啊。。。。。
还是无法运行啊。。你的代码
追答不太清楚你原来的配置,试试多调试,多看看java基础。
本回答被提问者采纳