// 간단한 함수 그리려는데요..  class가 두개

package com.android.mathgraph;

import java.util.StringTokenizer;

public class MathGraph extends Activity{
 protected static final Integer Inteager = null;
/** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  final EditText t1 = (EditText)findViewById(R.id.EditText01);
   t1.setText("");
 
   Button btn = (Button)findViewById(R.id.Button01);
 
  btn.setText("create a graph!");
 
  View DrawGraph = (View) findViewById(R.id.View01);
  final DrawGraph tv = new DrawGraph(this, null);

  btn.setOnClickListener(new View.OnClickListener() {                     //여기부터 클릭 리스너
  
   public void onClick(View arg0) {
    // TODO Auto-generated method stub

 tv.input[0] = 20;                                                                              //이렇게 2개를 그냥 집어너놨습니다.
 tv.input[1] = 10;
 
    setContentView(tv);                                                                //이건 그리기
   }
  });
 
 }
}

//그리는 클래스는 요기부터


package com.android.mathgraph;

import android.content.Context;

class DrawGraph extends View {

float[] input = new float []{0,0};                                          //여기 2개 만들어놈;

 public DrawGraph(Context context, AttributeSet attrs) {
  super(context);
  // TODO Auto-generated constructor stub
 }

 

 public void onDraw(Canvas canvas) {
 
  Paint p = new Paint(); // 그래프의 색
  p.setColor(Color.WHITE);
 
  Paint p1 = new Paint(); // 기준선의 색, X축, Y축
  p1.setColor(Color.WHITE);

  float startingX = 160.0f; // 원점 X좌표
  float startingY = 220.0f; // 원점 Y좌표

  canvas.drawLine(0, startingY, 320, startingY, p1);
  canvas.drawLine(startingX, 0, startingX, 480, p1);

  float x = -160f,y;

  y = input[0]*x+input[1];                                                                                //여기랑
 
  float x1 = x, y1 = y;

  for (; x <= 160.0f; x++)

  {

   y = input[0]*x+input[1];                                                                            //여기서 쓰임

   canvas.drawLine(x1 + startingX, -y1 + startingY, x + startingX, -y + startingY, p);

   x1 = x;
   y1 = y;
  }
 }
}


//익셉션이 계속 발생해요 뭐가 문제일까요? ㅠ 초보라.