1
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?
3
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()
{}
}
5
Name:
Anonymous
2007-10-10 2:20
Keep using perl
and static variables
6
Name:
Anonymous
2007-10-10 3:10
You are creating new x1, y1, x2, y2, x3, y3 variables in the scope of only the method start() .
Try:
x1 = JOptionPane.showInputDialog("Point 1 X?");
Rather than
String x1 = JOptionPane.showInputDialog("Point 1 X?");
7
Name:
Anonymous
2007-10-10 9:10
>>3
Typical Java hater, doesn't know shit about programming.
25
Name:
test
2010-02-20 18:02
26
Name:
test
2010-02-20 18:05
27
Name:
test
2010-02-20 18:05
28
Name:
test
2010-02-20 18:07
http://h<p:// <> http://http:<>//h<< ;;;"<<<<ttp://http://<><;
http://goo [a]"<><http://[/a]gle.com
29
Name:
test
2010-02-20 18:07
http://h<p:// <> http://http:<>//h<< ;;;"<<<<ttp://http://<><;
http://goo "<><http:// gle.com
30
Name:
test
2010-02-20 18:10
31
Name:
test
2010-02-20 18:12
http://h<p:// <> http://http:<>//h<< ;;;"<<<<ttp://http://<><;
http://goo [quote]"<><http://[/quote]gle.com
32
Name:
test
2010-02-20 18:14
33
Name:
test
2010-02-20 18:15