a problem with putting simple function inside the class // simple question
in
Programming Questions
•
3 years ago
Hi.
I've got this simple function below and I can't put it inside the class. Must be outside, otherwise application won't compile. Says "
The function overCircle(float, float, int) does not exist.". Well, I refer to overCircle function later in another function which is outside the class as well, but still... Why overCircle function has also to be outside ?
Why is that ?
-
public boolean overCircle(float x, float y, int diameter) {float disX = (x*zoom) - mouseX;
float disY = (y*zoom) - mouseY;
if (sqrt(sq(disX) + sq(disY)) < diameter/2 ) return true;
else return false;
}
Here's the class, but I doubt it matters...
- class ExtraWindow extends PApplet implements WindowListener, ComponentListener {
public boolean overCircle(float x, float y, int diameter) {
float disX = (x*zoom) - mouseX;
float disY = (y*zoom) - mouseY;
if (sqrt(sq(disX) + sq(disY)) < diameter/2 ) return true;
else return false;
}
protected int width = 600;
protected int height = 200;
protected int x = 100;
protected int y = 100;
protected String myName;
protected String myTitle;
protected boolean isCoordinates = false;
protected boolean isLoop = true;
public final static int NORMAL = 0;
public final static int ECONOMIC = 1;
protected int myMode = NORMAL;
protected String myRenderer = "";
protected int myFrameRate;
boolean isUndecorated = false;
PApplet papplet;
public ExtraWindow(PApplet theApplet) {
super();
papplet = theApplet;
}
public ExtraWindow(PApplet theApplet, String theName, int theWidth, int theHeight) {
this(theApplet,theName, theWidth, theHeight, "", 30);
}
public ExtraWindow(PApplet theApplet, String theName, int theWidth, int theHeight, String theRenderer, int theFrameRate) {
super();
papplet = theApplet;
myName = theName;
myTitle = theName;
width = theWidth;
height = theHeight;
myFrameRate = theFrameRate;
myRenderer = theRenderer;
launch();
}
public ExtraWindow(PApplet theApplet, final String theName, int theX, int theY, int theWidth, int theHeight) {
this(theApplet, theName, theX, theY, theWidth, theHeight, "", 30);
}
public ExtraWindow(PApplet theApplet, String theName, int theX, int theY, int theWidth, int theHeight, String theRenderer, int theFrameRate) {
super();
papplet = theApplet;
myName = theName;
myTitle = theName;
width = theWidth;
height = theHeight;
x = theX;
y = theY;
myFrameRate = theFrameRate;
myRenderer = theRenderer;
launch();
}
public void setup() {
smooth();
setUndecorated(true);
if (myRenderer.length() == 0) {
size(width, height);
}
else {
size(width, height, myRenderer);
}
frameRate(myFrameRate);
}
public void draw() {
stroke(colorGre);
noFill();
triangle(0.1*zoom*zoom, 0.9*zoom*zoom, 0.5*zoom*zoom, 0.1*zoom*zoom, 0.9*zoom*zoom, 0.9*zoom*zoom);
//ew1.triangle(25.6, 230.4, 128, 25.6, 230.4, 230.4);
stroke(226,200,34);
rect(0,0,ew1.width-1,ew1.height-1);
stroke(127,127,127);
line(20,20,270,20); line(20,20,20,270);
line(20,70,270,70); line(70,20,70,270);
line(20,120,270,120); line(120,20,120,270);
line(20,170,270,170); line(170,20,170,270);
line(20,220,270,220); line(220,20,220,270);
line(20,270,270,270); line(270,20,270,270);
}
public Frame getFrame() {
return frame;
}
public String name() {
return myName;
}
public void setVisible(boolean theValue) {
if (theValue == true) {
frame.show();
}
else {
frame.hide();
}
}
public void setResizeable(boolean theValue) {
frame.setResizable(theValue);
}
public void setTitle(String theTitle) {
myTitle = theTitle;
updateTitle();
}
protected void updateTitle() {
String m = myTitle;
if(isCoordinates) {
m += " x:" + x + " y:" + y + " " + width + "x" + height;
}
frame.setTitle(m);
}
public String title() {
return myTitle;
}
public void showCoordinates() {
isCoordinates = true;
updateTitle();
}
public void hideCoordinates() {
isCoordinates = false;
updateTitle();
}
public void windowActivated(WindowEvent e) {
isLoop = true;
loop();
}
public void keyPressed(KeyEvent theKeyEvent) {
papplet.keyPressed(theKeyEvent);
}
public void keyReleased(KeyEvent theKeyEvent) {
papplet.keyReleased(theKeyEvent);
}
public void keyTyped(KeyEvent theKeyEvent) {
papplet.keyTyped(theKeyEvent);
}
int mX;
int mY;
public void mousePressed(){
if (mouseButton == RIGHT) {
if(isUndecorated) {
mX = mouseX;
mY = mouseY;
}
}
else {
if ( over > 0 ) drag = true;
}
}
void mouseDragged(){
if (mouseButton == RIGHT) {
if(isUndecorated) {
frame.setLocation(
MouseInfo.getPointerInfo().getLocation().x-mX,
MouseInfo.getPointerInfo().getLocation().y-mY);
}
}
else {
if (over == 0 ) return;
//if ((mouseX > 69) && (mouseX < 221) && (mouseY > 69) && (mouseY < 221)) {
if ( over == 1 ) p1 = new Point(mouseX/zoom, mouseY/zoom);
if ( over == 2 ) p2 = new Point(mouseX/zoom, mouseY/zoom);
if ( over == 3 ) p3 = new Point(mouseX/zoom, mouseY/zoom);
//}
}
}
void mouseReleased() {
drag = false;
}
public void windowClosed(WindowEvent e) {
// System.out.println("window closed");
}
public void windowClosing(WindowEvent e) {
dispose();
}
public void windowDeactivated(WindowEvent e) {
if (myMode == ECONOMIC) {
isLoop = false;
noLoop();
}
}
public void windowDeiconified(WindowEvent e) {
}
public void windowIconified(WindowEvent e) {
}
public void windowOpened(WindowEvent e) {
}
public void componentHidden(ComponentEvent e) {
}
public void componentMoved(ComponentEvent e) {
Component c = e.getComponent();
x = c.getLocation().x;
y = c.getLocation().y;
updateTitle();
}
public void componentResized(ComponentEvent e) {
Component c = e.getComponent();
// System.out.println("componentResized event from " +
// c.getClass().getName() + "; new size: " + c.getSize().width
// + ", " + c.getSize().height);
}
public void componentShown(ComponentEvent e) {
// System.out.println("componentShown event from " +
// e.getComponent().getClass().getName());
}
public void setMode(int theValue) {
if (theValue == ECONOMIC) {
myMode = ECONOMIC;
return;
}
myMode = NORMAL;
}
public void toggleUndecorated() {
setUndecorated(!isUndecorated());
}
public void setUndecorated(boolean theFlag) {
if (theFlag != isUndecorated()) {
isUndecorated = theFlag;
frame.removeNotify();
frame.setUndecorated(isUndecorated);
setSize(width, height);
setBounds(0, 0, width, height);
frame.setSize(width, height);
frame.addNotify();
requestFocus();
}
}
public boolean isUndecorated() {
return isUndecorated;
}
protected void dispose() {
stop();
removeAll();
frame.removeAll();
frame.dispose();
}
private void launch() {
GraphicsDevice displayDevice = null;
if (displayDevice == null) {
GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
displayDevice = environment.getDefaultScreenDevice();
}
frame = new Frame(displayDevice.getDefaultConfiguration());
// remove the grow box by default
// users who want it back can call frame.setResizable(true)
frame.setResizable(false);
init();
frame.pack(); // get insets. get more.
frame.setLocation(x,y);
Insets insets = frame.getInsets();
int windowW = Math.max(width, MIN_WINDOW_WIDTH) + insets.left + insets.right;
int windowH = Math.max(height, MIN_WINDOW_HEIGHT) + insets.top + insets.bottom;
frame.setSize(windowW, windowH);
frame.setLayout(null);
frame.add(this);
int usableWindowH = windowH - insets.top - insets.bottom;
setBounds((windowW - width) / 2, insets.top + (usableWindowH - height) / 2, width, height);
frame.setAlwaysOnTop(true);
frame.addWindowListener(this);
frame.addComponentListener(this);
frame.setName(myName);
frame.setTitle(myName + " x:" + x + " y:" + y + " w:" + width + " h:" + height);
frame.setVisible(false); // frame.setVisible(true);
requestFocus();
}
}
1