aspose file tools*
The moose likes Applets and the fly likes Help on java graph applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Help on java graph applet" Watch "Help on java graph applet" New topic
Author

Help on java graph applet

Ranie Riegram
Greenhorn

Joined: Apr 10, 2004
Posts: 3
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class Marglida extends Applet implements ActionListener
{
TextField t1,t2, t3;
TextArea t4;
Label l1, l2, l3;
Button b1;
public void init()
{
t1 = new TextField(5);
t2 = new TextField(5);
t3 = new TextField(5);
t4 = new TextArea(5,25);
l1 = new Label ("A: ");
l2 = new Label ("B: ");
l3 = new Label ("C: ");
b1 = new Button ("Leysa j�fnuna!");
b1.addActionListener (this);
this.add (t1);
this.add (l1);
this.add (t2);
this.add (l2);
this.add (t3);
this.add (l3);
this.add (b1);
this.add (t4);

}
public void actionPerformed (ActionEvent e)
{
Double D1, D2, D3;
D1 = new Double( t1.getText() );
D2 = new Double( t2.getText() );
D3 = new Double( t3.getText() );
double d1, d2, d3;
d1 = D1.doubleValue();
d2 = D2.doubleValue();
d3 = D3.doubleValue();
double var1, var2, var3;
var1 = d1;
var2 = d2;
var3 = d3;
String gildi;
double x;
double svar, svar2;
x=Math.pow(d2,2) - 4*d1*d3;

if(x ==0){
svar = -d2/(2*d1);
gildi = "Ein lausn:" + svar;
}
else if ((Math.pow(d2,2) - 4*d1*d3) < 0) {
gildi = "Engin lausn";
}
else {
svar = (-d2+Math.sqrt(x))/(2*d1);
svar2 = (d2-Math.sqrt(x))/(2*d1);
gildi = "Tv�r lausnir: "+ svar + " og " + svar2;
}

t4.setText( gildi );
repaint();
}
public void paint( Graphics g ){
//hnitakerfi
//g.drawLine(x1,y1,x2,y2)
for( int i=-50; i<50; i+=1 ){
g.drawLine( 220+(i*10),220-((var1*(i*i)+(var2*i)+var3)*10),220+((i+1)*10),220-((var1*((i+1)*(i+1))+(var2*(i+1))+var3))*10);
g.drawLine(0,340,440,340); // x-�s
g.drawLine(220,140,220,580); // y-�s
// x-�s l�nur
g.drawLine(260,336,260,344);
g.drawLine(300,336,300,344);
g.drawLine(340,336,340,344);
g.drawLine(380,336,380,344);
g.drawLine(420,336,420,344);
g.drawLine(180,336,180,344);
g.drawLine(140,336,140,344);
g.drawLine(100,336,100,344);
g.drawLine(60,336,60,344);
g.drawLine(20,336,20,344);
// y-�s l�nur
g.drawLine(216,380,224,380);
g.drawLine(216,420,224,420);
g.drawLine(216,460,224,460);
g.drawLine(216,500,224,500);
g.drawLine(216,540,224,540);
g.drawLine(216,300,224,300);
g.drawLine(216,260,224,260);
g.drawLine(216,220,224,220);
g.drawLine(216,180,224,180);
g.drawLine(216,140,224,140);
//t�lur � hnitakerfi
// 1 til 5 � x-�s
g.drawString("5",417,355);
g.drawString("4",377,355);
g.drawString("3",337,355);
g.drawString("2",297,355);
g.drawString("1",257,355);
// -1 til -5 � x-�s
g.drawString("-1",176,355);
g.drawString("-2",136,355);
g.drawString("-3",96,355);
g.drawString("-4",56,355);
g.drawString("-5",16,355);
// 1 til 5 � y-�s
g.drawString("1",203,305);
g.drawString("2",203,265);
g.drawString("3",203,225);
g.drawString("4",203,185);
g.drawString("5",203,145);
// -1 til -5 � y-�s
g.drawString("-1",203,385);
g.drawString("-2",203,425);
g.drawString("-3",203,465);
g.drawString("-4",203,505);
g.drawString("-5",203,545);
// 000000000000000000000
g.drawString("0",222,352);

}
}
}

I can't get this thing to work, I need to make it able to paint a graph if you give the damm the thing there integers A,B,C as in Ax^2+Bx+C ... but as I've said, I can't get it to work.
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Ranie Riegram
Greenhorn

Joined: Apr 10, 2004
Posts: 3
It's veryvery nice... But the things is, I need to be able to choose (put in, that is the user) what A is, B is and C is as in Ax^2+Bx+C and also a textbox that tells you where the graph "cuts" the x-axis...
but once again... very very impressive
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
What else can I do for you?
Ranie Riegram
Greenhorn

Joined: Apr 10, 2004
Posts: 3
really nothing, it�s amazing, I just realized how it worked... it still though nee do be able to make the thing figure out his Ax^2+Bx+C=0 find the possible sollutions
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Help on java graph applet