|
rileylolz posted:For class, we've been assigned to make an 8x8 board for various pieces to move around on. I've run into a problem with user input, specifically dealing with how to handle tokens. I'm using Scanner to break up the input, but the problem is the largest command will have 5 tokens and the shortest will only have one. The way it's set up now is that it needs a command that will use all 5 tokens or else it crashes. Lazy way would be to catch the exception and ignore it. The more proper way would be to have a count=0 outside of the switch statement. Then have a switch statement based off what count it is. After the switch increment the count. You could probably get rid of the loop also with a series of ifs as well. You would check hasNext() and if true whatever equals next()
|
# ¿ Feb 20, 2009 06:05 |
|
|
# ¿ Apr 27, 2024 17:36 |
|
Keeper of Bees posted:image stuff If you are using a BufferedImage you should be able to get a Grapics2D object out of it and IIRC it has some rotate methods. If all you are doing is what is in your example though it should be hard to do manually. From your example, get the dimensions of your array using array.length and array[0].length. From that create a new array flipping the dimensions. Fill the second array using the standard double for loops just do array2[j][i] = array[i][j]. Or something to that effect.
|
# ¿ Mar 8, 2009 20:28 |
|
I don't normally write applets so I need some help with this badly. I have an applet that is hosted in in Tomcat that needs to communicate with a servlet on the same server. The servlet feeds the applet with the required data it uses for processing. Here is how I connect it : code:
Now I understand all the restrictions with applets. I know they can't communicate with just any server and can't modify local files. But they are suppose to be able to communicate with a remote server IF the applet was downloaded from there, right? Any ideas? I got to get live data to the applet to be displayed. edit: the error is thrown at "conn = url.openConnection();" edit2: gently caress me.... figure it out.... when I was testing poo poo locally again I set the URL ip to my machines IP instead of localhost. When I tried to connect to it from my local Tomcat server I reached it via localhost:8080 instead of with my IP address. Not only can't applets communicate with remote servers, the url have to be the same I guess. So if you hard code a IP into the URL object and try to access the page it sits in via a DNS address the applet will break, right? So I need to use JSP or my web.xml file to pass the url context incase it moves or for we set up a dns for it. I wish it was smarter then that. lamentable dustman fucked around with this message at 16:50 on Mar 10, 2009 |
# ¿ Mar 10, 2009 16:27 |
|
It wasn't so much whining as me bitching because of my own stupidity and taking a couple hours to figure it out. Mostly because I wrote a long post then figured it out 5 minutes later, as happens whenever I post here. Anyways, what I do now is write a little jsp to do the following code:
|
# ¿ Mar 10, 2009 20:20 |
|
Sorry, missed understood what you meant there. Didn't know there was a method for that. I'll update that, thanks for the tip. Like I said, I don't do applets generally, I just happened to make a mistake of showing my boss some of the features of the library I was using (JFreeChart). I was originally going just server some static pictures, from a servlet, representing weather data. I showed him some of the applet and dynamic features of it and next thing I know I'm making applets. Just trying to hack my way trough this poo poo and be done with applets for good and focus on backend stuff again.
|
# ¿ Mar 10, 2009 21:30 |
|
ayb posted:stuff When arrays are declared they have to have a set size because sequential memory is allotted to them when instantiated. They can not grow past that size otherwise you will get an array out of bounds error. If you need the array to be dynamic and grow based on the amount of items you will either need to use a different data structure (ArrayList). You could also create a function that returns an array of the correct size with the new item in it (google java growing array). Obviously use an ArrayList assuming advance data structures are allowed in your class. lamentable dustman fucked around with this message at 23:33 on Mar 26, 2009 |
# ¿ Mar 26, 2009 23:29 |
|
ayb posted:I understand now. I emailed the professor and he said to just use a fixed size and not do anything more advanced yet. I have it set and I can enter my numbers but I still can't get it to sum up or tell me what's the biggest take a look at these lines: code:
|
# ¿ Mar 26, 2009 23:44 |
|
To add what Mill Town said, from looking at your code snippit I don't think you know what an interface really is. Think of it as a template for functions for your code. When you implement the interface you must include your implementation of those methods in your code. Look at the jdoc for Comparable ( http://java.sun.com/javase/6/docs/api/java/lang/Comparable.html ). You see how the only method listed is 'int compareTo(T o)'? That means you must must include a method called compareTo that returns an int somewhere in your code. That is why you are getting the exception. As for how to implement the function, nobody is going to do your homework but here is a hint. What primitive type makes up a String object? And what other kind of primitive type can it be represented as?
|
# ¿ Apr 21, 2009 01:33 |
|
Mill Town posted:He doesn't even need to get that dirty, there's a perfectly good compareTo function already in String that he can use to do the dirty work... yea, i know that of course, but judging by the fact that the instructor wants him to implement the Comparable interface I think he is suppose to roll his own
|
# ¿ Apr 21, 2009 01:38 |
|
As far as I know you can't upload more then one file at a time in JavaScript/HTML. There are AJAX hacks around this but it is still but you still need to open that dialog box for every single file you want uploaded. If you want to do a batch upload (whole folders or whatever) you would need to use a signed applet
|
# ¿ May 27, 2009 16:02 |
|
zootm posted:It's a pity to have to spin up a JVM for such a small use-case but as dvinnen points out it's something that browsers simply can't do. HTML 5 (lol) should fix that when/if it ever comes out 1337JiveTurkey posted:For the purposes of making a file uploader, a JNLP-launched applet would work. JNLP allows a slightly larger set of permissions than plain applets such as to create a file open dialog. You would still need to sign it but JNLP is cool and a good way to package an applet. Makes using extensions like Java3D a breeze. lamentable dustman fucked around with this message at 19:13 on May 27, 2009 |
# ¿ May 27, 2009 19:10 |
|
almostkorean posted:Can someone help me understand how java passes in objects into functions? My previous understanding was that everything is passed by value and you can't pass by reference. But I'm working on this program where I'm using a union find data structure (it basically just holds a hashmap) and I'm doing something like this: simply put, objects are by reference and primitives are by by value not exactly but close enough
|
# ¿ Jun 24, 2009 19:45 |
|
karuna posted:I had them in separate files within a package, I just created a new package and is compiling fine now. take a look at the java order of precedence
|
# ¿ Oct 15, 2009 22:31 |
|
oval office.exe posted:
why? that is fine, it is printing out the same number 50 times because he is passing an int as x and only gets set once per thread
|
# ¿ Oct 16, 2009 14:56 |
|
tef posted:Any recommended json libraries or such? I use the one included with DWR but not sure how it compares to anything else, just wanted to make a GeoJSON library for a GIS project and was already using DWR for some AJAX poo poo. It is more geared for building JSON then parsing it though. (there is a bug in the DWR 3.0 RC1 distribution with JSON, if you go that route build a nightly)
|
# ¿ Dec 10, 2009 16:56 |
|
FunOne posted:Ok, so I'm building an application that needs to store a time of day (IE, 2:00pm) and it links back to a database so I should use java.util.Date rather than constructing something. There is java.sql.Date that is pretty much that. A thin date object for for jdbc that handles the translations.
|
# ¿ Jan 15, 2010 00:21 |
|
look here for the error:code:
e: yea, forgot to mention that, your style is horrible. Stay way from bracket-less statements lamentable dustman fucked around with this message at 17:28 on Jan 25, 2010 |
# ¿ Jan 25, 2010 17:23 |
|
GregNorc posted:OK so I'm guessing it's something relating to scope? (I was getting 4 for the first test sin ce 45/10 = 4.5 and since the result is an int, it gets truncated to 4, hence the appearance it was working?) You are thinking to far ahead. Focus on one error at a time. In the iteration of the code you posted the biggest error in the code is the infinite loop that is causing the "hanging." Follow the debugging steps rjmccall posted and remember to take things one at a time. Using sys outs or a debugger to pinpoint your problems couldn't hurt either.
|
# ¿ Jan 25, 2010 19:40 |
|
Several ways to do it I guess. I would probably do a nextInt() mod 2. If 0 multiply the random double by -1, else just leave it positive
|
# ¿ Jan 30, 2010 03:16 |
|
Internet Janitor posted:The simple way is to do ((Math.random() * 2) -1). yea, this is much better, don't answer in this thread while on the phone... fake edit: if you think about it this would be less random then Random is already is because the least significant digit will always be even, theoretically (in my mind) at least.
|
# ¿ Jan 30, 2010 03:59 |
|
Azerban posted:I've got an applet embedded in a webpage that works perfectly on Windows machines, but absolutely nothing shows up on Linux machines, just a blank page. Any idea what could be causing this? Did you set up Firefox or whatever to use the Java plugin? about :plugins to check You have to do it manually in linux
|
# ¿ Feb 2, 2010 05:53 |
|
Ferg posted:So I haven't touched Java since college and I'm diving back in for an Android project that is coming up for work. Being that this is my first time doing legit Java work (and since Java 1.4) can anybody explain to me the proper naming conventions for packages? doesn't really matter as long as it meets your companies guidelines. Just make sure it is logically placed
|
# ¿ Feb 11, 2010 17:52 |
|
Azerban posted:I've got an applet that needs to connect to a MYSQL database that's sitting behind a firewall, maybe two. What is the best, and/or easiest, way to get this done? Is the server that is serving the applet able to reach the database? If so you can use a servlet to do connect to the database. If they aren't on the same server then the applet has to be signed. In the applet you would do something similar to: code:
code:
e: A couple things, you probably need a time out in the applet in case the servlet is down as it won't do anything till it gets a response from the servlet. If you need to pass a primitive to the servlet just use one of the wrapper classes. You can also only pass serializable objects back and forth. lamentable dustman fucked around with this message at 18:17 on Feb 11, 2010 |
# ¿ Feb 11, 2010 18:13 |
|
fletcher posted:Looking for a way to generate some charts in Java and output to an image. JFree looks pretty sweet, anything else I should check out before diving in? Used it before, it works really well but the documentation sucks and is built around buying his book. Probably worth it but if you're cheap like me (or rather my company...) use a recompiled to look around the source of his demo app to learn alot lamentable dustman fucked around with this message at 02:47 on Feb 12, 2010 |
# ¿ Feb 12, 2010 02:44 |
|
i don't think those functions exist in Swing but i could be wrong
|
# ¿ Feb 23, 2010 17:37 |
|
Try printing out in.readObject().getClass().getName() and see what kind of object you actually are getting back
|
# ¿ Mar 1, 2010 22:17 |
|
for what is worth I prefer yatagan's way of writing it but would of had a else so it lines up
|
# ¿ Mar 9, 2010 17:26 |
|
this is java, can't bitch about being verbose when using java
|
# ¿ Mar 9, 2010 17:40 |
|
Partyworm posted:Does anyone have any experience with Java certification exams? Are they worth going for or just a waste of time next to practical ability? Never did them, probably a waste of money and time unless work is paying for it (and time to study for it)
|
# ¿ May 5, 2010 14:21 |
|
epswing posted:If you've never done them, why do you think your opinion that they're a waste of money is worth anything? Everyone that I know who has taken them says they are a waste, there was a thread on reddit yesterday were everyone said they were a waste also i guess they might be padding if you don't have a degree or something e: also just accepted a new job, during my hunt never saw anything that said "NEED JAVA CERTIFICATION", they all said you need a degree and some experience. lamentable dustman fucked around with this message at 16:27 on May 5, 2010 |
# ¿ May 5, 2010 16:25 |
|
epswing posted:I have a textfile in my src folder, like jdbc.properties or whitelist.xml, and when I compile it ends up in my bin folder (or more specifically, my war/WEB-INF/classes folder since I'm in tomcat-land). How can I access whitelist.xml? getClass().getClassLoader().getResourceAsStream("whitelist.xml") should get the file as a stream from the classpath root
|
# ¿ May 5, 2010 20:04 |
|
epswing posted:You could doesn't and take a look at how pircbot does things. Was going to suggest that, I've played around with it before. Very easy to use, runs its own irc client in main.
|
# ¿ May 17, 2010 03:10 |
|
Internet Janitor posted:WalltBeef: It's probably not the fastest solution, but if all you care about is 2d there's always the AWT Polygon class. Check out the contains() methods. When working on some GIS stuff I tried that at first, got annoyed and ended up just making my own stuff.
|
# ¿ May 20, 2010 00:01 |
|
YouAreCorrect posted:I have a question. Never met a recruiter or manager who cared about that cert but if my employer wanted me to get it and expected me to pay for it I would laugh in their face
|
# ¿ Jul 21, 2010 02:09 |
|
Jick Magger posted:I'm about to graduate with a CS degree, and I can't write a while loop properly. no worries, most programmers you meet on the job can't either
|
# ¿ Aug 20, 2010 04:42 |
|
MEAT TREAT posted:In Netbeans ALT-SHIFT-F will make you happy. ctrl+shift+f in eclipse
|
# ¿ Aug 20, 2010 22:26 |
|
Jewbert Jewstein posted:I'm at work right now and I'm working on pulling some data from Google Maps using their geocoding API. When I enter a url (example: http://maps.google.com/maps/api/geocode/xml?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false) it displays a page written in xml format. How do I extract data from this using java? Specifically I'm looking for the formatted address and the lat/long coordinates. Read it in and use XPath to get what you want out of it.
|
# ¿ Sep 15, 2010 19:24 |
|
Well that depends how you are accessing the data. If you are accessing it inside a program make a URL object out of it and open a stream to it and feed the stream into DocumentBuilder (iirc). If you just want to save what is in your browser go to file and save as.
|
# ¿ Sep 15, 2010 21:07 |
|
hayden. posted:To clarify, why can't I just let the program crash if there's a problem reading the file rather than being forced to specify what to do with an exception (I know this is retarded)? Is it just because the people designing Java decided to not let us do that? That is why it is a throw/catch If you don't give a gently caress you just throw it and are done with it, if you want to try and fix what happened you catch it and handle the error. Just add "throws Exception" in your function declaration if you give no gently caress and never deal with try/catches
|
# ¿ Sep 30, 2010 17:54 |
|
|
# ¿ Apr 27, 2024 17:36 |
|
IMlemon posted:I want to execute my algorithm in steps so that I can display the results nicely. User presses MoveButton, something is done and something is diplayed. He does that again, again something happens. Repeat. I don't want to completely block the application, user should still be able to select items and click buttons and whatnot. If I am reading right, I would have the MoveButton iterate a global count then disable the button with whatever function does that. The rest of the function would be a switch statement (or if/else block) that would call the correct step in your algorithm. After the last step reset the count or whatever. One it falls out of the switch renable the button. Things to keep in mind though is that unless you are threading the algorithm will run on the same thread as the GUI causing the app to act frozen till it is done. SwingWorker is a good class to help handle the threading.
|
# ¿ Oct 12, 2010 21:48 |