|
yay, thanks for that catch. I have one more problem im running into. How can i check the values next to each in an array? say, if this would be how it is saved in the array quote:
I need to be able to check the value for each adjacent item in the array. Is this possible, and any hint on how to do it?
|
# ? Apr 10, 2008 23:59 |
|
|
# ? May 11, 2024 13:04 |
|
Drumstick posted:yay, thanks for that catch. Your question makes me unsure whether you understand what's going on here, so I'm being intentionally general to make sure we're not doing your homework for you or something. If you're having trouble, draw a picture of one of your grids and label each row and column with an index, then try and generalize to the question I asked above. There's one catch: you'll want to check that each of your four/eight adjacent points are inside the matrix, but what you want to do about that will depend on whether you want to wrap around on edges or just drop them.
|
# ? Apr 11, 2008 00:43 |
|
Incoherence posted:There's one catch: you'll want to check that each of your four/eight adjacent points are inside the matrix, but what you want to do about that will depend on whether you want to wrap around on edges or just drop them. I've always wondered what people do when you just want to drop them. In the past I've surrounded that block of code with a try/catch that doesn't do anything when an IndexOutOfBoundsException is thrown.
|
# ? Apr 11, 2008 03:20 |
|
Incoherence posted:Suppose the point in question is lifegame[x][y]. What are the indices of the four adjacent points (or eight, if you want to go that way)? if i understand what your asking, you want the positions of the 8 adjacent 'boxes' quote:
Im assuming this is what you meant by that. As for checking, they will need to drop off and not wrap around. Let me know if i understood what you were asking.
|
# ? Apr 11, 2008 03:28 |
|
MEAT TREAT posted:I've always wondered what people do when you just want to drop them. In the past I've surrounded that block of code with a try/catch that doesn't do anything when an IndexOutOfBoundsException is thrown. code:
Drumstick posted:if i understand what your asking, you want the positions of the 8 adjacent 'boxes' quote:As for checking, they will need to drop off and not wrap around. Let me know if i understood what you were asking.
|
# ? Apr 11, 2008 04:20 |
|
haha, yeah thanks for helping point my mind in the right direction. as soon as i drew it out and worked it out I saw a possible way to do it. Thank you so much.
|
# ? Apr 11, 2008 04:22 |
|
Incoherence posted:If I ever saw anyone use a try/catch I'd go put it in the Coding Horror thread posthaste. You are right, I was too quick to post. Here is what I actually meant, I had an algorithm that would traverse the array diagonally. The problem I had was dealing with 01, 02, 04, 06, 08, and 09. So I put it in a try catch and let it keep doing it's thing. 01 02 03 04 05 06 07 08 09 As I posted this I realized that I could check to see if it was out of bounds and just use the continue statement.
|
# ? Apr 11, 2008 05:17 |
|
Would anyone know why this bit of code won't worry on a blackberry?code:
Is there a better way to accomplish this? Edit: I'm sorry if this isn't the right thread for this, given my code is JavaScript on a webpage. Treytor fucked around with this message at 07:55 on Apr 11, 2008 |
# ? Apr 11, 2008 07:52 |
|
To rephrase my question, can anybody recommend a free Java FTP client class that supports upload progress monitoring and can abort uploads? Apache's client can let me monitor the progress, but aborting doesn't seem to work...
|
# ? Apr 11, 2008 09:58 |
|
Treytor posted:Would anyone know why this bit of code won't worry on a blackberry? Please try the Small web dev questions thread.
|
# ? Apr 12, 2008 12:25 |
|
Fehler posted:To rephrase my question, can anybody recommend a free Java FTP client class that supports upload progress monitoring and can abort uploads? Apache's client can let me monitor the progress, but aborting doesn't seem to work... Check out JSCH (Java Secure Channel) at http://www.jcraft.com/jsch/. I know for sure it has progress monitoring, but I'm not certain if it lets you abort uploads and I can't find it on the site. I use it for SFTP uploads/downloads and it works really nicely.
|
# ? Apr 13, 2008 17:10 |
|
Anybody out there able to guess what my university lecturer means by "shrink-wrap the window"? It's a Java Swing exercise so I was thinking maybe it's referring to some feature that me and Google don't know about. [image removed - in fact never mind, this stupid poo poo isn't worth anybody's time] InvSqrt fucked around with this message at 17:47 on Apr 13, 2008 |
# ? Apr 13, 2008 17:22 |
|
Maybe he means calling the pack method on the window. Window.pack()
|
# ? Apr 13, 2008 17:50 |
|
Hi, I am fiddling with the java scripting interface. As I understand the rhino engine is packaged with the jdk but what I don't understand is how does one reconcile the objects one gets from their engine (e.g. sun.org.mozilla.javascript.internal.ScriptableObject) versus the ones in the rhino api (e.g. org.mozilla.javascript.ScriptableObject)? Is the one in the jdk heavily modified or wrappered up to suit their javax.scripting interface? More specifically, how do I manipulate javascript objects from java? e.g. suppose I have this java code: code:
Looking at the Rhino API obviously you normally get a org.mozilla.javascript.ScriptableObject and can call the .get() .getIds() methods. But I don't know how to translate the objects I am getting in my actual java code which uses the jdk engine into org.mozilla.javascript objects. Is this even possible? Am I misunderstanding something completely? Should I just be using the rhino js jar and not the javax.scripting interface? If so, for what reason is the javax.scripting interface implemented?
|
# ? Apr 15, 2008 03:40 |
|
^^ You need to look up the javax.script.Bindings class. That is how you pass variables back and forth between a script and the host java program.
|
# ? Apr 15, 2008 04:57 |
|
TRex EaterofCars posted:^^ You need to look up the javax.script.Bindings class. That is how you pass variables back and forth between a script and the host java program. sorry, but can you give me a concrete example of what you mean? As far as I can tell getting the Bindings will allow me to get a java reference to the javascript object - but I already do this using the jsEngine.get("foo"). What I want to know is how do I manipulate it? For instance, how would I get a value given a key, or list the keys?
|
# ? Apr 15, 2008 05:41 |
|
Not anything Java specific but Eclipse is a Java thing sort of so whatever. Eclipse at this point is the only IDE I'll ever use in a long time, yet this bug pops up once in a while and I waste about an hour loving with it. It pops up randomly, but sometimes it doesn't recognize a class in the entire code or just a single line. I clean and build and everything but it doesn't go away. The code will still compile because javac isn't as retarded as Eclipse but I depend on IntelliSense quite a bit when I don't have a javadoc on hand. If it still compiles I suppose it isn't a big problem, but it happened one too many times and I just want to get rid of it. EDIT: I'll throw in a real problem too, I guess. I'm using a Combobox on a GUI I've created, and whenever I fill the combobox up, the little down arrow button on the right of it disappears. I do a repaint on the componenet but nothing. Then again, I really don't understand repaint that well as everytime I tried to use it, it never really works for me. ShinAli fucked around with this message at 18:01 on Apr 15, 2008 |
# ? Apr 15, 2008 17:58 |
|
ShinAli posted:It pops up randomly, but sometimes it doesn't recognize a class in the entire code or just a single line. I clean and build and everything but it doesn't go away. I might have the error too, if you add a space in front of the 'package a.b.c;' to make it ' package a.b.c;', does it go away? Because if so, that's the only means I've found of getting rid of it.
|
# ? Apr 15, 2008 18:10 |
|
ShinAli posted:I'm using a Combobox on a GUI I've created, and whenever I fill the combobox up, the little down arrow button on the right of it disappears. I do a repaint on the componenet but nothing. Then again, I really don't understand repaint that well as everytime I tried to use it, it never really works for me. Have you tried calling revalidate on the panel it's in?
|
# ? Apr 15, 2008 19:36 |
|
Twitchy posted:Have you tried calling revalidate on the panel it's in? I'll try it right now. ShinAli fucked around with this message at 21:14 on Apr 15, 2008 |
# ? Apr 15, 2008 21:12 |
|
ShinAli posted:I'll try it right now. That didn't work This is how I fill up the combobox code:
|
# ? Apr 15, 2008 23:24 |
|
Simple question I think. I have a very long string, that I want to take all n-length substrings out of and place into an array. For example if n is 5 and the sentence is "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt whatever", I would want string one to be "Lorem ipsum dolor sit amet," , string two to be "ipsum dolor sit amet, consectetur", string three to be "dolor sit amet, consectetur adipisicing", and so on. What would be the best way to go about this? I am having a hard time getting anything to work really.
|
# ? Apr 17, 2008 05:34 |
|
clayburn posted:Simple question I think. I have a very long string, that I want to take all n-length substrings out of and place into an array. For example if n is 5 and the sentence is "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt whatever", I would want string one to be "Lorem ipsum dolor sit amet," Smells like homework. You probably want to take a look at the String.split method, or the StringTokenizer class. Before writing code, however, you should think about the problem and devise a strategy to tackle it. Think about what loops you'll need where (assuming recursion isn't in the picture yet). Wouldn't it be nice if all the words in your string were in an array that you could loop over? epswing fucked around with this message at 07:50 on Apr 17, 2008 |
# ? Apr 17, 2008 05:54 |
|
Haha it might be homework. I really just needed a point in the right direction like you gave, just some methods to look at. I've considered putting the words in some sort of array, I'm just worried about the efficiency of putting them there in the first place. I'll definitely check those methods out though, thanks.
|
# ? Apr 17, 2008 14:46 |
|
clayburn posted:Simple question I think. I have a very long string, that I want to take all n-length substrings out of and place into an array. For example if n is 5 and the sentence is "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt whatever", I would want string one to be "Lorem ipsum dolor sit amet,"
|
# ? Apr 17, 2008 15:06 |
|
clayburn posted:Haha it might be homework. I really just needed a point in the right direction like you gave, just some methods to look at. I've considered putting the words in some sort of array, I'm just worried about the efficiency of putting them there in the first place. I'll definitely check those methods out though, thanks.
|
# ? Apr 17, 2008 18:37 |
|
adante posted:sorry, but can you give me a concrete example of what you mean? As far as I can tell getting the Bindings will allow me to get a java reference to the javascript object - but I already do this using the jsEngine.get("foo"). What I want to know is how do I manipulate it? For instance, how would I get a value given a key, or list the keys? Bindings implements Map, so you'll be able to iterate over the entries just like Map: code:
|
# ? Apr 17, 2008 21:42 |
|
Popping in not for Java coding help, but NetBeans: Anybody know how to set the contents of a JComboBox from an array or list? There's a box to type your "pre-generation code," but I really don't know what to put there, and it's surprisingly hard to find clear instructions online.
|
# ? Apr 17, 2008 22:49 |
|
clayburn posted:Haha it might be homework. I really just needed a point in the right direction like you gave, just some methods to look at. I've considered putting the words in some sort of array, I'm just worried about the efficiency of putting them there in the first place. I'll definitely check those methods out though, thanks. You could tokenize the string like epswing said, or you can use the Matcher and Pattern classes (Regex) to do it for you, might aswell learn in now since it's incredibly useful. Basically what you want to search for is: 1 or more non-space characters, followed by an optional white space character, repeated 5 times. http://java.sun.com/docs/books/tutorial/essential/regex/index.html is an ok place to learn Regex in Java. I had a little shot at it and it's a pretty simple regular expression so once you know the basics it will be a piece of cake.
|
# ? Apr 17, 2008 23:35 |
|
Werthog posted:Popping in not for Java coding help, but NetBeans: Anybody know how to set the contents of a JComboBox from an array or list? There's a box to type your "pre-generation code," but I really don't know what to put there, and it's surprisingly hard to find clear instructions online. ShinAli posted:
Like every other Java Swing component, you'd have to jump through hoops and set up a model for ComboBox. Luckily, there is a default model that'll just take in an array of Strings in the constructor. Declaring or using an DefaultComboBoxModel object in the custom code text box should make it work.
|
# ? Apr 17, 2008 23:43 |
|
ShinAli posted:Like every other Java Swing component, you'd have to jump through hoops and set up a model for ComboBox. Luckily, there is a default model that'll just take in an array of Strings in the constructor. Declaring or using an DefaultComboBoxModel object in the custom code text box should make it work. Thanks. While waiting for this answer, I was screwing around with some other part of my project, and just happened to glance at some auto-generated code that helped me figure that out for myself, but having the full answer here helps, too. Now I've graduated to trying to make a table model for a JDBC connection. Fun stuff.
|
# ? Apr 18, 2008 01:22 |
|
TRex EaterofCars posted:Bindings implements Map, so you'll be able to iterate over the entries just like Map: ok, I am feeling a little silly to ask this, but could you provide me with EXACT CODE WHICH WILL COMPILE to do what I want, because I cannot see how to apply the bindings method (which is an engine method to the object o in my previous code listing.
|
# ? Apr 18, 2008 01:31 |
|
adante posted:ok, I am feeling a little silly to ask this, but could you provide me with EXACT CODE WHICH WILL COMPILE to do what I want, because I cannot see how to apply the bindings method (which is an engine method to the object o in my previous code listing. code:
|
# ? Apr 18, 2008 06:56 |
|
hey wiz posted:What else do you want, he pretty much gave you the code. If you want to iterate over each entry, probably you will want something like this: well as I said, I basically want the exact code which will compile. Either I have a fundamentally flawed view of the scripting API (and I am certainly not discounting this) or you guys are misunderstanding what I am asking for. I want to manipulate a javascript object by getting its keys and values. The only way I can see how to use the code you guys have given me is to manipulate the javascript ENGINE, allowing me to get its variables. This is great, I got the variable I wanted, a javascript object, in my first post, under the code line which goes "Object o = jsEngine.get("foo");". Now I want to get the keys and values of that object. I'm no expert with java and maybe you can use the Bindings class in a way to interrogate this object o. Unfortunately I have absolutely no idea how to do this because I cannot see any way to get a Bindings object relevant to o. Hence, I asked for some exact code which I could compile so that I could either figure out exactly how to use the bindings class (if this is infact the case) or confirm that there has been a misunderstanding and I need to clarify. In order to hopefully clarify exactly what I want, here's a skeleton template: code:
code:
code:
code:
|
# ? Apr 18, 2008 12:44 |
|
Not really a question but I thought it'd be a useful little tid bit to post. In all of my time of using Java, I've always assumed passing Objects in method parameters will pass by reference and primitives pass by value. This is actually not the case at all. Everything is passed by value. This doesn't mean what you think about Objects though, as the references to the Objects themselves are the ones that are passed by value. Here is an example: code:
Sorry if most of you all already knew this, but I think it's something useful to know for a the newbie passer-by Java programmers. It blew my mind to the point I'll always remember this and will never make a mistake like that.
|
# ? Apr 18, 2008 21:19 |
|
^^ Edit: Misunderstood you! I think you've got it a little confused, primitives are passed by value, objects are passed by reference. Passing by value means the method has it's own copy, so even if the variable is changed during the method, it will not have an effect on the parameter that was passed in. Objects on the other hand, pass by reference, meaning any changes you make to them inside a method will change the same object you passed into the method. When you set temp to null in that method, you are only saying that the variable no longer references the object. temp basically says "if you want to see what i contain, goto this location in memory", so when you it's set to null it just says "i don't refer to anything ", but the location in memory still exists because there is another reference to it in the other method. Jesus... I could never be a teacher. Twitchy fucked around with this message at 22:11 on Apr 18, 2008 |
# ? Apr 18, 2008 21:37 |
|
Twitchy posted:I think you've got it a little confused Actually he's got it exactly right. The reference to the object is passed by value; you can modify the object, but not the reference to it.
|
# ? Apr 18, 2008 22:02 |
|
csammis posted:Actually he's got it exactly right. The reference to the object is passed by value; you can modify the object, but not the reference to it. I think it was me being a little confused about what he meant then heh. It's still passed by reference though really, saying it's passed by value just because it's reference is stored in a variable is more likely to confuse a new programmer than help them, that's all. I thought he thought (I thought that he thought that he thought) that because he set the variable to null but the other variable reference was fine that each method had it's own copy of the object / value. Twitchy fucked around with this message at 22:12 on Apr 18, 2008 |
# ? Apr 18, 2008 22:04 |
|
Yeah I think I need to re-write it Does "pass by reference" usually mean passing by value the copy of the reference? Or does real "passing by reference" mean that you can modify the original reference? If it's the former, then Objects passing by reference is actually correct and I'm just retarded
|
# ? Apr 18, 2008 22:14 |
|
|
# ? May 11, 2024 13:04 |
|
ShinAli posted:Yeah I think I need to re-write it Yeah, passing by reference is assigning a variable to a location in memory, so setting it to null will not actually remove it (unless no other variables reference it, in which case it would be garbage collected). You are right though, technically the reference IS passed by value, meaning you can set it too null and other references will be fine, but I think it can be a rather confusing thing to get, especially for new programmers where there needs to be a clear distinction between values (primitives) and objects.
|
# ? Apr 18, 2008 22:19 |