Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Java Applets and Init()?

Name: Anonymous 2007-10-09 21:29

I'm having an issue passing variables from init() and paint() in a Java Applet- what's the rules on those again? I'm trying to pass variables from a user input window to a graphics display thing in paint(), but I can't get them to pass, the values are lost from init() to paint(). Ideas?

Name: Anonymous 2007-10-09 21:31

I know it's fucking ridiculous, I know Java is a shit language- but I have to take it before I get into C++ and the like. I'm a poor boy from the land of PERL and PHP, this shit annoys me to no end. The code looks like this (uncommented):

public class tester extends JApplet
{
public double dx1;
    String x1, x2, x3, y1, y2, y3;
    triangle tri;
    double area, perim, angleA, angleB, angleC;

    public void init()
    {
    }
    public void start()
    {
   
        String x1 = JOptionPane.showInputDialog("Point 1 X?");
        String y1 = JOptionPane.showInputDialog("Point 1 Y?");
        String x2 = JOptionPane.showInputDialog("Point 2 X?");
        String y2 = JOptionPane.showInputDialog("Point 2 Y?");
        String x3 = JOptionPane.showInputDialog("Point 3 X?");
        String y3 = JOptionPane.showInputDialog("Point 3 Y?");
       
        double dx1 = Double.parseDouble(x1);
        double dy1 = Double.parseDouble(y1);
        double dx2 = Double.parseDouble(x2);
        double dy2 = Double.parseDouble(y2);
        double dx3 = Double.parseDouble(x3);
        double dy3 = Double.parseDouble(y3);
       
        Point2D p1 = new Point2D.Double(dx1,dy1);
        Point2D p2 = new Point2D.Double(dx2,dy2);
        Point2D p3 = new Point2D.Double(dx3,dy3);
        triangle tri = new triangle(p1, p2, p3);
        }
    public void stop()
    {}
    public void paint(Graphics g)
    {
        double perim = tri.getPerimeter(tri.getLength(1),tri.getLength(2),tri.getLength(3));
        JOptionPane.showMessageDialog(null,perim);
        double area = tri.getArea(tri.getLength(1),tri.getLength(2),tri.getLength(3));
        double angleA = tri.getAngle(tri.getLength(1),tri.getLength(2),tri.getLength(3));
        double angleB = tri.getAngle(tri.getLength(2),tri.getLength(3),tri.getLength(1));
        double angleC = tri.getAngle(tri.getLength(3),tri.getLength(1),tri.getLength(2));
        Graphics2D g2 = (Graphics2D) g;
       
        tri.drawtriangle(g2);

        g2.drawString("Area: " + area,400,485);
        g2.drawString("Perim:" + perim,400,495);
        g2.drawString("A1: " + Math.toDegrees(angleA),400,455);
        g2.drawString("A2: " + Math.toDegrees(angleB),400,465);
        g2.drawString("A3: " + Math.toDegrees(angleC),400,475);
    }
    public void destroy()
    {}
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List