Blue J (java Anwendung) Kennt sich damit jemand etwas aus?
#1
geschrieben 11. November 2008 - 17:55
Kennt sich jemand hier im Forum vielleicht mit Blue J, eine Java Anwendung, etwas aus?
wäre sehr dankbar wenn sich jemand meldet.
Anzeige
#2
geschrieben 11. November 2008 - 18:09
Ich hab es auch mit BlueJ gelernt, fand des aber net so großartig schwer was man damit machen kann.
Was genau ist da dein Problem?
(Einer der dollen Sätze von Scooter)
Take care to get what you like, or you will be forced to like what you get.
(nochmal so einer)
#3
geschrieben 11. November 2008 - 18:42
Ich weiss, etwas unverständlich, einfach bitte nachfragen wenn nicht verstanden^^
#4
geschrieben 11. November 2008 - 19:55
Also 2 Square-Objekte erstellen(Haus+Fenster), dann ein Triangle(Dach), und ein Circle(Sonne).
Und an diesen Objekten dann die entsprechenden Methoden aufrufen da kannst du auch bei dem Circle "slowMoveVertical(int distance)" aufrufen um nen Sonnenuntergang zu simulieren
Ansonsten könntest du dir ne Methode schreiben die das für dich tut.
Und diese dann im Konstruktor der Klasse Picture aufrufen.
Des wäre aber programmieren in Java, was du ja nicht möchtest.
Oder versteh ich dich irgendwie falsch?
(Einer der dollen Sätze von Scooter)
Take care to get what you like, or you will be forced to like what you get.
(nochmal so einer)
#5
geschrieben 11. November 2008 - 20:40
ich wollt eigentlich halt nur, dass alle Teile sich möglichst irgendwie bewegen und sich dann aber wieder zusammenfügen. Mit den Methoden kennne ich mich überhaupt nicht aus.
Die Größe von den Shapes kann ich bereits verändern, nur ich kann keine Bewegung (Sonnenauf-/untergang) simulieren bzw. projezieren.
#6
geschrieben 11. November 2008 - 21:33
Ich schreib dir mal ne kleine Schritt-für-Schritt Anleitung für nen "Sonnenuntergang"
Wir sind im Project "Picture"
Du klickst mit Rechts auf die Klasse "Circle" machst "new Circle()"
und benennst des zB "sonne"(per Konvention klein) oder du lässt es auf "circle1" -> ok klicken.
Jetzt ist unten ein rotes Viereck(dein Objekt). Da klickst du mit Rechts drauf und siehst was du machen kannst.
Ruf zuerst mal "void makeVisible()" auf.
Ein Fenster mit nem blauen Punkt erscheint (das sogenannte Haus is glaub noch mit dabei).
Zum Farbe auf Gelb wechseln rufst du jetzt genau so "void changeColor(String newColor)" auf.
In dem Fenster gibst du jetzt ("yellow") ein, mit Anführungszeichen, da es ja ein String ist.
Jetzt hast du nen gelben Punkt, spaßeshalber machen wir den jetzt mal größer.
"void changeSize(int newDiameter)" -> gib halt mal die "70" ein oder so.
Zu guter Letzt rufst du jetzt an dem Objekt "void slowMoveVertical(int distance)" auf, gibst mal "50" ein. besser wenn du davor des Fenster "BlueJ Shapes Demo" an eine Stelle auf deinem Monitor ziehst wo du es sehen kannst ...
Dann wird sich deine "Sonne" langsam nach unten bewegen.
Ich schreib mal noch den Code wie der in der speziellen Methode namens "main()" aussehen könnte, um dir vllt zu zeigen, dass des nur dafür gedacht ist wenn du später ohne BlueJ programmierst und das in die main() Methode schreiben musst.
public static void main(String[] args) { Circle sun = new Circle(); sun.makeVisible(); sun.changeColor("yellow"); sun.changeSize(70); sun.slowMoveVertical(55); }
Dieser Beitrag wurde von Daniel88 bearbeitet: 11. November 2008 - 21:40
(Einer der dollen Sätze von Scooter)
Take care to get what you like, or you will be forced to like what you get.
(nochmal so einer)
#7
geschrieben 12. November 2008 - 19:21
#8
geschrieben 12. November 2008 - 20:33
/**
* This class represents a simple picture. You can draw the picture using
* the draw method. But wait, there's more: being an electronic picture, it
* can be changed. You can set it to black-and-white display and back to
* colors (only after it's been drawn, of course).
*
* This class was written as an early example for teaching Java with BlueJ.
*
* @author Michael Kolling and David J. Barnes
* @version 1.1 (24 May 2001)
*/
public class Picture
{
private Square wall;
private Square window;
private Triangle roof;
private Circle sun;
/**
* Constructor for objects of class Picture
*/
public Picture()
{
// nothing to do... instance variables are automatically set to null
}
/**
* Draw this picture.
*/
public void draw()
{
wall = new Square();
wall.moveVertical(80);
wall.changeSize(100);
wall.makeVisible();
window = new Square();
window.changeColor("black");
window.moveHorizontal(20);
window.moveVertical(100);
window.makeVisible();
roof = new Triangle();
roof.changeSize(50, 140);
roof.moveHorizontal(20);
roof.moveVertical(43);
roof.makeVisible();
roof.changeSize(49, 140);
roof.changeSize(48, 140);
roof.changeSize(47, 140);
roof.changeSize(46, 140);
roof.changeSize(45, 140);
roof.changeSize(44, 140);
roof.changeSize(43, 140);
roof.changeSize(42, 140);
roof.changeSize(41, 140);
roof.changeSize(40, 140);
roof.changeSize(39, 140);
roof.changeSize(38, 140);
roof.changeSize(37, 140);
roof.changeSize(36, 140);
roof.changeSize(35, 140);
roof.changeSize(34, 140);
roof.changeSize(33, 140);
roof.changeSize(32, 140);
roof.changeSize(31, 140);
roof.changeSize(30, 140);
roof.changeSize(29, 140);
roof.changeSize(28, 140);
roof.changeSize(27, 140);
roof.changeSize(26, 140);
roof.changeSize(25, 140);
roof.changeSize(24, 140);
roof.changeSize(23, 140);
roof.changeSize(22, 140);
roof.changeSize(21, 140);
roof.changeSize(20, 140);
roof.changeSize(19, 140);
roof.changeSize(18, 140);
roof.changeSize(17, 140);
roof.changeSize(16, 140);
roof.changeSize(15, 140);
roof.changeSize(14, 140);
roof.changeSize(13, 140);
roof.changeSize(12, 140);
roof.changeSize(11, 140);
roof.changeSize(10, 140);
roof.changeSize(9, 140);
roof.changeSize(8, 140);
roof.changeSize(7, 140);
roof.changeSize(6, 140);
roof.changeSize(5, 140);
roof.changeSize(4, 140);
roof.changeSize(3, 140);
roof.changeSize(2, 140);
roof.changeSize(1, 140);
roof.changeSize(-1, 140);
roof.changeSize(-2, 140);
roof.changeSize(-3, 140);
roof.changeSize(-4, 140);
roof.changeSize(-5, 140);
roof.changeSize(-6, 140);
roof.changeSize(-7, 140);
roof.changeSize(-8, 140);
roof.changeSize(-9, 140);
roof.changeSize(-10, 140);
roof.changeSize(-11, 140);
roof.changeSize(-12, 140);
roof.changeSize(-13, 140);
roof.changeSize(-14, 140);
roof.changeSize(-15, 140);
roof.changeSize(-16, 140);
roof.changeSize(-17, 140);
roof.changeSize(-18, 140);
roof.changeSize(-19, 140);
roof.changeSize(-20, 140);
roof.changeSize(-21, 140);
roof.changeSize(-22, 140);
roof.changeSize(-23, 140);
roof.changeSize(-24, 140);
roof.changeSize(-25, 140);
roof.changeSize(-26, 140);
roof.changeSize(-27, 140);
roof.changeSize(-28, 140);
roof.changeSize(-29, 140);
roof.changeSize(-30, 140);
roof.changeSize(-31, 140);
roof.changeSize(-32, 140);
roof.changeSize(-33, 140);
roof.changeSize(-34, 140);
roof.changeSize(-35, 140);
roof.changeSize(-36, 140);
roof.changeSize(-37, 140);
roof.changeSize(-38, 140);
roof.changeSize(-39, 140);
roof.changeSize(-40, 140);
roof.changeSize(-41, 140);
roof.changeSize(-42, 140);
roof.changeSize(-43, 140);
roof.changeSize(-44, 140);
roof.changeSize(-45, 140);
roof.changeSize(-46, 140);
roof.changeSize(-47, 140);
roof.changeSize(-48, 140);
roof.changeSize(-49, 140);
roof.changeSize(-48, 140);
roof.changeSize(-47, 140);
roof.changeSize(-46, 140);
roof.changeSize(-45, 140);
roof.changeSize(-44, 140);
roof.changeSize(-43, 140);
roof.changeSize(-42, 140);
roof.changeSize(-41, 140);
roof.changeSize(-40, 140);
roof.changeSize(-39, 140);
roof.changeSize(-38, 140);
roof.changeSize(-37, 140);
roof.changeSize(-36, 140);
roof.changeSize(-35, 140);
roof.changeSize(-34, 140);
roof.changeSize(-33, 140);
roof.changeSize(-32, 140);
roof.changeSize(-31, 140);
roof.changeSize(-30, 140);
roof.changeSize(-29, 140);
roof.changeSize(-28, 140);
roof.changeSize(-27, 140);
roof.changeSize(-26, 140);
roof.changeSize(-25, 140);
roof.changeSize(-24, 140);
roof.changeSize(-23, 140);
roof.changeSize(-22, 140);
roof.changeSize(-21, 140);
roof.changeSize(-20, 140);
roof.changeSize(-19, 140);
roof.changeSize(-18, 140);
roof.changeSize(-17, 140);
roof.changeSize(-16, 140);
roof.changeSize(-15, 140);
roof.changeSize(-14, 140);
roof.changeSize(-13, 140);
roof.changeSize(-12, 140);
roof.changeSize(-11, 140);
roof.changeSize(-10, 140);
roof.changeSize(-9, 140);
roof.changeSize(-8, 140);
roof.changeSize(-7, 140);
roof.changeSize(-6, 140);
roof.changeSize(-5, 140);
roof.changeSize(-4, 140);
roof.changeSize(-3, 140);
roof.changeSize(-2, 140);
roof.changeSize(-1, 140);
roof.changeSize(0, 140);
roof.changeSize(1, 140);
roof.changeSize(2, 140);
roof.changeSize(3, 140);
roof.changeSize(4, 140);
roof.changeSize(5, 140);
roof.changeSize(6, 140);
roof.changeSize(7, 140);
roof.changeSize(8, 140);
roof.changeSize(9, 140);
roof.changeSize(10, 140);
roof.changeSize(11, 140);
roof.changeSize(12, 140);
roof.changeSize(13, 140);
roof.changeSize(14, 140);
roof.changeSize(15, 140);
roof.changeSize(16, 140);
roof.changeSize(17, 140);
roof.changeSize(18, 140);
roof.changeSize(19, 140);
roof.changeSize(20, 140);
roof.changeSize(21, 140);
roof.changeSize(22, 140);
roof.changeSize(23, 140);
roof.changeSize(24, 140);
roof.changeSize(25, 140);
roof.changeSize(26, 140);
roof.changeSize(27, 140);
roof.changeSize(28, 140);
roof.changeSize(29, 140);
roof.changeSize(30, 140);
roof.changeSize(31, 140);
roof.changeSize(32, 140);
roof.changeSize(33, 140);
roof.changeSize(34, 140);
roof.changeSize(35, 140);
roof.changeSize(36, 140);
roof.changeSize(37, 140);
roof.changeSize(38, 140);
roof.changeSize(39, 140);
roof.changeSize(40, 140);
roof.changeSize(41, 140);
roof.changeSize(42, 140);
roof.changeSize(43, 140);
roof.changeSize(44, 140);
roof.changeSize(45, 140);
roof.changeSize(46, 140);
roof.changeSize(47, 140);
roof.changeSize(48, 140);
roof.changeSize(49, 140);
sun = new Circle();
sun.changeColor("yellow");
sun.moveHorizontal(180);
sun.moveVertical(-10);
sun.changeSize(60);
sun.makeVisible();
sun.slowMoveHorizontal(-1);
sun.slowMoveVertical(1);
sun.slowMoveHorizontal(-1);
sun.slowMoveVertical(1);
sun.slowMoveHorizontal(-1);
sun.slowMoveVertical(1);
sun.slowMoveHorizontal(-1);
sun.slowMoveVertical(1);
sun.slowMoveHorizontal(-1);
sun.slowMoveVertical(1);
sun.slowMoveHorizontal(-1);
sun.slowMoveVertical(1);
sun.slowMoveHorizontal(-1);
sun.slowMoveVertical(1);
sun.slowMoveHorizontal(-1);
sun.slowMoveVertical(1);
sun.slowMoveHorizontal(-1);
sun.slowMoveVertical(1);
sun.slowMoveHorizontal(-1);
sun.slowMoveVertical(1);
sun.slowMoveHorizontal(-1);
sun.slowMoveVertical(1);
sun.slowMoveHorizontal(-1);
sun.slowMoveVertical(1);
sun.slowMoveHorizontal(-1);
sun.slowMoveVertical(1);
sun.slowMoveHorizontal(-1);
sun.slowMoveVertical(1);
sun.slowMoveHorizontal(-1);
sun.slowMoveVertical(1);
sun.slowMoveHorizontal(-1);
sun.slowMoveVertical(1);
sun.slowMoveHorizontal(-1);
sun.slowMoveVertical(1);
sun.slowMoveHorizontal(-1);
sun.slowMoveVertical(1);
sun.slowMoveHorizontal(-1);
sun.slowMoveVertical(1);
sun.slowMoveHorizontal(-1);
sun.slowMoveVertical(1);
sun.slowMoveHorizontal(-1);
sun.slowMoveVertical(1);
sun.slowMoveHorizontal(-1);
sun.slowMoveVertical(1);
sun.slowMoveHorizontal(-1);
sun.slowMoveVertical(1);
sun.slowMoveHorizontal(-1);
sun.slowMoveVertical(1);
sun.slowMoveHorizontal(-1);
sun.slowMoveVertical(1);
sun.slowMoveHorizontal(-1);
sun.slowMoveVertical(1);
sun.slowMoveHorizontal(-1);
sun.slowMoveVertical(1);
sun.slowMoveHorizontal(-1);
sun.slowMoveVertical(1);
sun.slowMoveHorizontal(-1);
sun.slowMoveVertical(1);
sun.slowMoveHorizontal(-1);
sun.slowMoveVertical(1);
sun.slowMoveHorizontal(-1);
sun.slowMoveVertical(1);
sun.slowMoveHorizontal(-1);
sun.slowMoveVertical(1);
sun.slowMoveHorizontal(-1);
sun.slowMoveVertical(1);
sun.slowMoveHorizontal(-1);
sun.slowMoveVertical(1);
sun.slowMoveHorizontal(-1);
sun.slowMoveVertical(1);
sun.slowMoveHorizontal(-1);
sun.slowMoveVertical(1);
sun.slowMoveHorizontal(-1);
sun.slowMoveVertical(1);
sun.slowMoveHorizontal(-1);
sun.slowMoveVertical(1);
sun.slowMoveHorizontal(-1);
sun.slowMoveVertical(1);
sun.slowMoveHorizontal(-1);
sun.slowMoveVertical(1);
sun.slowMoveHorizontal(-1);
sun.slowMoveVertical(1);
roof.changeColor("black");
wall.changeColor("black");
sun.changeColor("black");
}
/**
* Change this picture to black/white display
*/
public void setBlackAndWhite()
{
if(wall != null) // only if it's painted already...
{
wall.changeColor("black");
window.changeColor("white");
roof.changeColor("black");
sun.changeColor("black");
}
}
/**
* Change this picture to use color display
*/
public void setColor()
{
if(wall != null) // only if it's painted already...
{
wall.changeColor("red");
window.changeColor("black");
roof.changeColor("green");
sun.changeColor("yellow");
}
}
}
etwas umständlich, aber das Dach habe ich somit einmal gedreht und zurück.
Wie mach ich nun, dass die Sonne langsam über das Haus in einer brückenform wandert?
Dieser Beitrag wurde von Witi bearbeitet: 13. November 2008 - 08:15
Änderungsgrund: Witi: Quellcode in Codebox-Tag gepackt
#9
geschrieben 12. November 2008 - 22:28
#10
geschrieben 12. November 2008 - 22:49
du könntest einiges mit ner for-Schleife verkürzen.
roof.changeSize(49, 140); roof.changeSize(48, 140); roof.changeSize(47, 140); roof.changeSize(46, 140); roof.changeSize(45, 140); roof.changeSize(44, 140); roof.changeSize(43, 140); roof.changeSize(42, 140); roof.changeSize(41, 140); roof.changeSize(40, 140); roof.changeSize(39, 140); roof.changeSize(38, 140); roof.changeSize(37, 140); roof.changeSize(36, 140); roof.changeSize(35, 140); roof.changeSize(34, 140); roof.changeSize(33, 140); roof.changeSize(32, 140); roof.changeSize(31, 140); roof.changeSize(30, 140); roof.changeSize(29, 140); roof.changeSize(28, 140); roof.changeSize(27, 140); roof.changeSize(26, 140); roof.changeSize(25, 140); roof.changeSize(24, 140); roof.changeSize(23, 140); roof.changeSize(22, 140); roof.changeSize(21, 140); roof.changeSize(20, 140); roof.changeSize(19, 140); roof.changeSize(18, 140); roof.changeSize(17, 140); roof.changeSize(16, 140); roof.changeSize(15, 140); roof.changeSize(14, 140); roof.changeSize(13, 140); roof.changeSize(12, 140); roof.changeSize(11, 140); roof.changeSize(10, 140); roof.changeSize(9, 140); roof.changeSize(8, 140); roof.changeSize(7, 140); roof.changeSize(6, 140); roof.changeSize(5, 140); roof.changeSize(4, 140); roof.changeSize(3, 140); roof.changeSize(2, 140); roof.changeSize(1, 140);
Das ganze wird dann zu
// Initialisierung; Bedingung; In/Dekrementierung for(int i = 49; i>0; i--) { roof.changeSize(i, 140); //setzt von 49 abwärts jeweils //die Laufvariable i bis runter zu 1 ein. }
Das mit dem brückenmäßigen Sonnenuntergang klingt eigentlich ganz einleuchtend wie du das im Code gemacht hast (auch ersetzbar mit ner Schleife). Vom Durchlesen her jetzt.
Was funktioniert da nicht?
ich versuch mal grob dir n Rectangle zu beschreiben.
Das is ne Klasse Rectangle mit nem int width und nem int height
Schau dir genau die Klasse Square an
dort findest du folgendes:
/* * Draw the square with current specifications on screen. */ private void draw() { if(isVisible) { Canvas canvas = Canvas.getCanvas(); canvas.draw(this, color, new Rectangle(xPosition, yPosition, size, size)); //interessant oder?! canvas.wait(10); } }
Dort wo der Kommentar steht wird ein RECHTECK gezeichnet, nur eben mit ein und derselben Höhe und breite
Dieser Beitrag wurde von Daniel88 bearbeitet: 12. November 2008 - 22:51
(Einer der dollen Sätze von Scooter)
Take care to get what you like, or you will be forced to like what you get.
(nochmal so einer)
#11
geschrieben 13. November 2008 - 13:11
Zitat (Daniel88: 12.11.2008, 22:49)
canvas.draw(this, color,
new Rectangle(xPosition, yPosition, size, size));
//interessant oder?!
canvas.wait(10);
}
}[/code]
Dort wo der Kommentar steht wird ein RECHTECK gezeichnet, nur eben mit ein und derselben Höhe und breite
Das Untergestrichene wird bei mir als Fehler identifiziert. (irgendwas mit unknown variable oder so)
#12
geschrieben 13. November 2008 - 13:54
Tja Variablen müssen vor der Verwendung deklariert oder/und initialisiert werden...
//Deklaration(Bekannt machen) int maxSpace; //Initialisierung(Wert zuweisen) maxSpace = 50; //oder in einer Zeile: int maxSpace = 50;
(Einer der dollen Sätze von Scooter)
Take care to get what you like, or you will be forced to like what you get.
(nochmal so einer)
#13
geschrieben 13. November 2008 - 14:38
import java.awt.*;
/**
* A square that can be manipulated and that draws itself on a canvas.
*
* @author Michael Kolling and David J. Barnes
* @version 1.0 (15 July 2000)
*/
public class Rectangle
{
private int sizea;
private int sizeb;
private int xPosition;
private int yPosition;
private String color;
private boolean isVisible;
/**
* Create a new square at default position with default color.
*/
public Rectangle()
{
sizea = 30;
sizeb = 60;
xPosition = 60;
yPosition = 50;
color = "red";
isVisible = false;
}
/**
* Make this square visible. If it was already visible, do nothing.
*/
public void makeVisible()
{
isVisible = true;
draw();
}
/**
* Make this square invisible. If it was already invisible, do nothing.
*/
public void makeInvisible()
{
erase();
isVisible = false;
}
/**
* Move the square a few pixels to the right.
*/
public void moveRight()
{
moveHorizontal(20);
}
/**
* Move the square a few pixels to the left.
*/
public void moveLeft()
{
moveHorizontal(-20);
}
/**
* Move the square a few pixels up.
*/
public void moveUp()
{
moveVertical(-20);
}
/**
* Move the square a few pixels down.
*/
public void moveDown()
{
moveVertical(20);
}
/**
* Move the square horizontally by 'distance' pixels.
*/
public void moveHorizontal(int distance)
{
erase();
xPosition += distance;
draw();
}
/**
* Move the square vertically by 'distance' pixels.
*/
public void moveVertical(int distance)
{
erase();
yPosition += distance;
draw();
}
/**
* Slowly move the square horizontally by 'distance' pixels.
*/
public void slowMoveHorizontal(int distance)
{
int delta;
if(distance < 0)
{
delta = -1;
distance = -distance;
}
else
{
delta = 1;
}
for(int i = 0; i < distance; i++)
{
xPosition += delta;
draw();
}
}
/**
* Slowly move the square vertically by 'distance' pixels.
*/
public void slowMoveVertical(int distance)
{
int delta;
if(distance < 0)
{
delta = -1;
distance = -distance;
}
else
{
delta = 1;
}
for(int i = 0; i < distance; i++)
{
yPosition += delta;
draw();
}
}
/**
* Change the size to the new size (in pixels). Size must be >= 0.
*/
public void changeSize(int newSize)
{
erase();
sizea = newSizea;
sizeb = newSizeb;
draw();
}
/**
* Change the color. Valid colors are "red", "yellow", "blue", "green",
* "magenta" and "black".
*/
public void changeColor(String newColor)
{
color = newColor;
draw();
}
/*
* Draw the square with current specifications on screen.
*/
private void draw()
{
if(isVisible) {
Canvas canvas = Canvas.getCanvas();
canvas.draw(this, color,
new Rectangle(xPosition, yPosition, size, size));
canvas.wait(10);
}
}
/*
* Erase the square on screen.
*/
private void erase()
{
if(isVisible) {
Canvas canvas = Canvas.getCanvas();
canvas.erase(this);
}
}
}
Wenn ich das nun kompilieren will, öffnet er mir ''Canvas''. Da steht dann bei private void erase:
*/
private void erase()
{
Color original = graphic.getColor();
graphic.setColor(backgroundColour);
Dimension size = canvas.getSize();
graphic.fill(new Rectangle(0, 0, size.width, size.height));
graphic.setColor(original);
}
Das Untergestrichene markiert er mir und sagt: ''cannot find symbol - constructor Rectangle(int,int,int,int)
Gehe ich zu ''Canvas'' und drücke dort auf Compile, öffnet er mir den Quelltext von Rectangle:
public void changeSize(int newSize)
{
erase();
sizea = newSizea;
sizeb = newSizeb;
draw();
}
Das Unterstrichene markiert er mir und sagt:''cannot find symbol - variable newSizea''
Wenn ich bei Picture compile drücke, zeigt er mir beide von den oben beschriebenen Fehlermeldungen an
#14
geschrieben 13. November 2008 - 14:49
Schnelle(etwas unschöne) Lösung ist, dass du DEINE Klasse Rectangle in z.B. "MyRectangle" umbenennst.
Da müssten aber noch n paar Bugs drin sein.
/** * Change the size to the new size (in pixels). Size must be >= 0. */ public void changeSize(int newSize) { erase(); sizea = newSizea; sizeb = newSizeb; draw(); }
um die size zu ändern musst du da jetzt 2 Parameter mitgeben! damit dein sizea den wert "newSizea" hat nachher und dein sizeb den Wert "newSizeb" hat.
/** * Change the size to the new size newSizea and newSizeb(in pixels). Size must be >= 0. */ public void changeSize(int newSizea, int newSizeb) { erase(); sizea = newSizea; sizeb = newSizeb; draw(); }
Das nächste Problem hier ist:
/* * Draw the square with current specifications on screen. */ private void draw() { if(isVisible) { Canvas canvas = Canvas.getCanvas(); canvas.draw(this, color, new Rectangle(xPosition, yPosition, size, size)); canvas.wait(10); } }
Das wird immer noch ein Quadrat, da zweimal der wert "size" eingetragen wird. Naja is eh net bekannt, also gibt des au n Fehler vom Compiler.
Was du da meinst/brauchst ist:
/* * Draw the square with current specifications on screen. */ private void draw() { if(isVisible) { Canvas canvas = Canvas.getCanvas(); canvas.draw(this, color, new Rectangle(xPosition, yPosition, sizea, sizeb)); canvas.wait(10); } }
Rectangle lassen!!! Das müsste ne Standard Klasse von Java sein.
(Einer der dollen Sätze von Scooter)
Take care to get what you like, or you will be forced to like what you get.
(nochmal so einer)
#15
geschrieben 13. November 2008 - 15:17
Zitat (Daniel88: 13.11.2008, 14:49)
Schnelle(etwas unschöne) Lösung ist, dass du DEINE Klasse Rectangle in z.B. "MyRectangle" umbenennst.
Da müssten aber noch n paar Bugs drin sein.
/** * Change the size to the new size (in pixels). Size must be >= 0. */ public void changeSize(int newSize) { erase(); sizea = newSizea; sizeb = newSizeb; draw(); }
um die size zu ändern musst du da jetzt 2 Parameter mitgeben! damit dein sizea den wert "newSizea" hat nachher und dein sizeb den Wert "newSizeb" hat.
/** * Change the size to the new size newSizea and newSizeb(in pixels). Size must be >= 0. */ public void changeSize(int newSizea, int newSizeb) { erase(); sizea = newSizea; sizeb = newSizeb; draw(); }
Das nächste Problem hier ist:
/* * Draw the square with current specifications on screen. */ private void draw() { if(isVisible) { Canvas canvas = Canvas.getCanvas(); canvas.draw(this, color, new Rectangle(xPosition, yPosition, size, size)); canvas.wait(10); } }
Das wird immer noch ein Quadrat, da zweimal der wert "size" eingetragen wird. Naja is eh net bekannt, also gibt des au n Fehler vom Compiler.
Was du da meinst/brauchst ist:
/* * Draw the square with current specifications on screen. */ private void draw() { if(isVisible) { Canvas canvas = Canvas.getCanvas(); canvas.draw(this, color, new Rectangle(xPosition, yPosition, sizea, sizeb)); canvas.wait(10); } }
Rectangle lassen!!! Das müsste ne Standard Klasse von Java sein.
Das habe ich alles gemacht, bis auf das umbenennen in ''MyRectangle''. Wo soll ich das tun?
Ich kann ''Picture'' immer noch nicht kompilieren. Er zeigt mir jetzt immer noch bei ''Canvas'', ''Rectangle'' und jetzt auch bei ''Square'' diesen Fehler an:
bei ''Rectangle'':
private void draw()
{
if(isVisible) {
Canvas canvas = Canvas.getCanvas();
canvas.draw(this, color,
new Rectangle(xPosition, yPosition, sizea, sizeb));
canvas.wait(10);
}
}
Das Unterstrichene wird immer noch mit der selben Fehlermeldung erkannt (cannot find symbol - constructor Rectangle(int,int,int,int))
bei ''Square'':
private void draw()
{
if(isVisible) {
Canvas canvas = Canvas.getCanvas();
canvas.draw(this, color,
new Rectangle(xPosition, yPosition, size, size));
canvas.wait(10);
}
}
Das Unterstrichene wird immer noch mit der selben Fehlermeldung erkannt (cannot find symbol - constructor Rectangle(int,int,int,int))
bei ''Canvas'':
private void erase()
{
Color original = graphic.getColor();
graphic.setColor(backgroundColour);
Dimension size = canvas.getSize();
graphic.fill(new Rectangle(0, 0, size.width, size.height));
graphic.setColor(original);
}
Das Unterstrichene wird immer noch mit der selben Fehlermeldung erkannt (cannot find symbol - constructor Rectangle(int,int,int,int))