Hi,
hab euch ja die Tage mit meiner Parabel belästigt. Versuche die Sache weiter zu verfeinern. Und hangel mich durch.
Wohin übergebe ich die Eingabe? an den Controller?
der der sie dann an Modell weiterübergibt. berechnet und dann in View zeichnet?
Knoten im Kopf.
hab euch ja die Tage mit meiner Parabel belästigt. Versuche die Sache weiter zu verfeinern. Und hangel mich durch.
Java:
import java.awt.*;
import javax.swing.*;
public class Parabel extends JFrame
{
private float a,b,c,z;
public Parabel(float a1,float z1,float b1,float c1)
{
a = a1;
b = b1;
c = c1;
z = z1;
setLocation(300,300);
setSize(500,500);
setTitle("Parabel");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public void paint(Graphics g)
{
double xold=0, yold=0;
g.setColor(Color.black);
//Koordinatenkreuz
g.drawLine(0,250,500,250);//x - Achse
g.drawLine(250,0,250,500);//y - Achse
for (int i=50;i<250;i+=50){
g.drawLine(245,i,255,i);
}
for (int i=300;i<500;i+=50){
g.drawLine(245,i,255,i);
}
for (int i=50;i<250;i+=50){
g.drawLine(i,245,i,255);
}
for (int i=300;i<500;i+=50){
g.drawLine(i,245,i,255);
}
//Beschriftung
String strX = new String ("x");
String strY = new String ("y");
g.drawString(strX,490,263);
g.drawString(strY,255,33);
String[]A ={"-4","-3","-2","-1"," ","1","2","3","4"};
int xStep = 40;
for(int i = 0;i<9;++i){
g.drawString(A[i],xStep,268);
if(i==4) xStep=250;
if(i>0){
xStep+=48;
}else{
xStep+=48;
}
}
//PunkteGrid
for (int i=50;i<250;i+=50){
for (int j=0;j<250;j+=50){
g.drawOval(i,j,1,1);
}
}
for (int i= 300;i<500;i+=50){
for (int j = 50;j<250;j+=50){
g.drawOval(i,j,1,1);
}
}
for (int i= 50;i<250;i+=50){
for (int j = 300;j<500;j+=50){
g.drawOval(i,j,1,1);
}
}
for (int i= 300;i<500;i+=50){
for (int j = 300;j<500;j+=50){
g.drawOval(i,j,1,1);
}
}
g.translate(250,250);
double y=0;
final int pixel=50;
g.setColor(Color.red);
for(double x=-50;x<=50;x+=.1)
{
y=a*Math.pow(x,z)+b*x+c;
System.out.println(y);
y*=-1;
if(x==-50)
{
xold=x;
yold=y;
}
g.drawLine((int)(xold*pixel),(int)(yold*pixel),(int)(x*pixel),(int)(y*pixel));
xold=x;
yold=y;
}
}
public static void main(String[] args)
{
String eing = JOptionPane.showInputDialog("Bitte geben sie für die Parabelform y = ax^z + bx + c den Wert a ein:");
float a = Float.parseFloat(eing);
eing = JOptionPane.showInputDialog("Bitte geben sie für die Parabelform y = ax^z + bx + c den Wert z ein:");
float z = Float.parseFloat(eing);
eing = JOptionPane.showInputDialog("Bitte geben sie für die Parabelform y = ax^z + bx + c den Wert b ein:");
float b = Float.parseFloat(eing);
eing = JOptionPane.showInputDialog("Bitte geben sie für die Parabelform y = ax^z + bx + c den Wert c ein:");
float c = Float.parseFloat(eing);
Parabel p1 = new Parabel(a,z,b,c);
}
}
der der sie dann an Modell weiterübergibt. berechnet und dann in View zeichnet?
Knoten im Kopf.