I hate to ask something so trivial, but I can't work this one out. I'm trying to create a basic object for convenience, like this:
triangle = {
side: { A: 0, B: 0, C: 0 },
angle: { a, b, c },
function calcAngle(){}
}
Ideally, I'd like to just create a generic object on the fly. I'm only creating one "triangle", must I create a whole class for one instance? I'm sure this is answered somewhere, but I can't seem to word the question right for anything useful. For your amusement I'll post some of my failures:
public class TGUI{
// Attempt One
public Object triangle = new Object(){ int test; };
public static void main(String[] args) {
triangle.test = 1;
// ^- Cannot make a static reference to the non-static field triangle
triangle tri = new triangle();
// ^- Made the compiler cry; triangle cannot be resolved to as type
}
// Attempt Two
public class triangle{ int test; }
public static void main(String[] args) {
triangle tri = new triangle();
/* ^- No enclosing instance of TGUI is accessible. Must qualify the allocation with an enclosing instance of type TGUI (eg x.new A() where x is an instance of TGUI) */
}
// Attempt Three
public void triangle(){ int test = 1; }
public static void main(String[] args) {
triangle tri = new triantle();
// ^- triangle cannot be resolved to a type
}
// Attempt Four
public TGUI(){ int test; }
/* I'm gonna quit here, you get the idea */
}
doublevalues?