+ 5

Can anyone help?

I wanted to create an app that at start displays a green circle in which hello is written then for every 0.1 seconds draws a circle of random size and position. things go well till the green circle with hello but it doesn't draws any circles. Please see my code and tell what to do? I am newbie to android, who has started just two days ago.

27th Mar 2017, 8:18 AM
Prabhakar Dev
Prabhakar Dev - avatar
3 odpowiedzi
+ 5
package com.mycompany.myappcanvas; import android.app.*; import android.os.*; import android.view.*; import android.content.*; import android.graphics.*; import android.widget.*; import java.util.*; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); DemoView d=new DemoView(this); setContentView(d); } private class DemoView extends View{ public DemoView(Context c){ super(c); } @Override protected void onDraw(Canvas ca){ super.onDraw(ca); Paint p= new Paint(); p.setStyle(Paint.Style.FILL); p.setColor(Color.BLACK); ca.drawPaint(p); p.setAntiAlias(true); p.setColor(Color.GREEN); ca.drawCircle(200,200,105,p); p.setColor(Color.WHITE); ca.drawText("Hello",200,200,p); Timer t=new Timer(); Xfdr x=new Xfdr(ca,p); long n=100; t.schedule(x,n); } private class Xfdr extends TimerTask { Canvas cnx; Paint px; public Xfdr(Canvas cn,Paint p1){ this.cnx=cn; this.px=p1; } public void run(){ cnx.drawCircle(((float)Math.round(Math.random()*450)),((float)Math.round(Math.random()*450)),((float)Math.round(Math.random()*450)),px); } } } }
27th Mar 2017, 8:18 AM
Prabhakar Dev
Prabhakar Dev - avatar
+ 5
@Conrad java Please try only modifying my code below
27th Mar 2017, 8:59 AM
Prabhakar Dev
Prabhakar Dev - avatar
0
du u want to use java on the circle or xml
27th Mar 2017, 8:31 AM
Azim Conrad Wawire
Azim Conrad Wawire - avatar