Calling the methods in java

android

I know what it is the Calling the methods in java and before the question, I read about Java grammar very much.I know what it is the this in java, but I do not know, How is invoked the following code in MainActivity. java

public void onDraw(Canvas canvas) {
    paint.setColor(Color.BLUE);
    canvas.drawCircle(120,120,40,paint);
}

Now. I put the full code:

MainActivity.java

public class MainActivity extends Activity {
    Draw draw;
    Cal cal;
    TextView textView;
    RelativeLayout linearLayout;

    public void onCreate(Bundle s) {
        super.onCreate(s);
        setContentView(R.layout.activity_main);

        linearLayout = (RelativeLayout) findViewById(R.id.t);
        cal = new Cal(this);
        cal.cal();

        textView = new TextView(getApplicationContext());
        textView.setText("" + cal.result);
        textView.setTextColor(Color.RED);

        draw = new Draw(this);
        linearLayout.addView(textView);
        linearLayout.addView(draw);
    }
}

Cal.java

public class Cal extends View {
    Cal(Context context){
        super(context);
    }
    public double result;
    double parameter = (Math.pow(40,2)) * 3.14;
    public void cal(){
        result = Math.sqrt(parameter);

    }
}

Draw.java

public class Draw extends View {
Paint paint = new Paint();
    Draw(Context context) {
        super(context);
    }
    public void onDraw(Canvas canvas) {
        paint.setColor(Color.BLUE);
        canvas.drawCircle(120,120,40,paint);
    }
}

The public void cal(){ result = Math.sqrt(parameter);} is invoked by cal.cal(); in MainActivity But I do not know, How is invoked the

public void onDraw(Canvas canvas) {
    paint.setColor(Color.BLUE);
    canvas.drawCircle(120,120,40,paint);
}

in MainActivity.java ?? in MainActivity.java, we have only the draw = new Draw(this); for calling the Draw(Context context) {super(context);} in Draw.java

David SN

Your Draw class extends the android class View.

You are adding a view to your layout in the onCreateMethod():

linearLayout.addView(draw);

Android will call the onDraw() method in the draw object when the view is rendering.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

XPages - Calling Java methods

From Dev

Calling Java Methods in XSLT

From Java

Calling multiple methods in Java

From Java

Calling the methods in a class in Java

From Dev

Calling methods on objects Java

From Java

Calling methods on string literals (Java)

From Java

Calling methods of "parent" component in Java

From Java

Calling two Java methods asynchronously

From Dev

Calling Java methods with React locally

From Java

calling java methods in javascript code

From Dev

Calling methods in a Java Fx ActionEvent

From Dev

Generics in Java preventing calling of methods

From Dev

Calling methods for my java class

From Dev

Clojure: calling a sequence of methods on a Java object

From Java

Java: Printing triangles and spaces by calling methods

From Dev

Programatically calling all methods in a Java class

From Dev

Compiler error with calling Generic methods java

From Dev

Calling methods of a Java subclass using Jython

From Java

Calling Java Methods from Shell Scripts

From Dev

calling objects from other methods in java

From Dev

Using variables for creating objects and calling methods in Java

From Dev

Calling Methods In Java - Hello World Example

From Dev

Java FXML calling methods on button clicks

From Dev

How to print a christmas tree in Java, by calling methods?

From Dev

How Variable of an Interface is Working in JAVA and Calling the Methods of Interface?

From Java

Java question (calling methods with parameters) using UnboundID LDAP SDK api

From Java

Why calling methods from container class instead of instances of it in Java

From Java

Java: Calling in main implemented Interface Methods from a jUnit - Test

From Dev

Proper/easy way of calling methods from a program on remote server in java?

Related Related

  1. 1

    XPages - Calling Java methods

  2. 2

    Calling Java Methods in XSLT

  3. 3

    Calling multiple methods in Java

  4. 4

    Calling the methods in a class in Java

  5. 5

    Calling methods on objects Java

  6. 6

    Calling methods on string literals (Java)

  7. 7

    Calling methods of "parent" component in Java

  8. 8

    Calling two Java methods asynchronously

  9. 9

    Calling Java methods with React locally

  10. 10

    calling java methods in javascript code

  11. 11

    Calling methods in a Java Fx ActionEvent

  12. 12

    Generics in Java preventing calling of methods

  13. 13

    Calling methods for my java class

  14. 14

    Clojure: calling a sequence of methods on a Java object

  15. 15

    Java: Printing triangles and spaces by calling methods

  16. 16

    Programatically calling all methods in a Java class

  17. 17

    Compiler error with calling Generic methods java

  18. 18

    Calling methods of a Java subclass using Jython

  19. 19

    Calling Java Methods from Shell Scripts

  20. 20

    calling objects from other methods in java

  21. 21

    Using variables for creating objects and calling methods in Java

  22. 22

    Calling Methods In Java - Hello World Example

  23. 23

    Java FXML calling methods on button clicks

  24. 24

    How to print a christmas tree in Java, by calling methods?

  25. 25

    How Variable of an Interface is Working in JAVA and Calling the Methods of Interface?

  26. 26

    Java question (calling methods with parameters) using UnboundID LDAP SDK api

  27. 27

    Why calling methods from container class instead of instances of it in Java

  28. 28

    Java: Calling in main implemented Interface Methods from a jUnit - Test

  29. 29

    Proper/easy way of calling methods from a program on remote server in java?

HotTag

Archive