Java Forum / General / April 2006
integers and arrays in Java - how?
Robert Baer - 30 Mar 2006 11:20 GMT I used Google and found some references for integer in Java. But "int" not only does not work, it also prevents reading X and Y coordinates of the mouse. What i would like to do: 1) Get X and Y mouse coordinates into a variable that i can do real math on. So far, i can do math on the values "read" and that result goes into a "variable" that is useful *only* for display. If i try "int" in that math, the values are then zero for everything - even those where i do no calculation. 2) Use the calculated integer values as an index to a table or array. It is acceptable to use an HTML "table" as the source for the lookup; W(CalcFromX) and P(CalcFromX) would be the resulting values to be displayed on the screen somewhere.
Can this be done, and eXactly how?
Oliver Wong - 30 Mar 2006 16:03 GMT > I used Google and found some references for integer in Java. > But "int" not only does not work, it also prevents reading X and Y [quoted text clipped - 12 lines] > > Can this be done, and eXactly how? I didn't understand your question at all. Perhaps you can post an SSCCE? http://mindprod.com/jgloss/sscce.html
Be sure to specify what results you expected your program to produce, and what results you actually got, and how they differed.
- Oliver
Robert Baer - 31 Mar 2006 11:47 GMT >> I used Google and found some references for integer in Java. >> But "int" not only does not work, it also prevents reading X and Y [quoted text clipped - 20 lines] > > - Oliver I *thought* i mentioned what i wanted to do, as well as "int" not only does not work, it kills the reading of mouse XY coordinates. And i would have no clue as if the code was compilable or not, and i do not think i care, since the jave code is a part of an HTML web page. However, i will copy the code i have across from my other OS drive later.
Oliver Wong - 31 Mar 2006 15:52 GMT >>> I used Google and found some references for integer in Java. >>> But "int" not only does not work, it also prevents reading X and Y [quoted text clipped - 26 lines] > However, i will copy the code i have across from my other OS drive > later. Since the code is "part of an HTML web page", might you be talking about JavaScript, rather than Java?
- Oliver
Robert Baer - 06 Apr 2006 07:58 GMT >>>> I used Google and found some references for integer in Java. >>>> But "int" not only does not work, it also prevents reading X and Y [quoted text clipped - 32 lines] > > - Oliver I have been sick since Saturday, and that is why i have not posted anything. From others, i discovered that you are correct; Java Script.
Oliver Wong - 06 Apr 2006 14:44 GMT >> Since the code is "part of an HTML web page", might you be talking >> about JavaScript, rather than Java? >> > I have been sick since Saturday, and that is why i have not posted > anything. Hope you're feeling better now.
> From others, i discovered that you are correct; Java Script. Okay, you can probably ignore most of the advice you've received here (e.g. "class" is a concept which only exists in Java, and not in JavaScript). Probably best if you repost your question at a JavaScript newsgroup like comp.lang.javascript.
- Oliver
Robert Baer - 06 Apr 2006 22:07 GMT >>> Since the code is "part of an HTML web page", might you be talking >>> about JavaScript, rather than Java? [quoted text clipped - 12 lines] > > - Oliver Thanks!
Evan Stratford - 30 Mar 2006 18:03 GMT > I used Google and found some references for integer in Java. > But "int" not only does not work, it also prevents reading X and Y [quoted text clipped - 11 lines] > > Can this be done, and eXactly how? I'm taking a broad guess here, seeing as how your description is vague, but...what you probably want is something along the lines of this:
public MyClass implements MouseMotionListener {
// constructors and other methods...
// MouseMotionListener methods public void mouseMoved(MouseEvent e) { Point p = e.getPoint(); doSomeCalculation(p); }
public void mouseDragged(MouseEvent e) { /* more stuff here if necessary */ }
}
Alternatively, if called from within a class that extends some subclass of java.awt.Component:
public MyClass extends JFrame { public MyClass( /* parameters */) { addMouseMotionListener(new MouseMotionListener() { public void mouseMoved(MouseEvent e) { Point p = e.getPoint(); doSomeCalculation(p); } public void mouseDragged(MouseEvent e) { /* ... */ } }); }
}
The doSomeCalculation(Point p) method could provide, say, a mapping from regions to elements of a table, e.g. with the java.awt.Rectangle contains() method.
Hope this helps; if not, you might want to be more specific!
Evan Stratford 1B CompSci/SoftEng option University of Waterloo
Robert Baer - 31 Mar 2006 11:54 GMT >> I used Google and found some references for integer in Java. >> But "int" not only does not work, it also prevents reading X and Y [quoted text clipped - 60 lines] > 1B CompSci/SoftEng option > University of Waterloo WHat you gave might be useful to someone, but "class"? and "method"? and why bother to create what might be some kind of a function if a calculation is neededin only one place? The "do some calculation" bit is what is troubling; "int" does not work and kills reading of mouse XY coordinates. I will copy across the HTML / Java code i have from the OS and drive it is on, for show.
Sigmund Hansen - 31 Mar 2006 15:55 GMT >>> I used Google and found some references for integer in Java. >>> But "int" not only does not work, it also prevents reading X and Y [quoted text clipped - 68 lines] > I will copy across the HTML / Java code i have from the OS and drive > it is on, for show. Can't you just grab the coordinates from the Point? Method is another name for member function... What exactly do you mean by "'class'?"? Don't you know what a class is? Anyway, if you don't want to use a function, then just put the content of the function where he used one...
Robert Baer - 06 Apr 2006 07:59 GMT >>>> I used Google and found some references for integer in Java. >>>> But "int" not only does not work, it also prevents reading X and Y [quoted text clipped - 76 lines] > if you don't want to use a function, then just put the content of the > function where he used one... No, i have no clue what a "calss" is, or how to do what you mentioned.
Sigmund Hansen - 31 Mar 2006 15:58 GMT >>> I used Google and found some references for integer in Java. >>> But "int" not only does not work, it also prevents reading X and Y [quoted text clipped - 68 lines] > I will copy across the HTML / Java code i have from the OS and drive > it is on, for show. Oh yeah, I forgot: to get the X and Y coordinates just use:
snippety snippety snip ...
Point p = e.getPoint(); int x = p.getX(); int y = p.getY();
snippety ...
The getX and getY functions will return the ints of the Point you got from the mouseEvent in Evan's code...
Ian Shef - 03 Apr 2006 20:19 GMT Sigmund Hansen <sigmunha@student.hf.uio.no> wrote in news:qsbXf.8452$zc1.6768 @amstwist00:
> Oh yeah, I forgot: > to get the X and Y coordinates just use: [quoted text clipped - 9 lines] > The getX and getY functions will return the ints of the Point you got > from the mouseEvent in Evan's code... Wrong! Sorry, but I just got caught by this the other day.
The methods getX() and getY() in java.awt.Point each return a double !
Your code should look more like:
Point p = e.getPoint(); int x = p.x; int y = p.y;
x and y are public int fields of Point.
 Signature Ian Shef 805/F6 * These are my personal opinions Raytheon Company * and not those of my employer. PO Box 11337 * Tucson, AZ 85734-1337 *
