ג'אווה גרפיקה ואובייקטים כמה שאלות - עמוד 2 - תכנות - HWzone פורומים
עבור לתוכן
  • צור חשבון

ג'אווה גרפיקה ואובייקטים כמה שאלות


supercars

Recommended Posts

לא למדתי על קלאסים.

כשציינת את המילה קלאס, חשבתי שאתה מתכוון לקטע תוכנית עם לולאות, תנאים,משתנים וכד'.

בשורה התחתונה לא משנה מה למדתי מה לא:

אני לא יודע אובייקטים.

תוכל בבקשה להסביר לי איך אני בונה אובייקט שמורכב מהצורות הנ"ל?

זה לא אמור להיות כל כך מסובך להסביר כזה דבר פשוט תגיד לי מה לכתוב או שתכתוב בעצמך ותעתיק לכאן זה אמור להיות פשוט מאוד לפי מה שאתה אומר.

עריכה:

עזוב לא יודע אובייקטים.

אני לא יודע לבצע את המשימה הזאת. תוכל להסביר לי?

מי שנתן לי לעשות אותה לא מצפה שאני אדע אובייקטים, אתה מבין אותי?

קישור לתוכן
שתף באתרים אחרים

לא למדת על קלאסים? אז איך המורה מצפה שתעשו דבר כזה בכלל?

קלאסים זה לא איזה נושא קטנטן שאפשר ללמוד עליו בשתי שניות, מדובר במרכיב משמעותי בשפה. התרגיל הזה הוא בערך כמו לומר לך לכתוב תכנית שעושה משהו בלי שלמדת את שפת התכנות.

אם אתה רוצה ללמוד על קלאסים ואובייקטים, אתה מוזמן לפתוח ספר לימוד ג'אווה (או לחפש אתרי לימוד ברשת) וללמוד. כאמור, מדובר בנושא שלם. אישית, הייתי שואל את המורה איך לעזאזל היא/הוא מצפה שתגדירו אובייקטים בלי לדעת מה זה אובייקטים (נשמע פילוסופי משהו).

קישור לתוכן
שתף באתרים אחרים

ושוב, אתה מצפה שננחש מה עשית עד עכשיו?

בהנחה שיש לאובייקט שלך שדות שמייצגים את המימדים שלו (נניח אורך ורוחב), אז פעולת ההגדלה פשוט צריכה להכפיל אותם באותו scale. סיבוב זו פעולה קצת יותר מסובכת (צריך גם ציר סיבוב, ויש נוסחה מתמטית עם סינוסים וקוסינוסים).

קישור לתוכן
שתף באתרים אחרים

