V
VielenDank
Gast
Ich habe ein Problem mit der Drachenkurve und bräuchte eure Hilfe.
Hier unser Code.
[Java] import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
/**
*
* Beschreibung
*
* @version 1.0 vom 06.12.2011
* @author
*/
public class Drachenkoorve extends JFrame {
// Anfang Attribute
private Button button1 = new Button();
private Turtle t1 = new Turtle(100, 100);
// Ende Attribute
public Drachenkoorve(String title) {
// Frame-Initialisierung
super(title);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
int frameWidth = 927;
int frameHeight = 571;
setSize(frameWidth, frameHeight);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
int x = (d.width - getSize().width) / 2;
int y = (d.height - getSize().height) / 2;
setLocation(x, y);
setResizable(false);
Container cp = getContentPane();
cp.setLayout(null);
// Anfang Komponenten
button1.setBounds(136, 0, 75, 25);
button1.setLabel("button1");
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
button1_ActionPerformed(evt);
}
});
cp.add(button1);
t1.setBounds(48, 80, 100, 100);
cp.add(t1);
t1.setBounds(0, 40, 892, 500);
t1.setBounds(40, 24, 852, 516);
// Ende Komponenten
setVisible(true);
}
// Anfang Methoden
int rechts=-1;
int links =+1;
public void Drachenkoorve(int stufe, double laenge, int richtung)
{
if (stufe > 0)
{ t1.turn(-45*richtung);
Drachenkoorve(stufe-1, laenge/2, links);
t1.turn(90*richtung);
Drachenkoorve(stufe-1, laenge/2, rechts);
t1.turn(-45*richtung);
}
else { t1.move(laenge); }
}
public void button1_ActionPerformed(ActionEvent evt) {
int laenge=70;
int stufe= 5 ;
int richtung=6;
t1.moveto(90,87);
this.Drachenkoorve(stufe, laenge, richtung);
t1.draw(250);
}
public static void main(String[] args) {
new Drachenkoorve("Drachenkoorve");
}
}
[/code]
Er zeichnet bei uns nur einen horizontalen Strich. Vielen Dank für Ihre Antworten.
Hier unser Code.
[Java] import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
/**
*
* Beschreibung
*
* @version 1.0 vom 06.12.2011
* @author
*/
public class Drachenkoorve extends JFrame {
// Anfang Attribute
private Button button1 = new Button();
private Turtle t1 = new Turtle(100, 100);
// Ende Attribute
public Drachenkoorve(String title) {
// Frame-Initialisierung
super(title);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
int frameWidth = 927;
int frameHeight = 571;
setSize(frameWidth, frameHeight);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
int x = (d.width - getSize().width) / 2;
int y = (d.height - getSize().height) / 2;
setLocation(x, y);
setResizable(false);
Container cp = getContentPane();
cp.setLayout(null);
// Anfang Komponenten
button1.setBounds(136, 0, 75, 25);
button1.setLabel("button1");
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
button1_ActionPerformed(evt);
}
});
cp.add(button1);
t1.setBounds(48, 80, 100, 100);
cp.add(t1);
t1.setBounds(0, 40, 892, 500);
t1.setBounds(40, 24, 852, 516);
// Ende Komponenten
setVisible(true);
}
// Anfang Methoden
int rechts=-1;
int links =+1;
public void Drachenkoorve(int stufe, double laenge, int richtung)
{
if (stufe > 0)
{ t1.turn(-45*richtung);
Drachenkoorve(stufe-1, laenge/2, links);
t1.turn(90*richtung);
Drachenkoorve(stufe-1, laenge/2, rechts);
t1.turn(-45*richtung);
}
else { t1.move(laenge); }
}
public void button1_ActionPerformed(ActionEvent evt) {
int laenge=70;
int stufe= 5 ;
int richtung=6;
t1.moveto(90,87);
this.Drachenkoorve(stufe, laenge, richtung);
t1.draw(250);
}
public static void main(String[] args) {
new Drachenkoorve("Drachenkoorve");
}
}
[/code]
Er zeichnet bei uns nur einen horizontalen Strich. Vielen Dank für Ihre Antworten.