Sigmund Hansen - 03 Apr 2006 20:53 GMT > Sigmund Hansen <sigmunha@student.hf.uio.no> wrote in news:qsbXf.8452$zc1.6768 > @amstwist00: [quoted text clipped - 24 lines] > > x and y are public int fields of Point. Yeah I noticed that a bit later, but figured it was a bit late to post another correction... Didn't know they were public, but that might explain why it has integer coordinates whose get methods return doubles...
Anyway, it doesn't apply to this because he's coding JavaScript... (BTW, I haven't actually coded in years, so my memory on classes and functions in even the standard API is kind of nasty, and for that matter deprecated. But I'm starting back up now, trying to learn some LWJGL and such, hopefully it will be fun, and not just time consuming (time being something I don't have a lot of))... ;)
Robert Baer - 06 Apr 2006 08:01 GMT >>>> I used Google and found some references for integer in Java. >>>> But "int" not only does not work, it also prevents reading X and Y [quoted text clipped - 82 lines] > The getX and getY functions will return the ints of the Point you got > from the mouseEvent in Evan's code... I will try that, but am not enthused as "int" seems to not work but worse, kill everything else JavaScript wise..
Robert Baer - 31 Mar 2006 23:44 GMT > I used Google and found some references for integer in Java. > But "int" not only does not work, it also prevents reading X and Y [quoted text clipped - 12 lines] > > Can this be done, and eXactly how? Here is the code i have so far: <html code starts here; this is altered to help protect some> <head> <title>Test page</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link rel="stylesheet" type="text/css" href="style.css"> </head>
<!-- var with "Netscape" makes Netscape happy adding "int" or "integer" in any way totally kills operation --> <SCRIPT LANGUAGE="JavaScript"> <!-- var isNav = (navigator.appName.indexOf("Netscape") !=-1); function handlerMM(e){ Xmm = (isNav) ? e.pageX : event.clientX; Ymm = (isNav) ? e.pageY : event.clientY; document.dataholder.mmX.value=((Xmm-173)/6.8+1938); document.dataholder.mmY1.value=Ymm; document.dataholder.mmY2.value=Xmm; document.dataholder.mmZ.value=((Xmm-173)/6.8+1938); } if (isNav) { document.captureEvents(Event.MOUSEMOVE); } document.onmousemove = handlerMM; // --> </SCRIPT>
<body> <center> <form name="dataholder"> <table border=1> <tr> <td><i>Year(wide)</i></td> <td><input type="text" size=9 name="mmX" value="0"></td> <td><i>Year(narrow)</i></td> <td><input type="number" size=3.8 name="mmX" value="0"></td> <td><i>Number of wells</i></td> <td><input type="text" size=5 name="mmY1" value="0"></td> <td><i>Production BBLs</i></td> <td><input type="text" size=5 name="mmY2" value="0"></td> <td><i>Z value</i></td> <td><input type="text" size=9 name="mmZ" value="0"></td> </tr> </table> </form> </div>
<!-- This code *used to* work, showing a calculated year in the first 2 boxes; the width of the second box was made narrow to visually "truncate" the numbers to integer. I have no idea as to why they no longer work. I added "Z value" and *that* works (!!). Go figure. -->
<table align="center"> <tr> <td align=center> <center> <div><i>© 2006 Oil 4 Less LLC</i></div> </center> </td> </tr> </table>
<!-- style and then img src as seperate items makes IE happy; GIF is 90% BMP --> <div style="position: absolute; height: 316px; width: 697px; top: 100px; left: 20px; " <style="height: 316px; width: 697px; top: 100px; left: 20px; " > <img src="Arkansas.gif" alt="" usemap="#AK" style="border-style:none" > </div>
</body> </html>
Sigmund Hansen - 02 Apr 2006 01:19 GMT >> I used Google and found some references for integer in Java. >> But "int" not only does not work, it also prevents reading X and Y [quoted text clipped - 92 lines] > </body> > </html> Yeah, this is JavaScript, which basically has nothing to do with Java... I believe there is some Object Orientation in it, but not as advanced as Java's. I'd recommend you go to the comp.lang.javascript group instead, or a similar one...
Robert Baer - 06 Apr 2006 08:02 GMT >>> I used Google and found some references for integer in Java. >>> But "int" not only does not work, it also prevents reading X and Y [quoted text clipped - 100 lines] > I'd recommend you go to the comp.lang.javascript group instead, or a > similar one... Thanks.
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|