public class Face 
{
private Circle Face;
private Circle Eye1;
private Circle Eye2;
private Triangle Hat;
private Square Mouth1;
private Square Mouth2;
private Square Mouth3;
private Circle Freckle;
private Line Brow1;
private Line Brow2;
private Circle Round;
private Text Name;
// Creates the face parts
public Face(int bSize,String bColor,
int dSize,String inColor, int knobRadious,String knobColor,
int chimSize,String chimColor,
int rHeight, int rWidth,String rColor,
int radious,
String name)
{
Canvas canvas = Canvas.getCanvas();
this.Face = new Circle (85,85,bSize,bColor);
canvas.wait(500);
this.Eye1 = new Circle(370,30,dSize,inColor);
this.Eye2 = new Circle(370,360,dSize,inColor);
this.Round = new Circle(550,350,knobRadious,knobColor);
canvas.wait(500);
this.Mouth1= new Square(200,350,chimSize,chimColor);
this.Mouth2 = new Square(200,350+chimSize,chimSize,chimColor);
this.Mouth3 = new Square(200,350+chimSize,chimSize,chimColor);
canvas.wait(500);
this.Hat = new Triangle((int)rWidth/2,200,rWidth,rHeight,rColor);
canvas.wait(500);
this.Freckle = new Circle(radious,550,radious,inColor);
canvas.wait(500);
this.Brow1 = new Line(550-radious,radious,550+radious,radious,"black");
this.Brow2 = new Line(550-radious,radious,550+radious,radious,"black");
canvas.wait(500);
this.Name = new Text(500,300,name,"black");
}
// Organizes the face parts into a face
public void delayMoveTo(int xPosition,int yPosition)
{
int bSize = this.Face.getSize();
int chimSize = this.Mouth1.getSize();
double radious = this.Freckle.getRadious();
int dSize = this.Eye1.getSize();
int rHeight = this.Hat.getHeight();
Canvas canvas = Canvas.getCanvas();
this.Face.moveTo(xPosition,yPosition);
canvas.wait(500);
this.Eye1.moveTo(xPosition+(bSize/4)-50,yPosition+(bSize-dSize)-15);
this.Eye2.moveTo(xPosition+(bSize/4)+50,yPosition+(bSize-2*dSize)-15);
this.Round.moveTo(xPosition+(bSize/4)+(int)(dSize*0.75),yPosition+(bSize-dSize));
canvas.wait(500);
this.Mouth1.moveTo(xPosition+(int)+(bSize*0.75)-16,yPosition-(int)(bSize*0.35)+35);
this.Mouth2.moveTo(xPosition+(int)+(bSize*0.75)-10,yPosition-(int)(bSize*0.35)-chimSize+42);
this.Mouth3.moveTo(xPosition+(int)+(bSize*0.75)-4,yPosition-(int)(bSize*0.35)-chimSize+35);
canvas.wait(500);
this.Hat.moveTo(xPosition+(bSize/2),yPosition-rHeight-148);
canvas.wait(500);
this.Freckle.moveTo(xPosition+(int)(bSize*0.75),yPosition+(int)(bSize*0.25));
canvas.wait(500);
this.Brow1.moveTo(xPosition+(int)(bSize*0.75)-(int)radious+38,yPosition+(int)(bSize*0.25)-40);
this.Brow2.moveTo(xPosition+(int)(bSize*0.75)-(int)radious-63,yPosition+(int)(bSize*0.25)-40);
canvas.wait(500);
this.Name.moveTo(xPosition+(int)(bSize*0.25)-200,yPosition-(int)(rHeight*0.25)-80);
}
//Move the face to a new location
public void moveTo(int xPosition,int yPosition)
{
int bSize = this.Face.getSize();
int chimSize = this.Mouth1.getSize();
double radious = this.Freckle.getRadious();
int dSize = this.Eye1.getSize();
int rHeight = this.Hat.getHeight();
this.Face.moveTo(xPosition,yPosition+60);
this.Eye1.moveTo(xPosition+(bSize/4)-50,yPosition+(bSize-dSize)+4);
this.Eye2.moveTo(xPosition+(bSize/4)+50,yPosition+(bSize-2*dSize)+4);
this.Round.moveTo(xPosition+(bSize/4)+(int)(dSize*0.75),yPosition+(bSize-dSize)+25);
this.Mouth1.moveTo(xPosition+(int)+(bSize*0.75)-16,yPosition-(int)(bSize*0.35)+65);
this.Mouth2.moveTo(xPosition+(int)+(bSize*0.75)-10,yPosition-(int)(bSize*0.35)-chimSize+65);
this.Mouth3.moveTo(xPosition+(int)+(bSize*0.75)-4,yPosition-(int)(bSize*0.35)-chimSize+65);
this.Hat.moveTo(xPosition+(bSize/2),yPosition-rHeight-75);
this.Freckle.moveTo(xPosition+(int)(bSize*0.75),yPosition+(int)(bSize*0.25)+25);
this.Brow1.moveTo(xPosition+(int)(bSize*0.75)-(int)radious+38,yPosition+(int)(bSize*0.25)+5);
this.Brow2.moveTo(xPosition+(int)(bSize*0.75)-(int)radious-63,yPosition+(int)(bSize*0.25)+5);
this.Name.moveTo(xPosition+(int)(bSize*0.25)-100,yPosition-(int)(rHeight*0.25)-100);
}
//Move face by an amount
public void moveAmount(int deltaX,int deltaY)
{
this.Face.move(deltaX, deltaY);
this.Eye1.move(deltaX, deltaY);
this.Eye2.move(deltaX, deltaY);
this.Mouth1.move(deltaX, deltaY);
this.Mouth2.move(deltaX, deltaY);
this.Mouth3.move(deltaX, deltaY);
this.Hat.move(deltaX, deltaY);
this.Freckle.move(deltaX, deltaY);
this.Brow1.move(deltaX, deltaY);
this.Brow2.move(deltaX, deltaY);
this.Round.move(deltaX, deltaY);
this.Name.move(deltaX, deltaY);
}
//Disassembles the face into face parts
public void disassembel()
{
this.Face.moveTo(85,85);
this.Eye1.moveTo(370,30);
this.Eye2.moveTo(370,360);
this.Round.moveTo(550,350);
this.Mouth1.moveTo(200,350);
this.Mouth2.moveTo(200,350+this.Mouth1.getSize());
this.Mouth3.moveTo(200,350+this.Mouth1.getSize());
this.Hat.moveTo(this.Hat.getWidth()+150/2,200);
this.Freckle.moveTo((int)this.Freckle.getRadious()+50,350);
this.Brow1.moveTo(550-(int)this.Freckle.getRadious(),(int)this.Freckle.getRadious()+20);
this.Brow2.moveTo(550-(int)this.Freckle.getRadious(),(int)this.Freckle.getRadious()+30);
this.Name.moveTo(550,200);
}
}

קישור לתוכן
שתף באתרים אחרים

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

×
  • צור חדש...