public class SetCenter {
public static void main(String args[]){
//Rectangle point x,y start as 0,0
float x1,x2,x3,x4;
float y1,y2,y3,y4;
//x,y point
x1 = 0.0f; x2 = 0.0f; x3 = 100.0f; x4 = 100.0f;
y1 = 0.0f; y2 = 40.0f; y3 = 40.0f; y4 = 0.0f;
//Rectangle set center in box x,y
float a = 60.0f; float b = 20.0f; // width x height
//now fix specify x,y point
//and have rectangle or axb
//calculate
float ax = ((x4 - x1) - a)/2;
float ay = ((y2 - y1) - b)/2;
System.out.println("Start draw at point" + ax + " , " + ay);
}
}
เป็นเบื้องต้นในการเขียนโปรแกรม ตัวอย่างนี้มันไม่ได้สร้างเป็นโปรเจคที่ใหญ่ๆ แต่เป็นติ่งหนึ่งในโปรเจคหรือโปรแกรมใหญ่ เช่น Web WebApplication เป็นต้น
ไม่มีความคิดเห็น:
แสดงความคิดเห็น