Try using something like this:
package game.balance;
import android.app.Activity;
import android.os.Bundle;
public class Balance extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new Ball(this, 10, 10, 30));
}
}
package game.balance;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.view.View;
public class Ball extends View {
private final float x;
private final float y;
private final int r;
private final Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
public Ball(Context context, float x, float y, int r) {
super(context);
mPaint.setColor(0xFFFF0000);
this.x = x;
this.y = y;
this.r = r;
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawCircle(x, y, r, mPaint);
}
}
On Jun 9, 7:24 pm, patpat <[email protected]> wrote:
> I am new and here is my code.. when i ran it ...there was nothing...i
> expected there should be a circle appear..
> can anyone tell me why??
>
> package game.balance;
>
> import android.app.Activity;
> import android.os.Bundle;
> import android.view.ViewGroup.LayoutParams;
> import android.widget.LinearLayout;
>
> public class theGame extends Activity {
> /** Called when the activity is first created. */
> @Override
> public void onCreate(Bundle savedInstanceState) {
> super.onCreate(savedInstanceState);
> LinearLayout mLinearLayout = new LinearLayout(this);
> Ball mBall = new Ball(this,10,10,30);
> setContentView(mLinearLayout);
> }
>
> }
>
> package game.balance;
>
> import android.content.Context;
> import android.graphics.Canvas;
> import android.graphics.Paint;
> import android.view.View;
>
> public class Ball extends View{
>
> public Ball(Context context,float x,float y,int r) {
> super(context);
> // TODO Auto-generated constructor stub
> Paint mPaint = new Paint();
> mPaint.setColor(0xFF0000);
> Canvas mCanvas = new Canvas();
> mCanvas.drawCircle(x,y,r,mPaint);
>
> }
>
>
>
> }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---