|
mister_gosh posted:I have a servlet which kicks off a separate jar (all my own code). I want to set up a queue for kicking off this separate operation because the operation can take some time and/or we can get multiple requests at a time. I want to process one at a time. What about a threadpool of one? It essentially becomes a FIFO, but should do what you need.
|
# ? Mar 23, 2009 17:38 |
|
|
# ? May 9, 2024 15:10 |
|
Since you own the other library anyway, why not give it a public API that you can just call from your servlet? Then you just need to create a worker thread to read your queue and make the API calls. There are plenty of serviceable concurrent queue implementations in any modern version of Java; just look through java.util.
|
# ? Mar 23, 2009 18:05 |
|
I've got a problem with painting in 2d to an InternalJFrame. I have an app that is best described as an MDI. I have an InternalJFrame that has tabs on it that will each show different information from a database. What I'm having problems with is being able to manipulate the graphics of the JPanels I attach to the Tabs. (I'm not actually at the tabs yet, just trying to add the JPanel to the InternalJFrame and have it show some sample graphics.) Here's some code: code:
code:
Thanks for any input you guys can give me. And a picture of what I've got so far because that might explain it a bit better : http://sa.plinkey.com/JavaApp.JPG edit: Is this a problem with mixing swing a AWT components? I got the text to show up but its in the menu bar of the Internal Frame. When I add a button using a FlowLayout Manager the button shows up in the right spot of the Internal Frame's Content Pane. And all of my 2d drawing seems to be trapped in the menu bar...wtf. Plinkey fucked around with this message at 20:23 on Mar 23, 2009 |
# ? Mar 23, 2009 19:09 |
|
rjmccall posted:Since you own the other library anyway, why not give it a public API that you can just call from your servlet? Then you just need to create a worker thread to read your queue and make the API calls. I guess I'm just confused overall on how to do this. the concurrent queue implementations address this? I guess you can tell I haven't worked with threads. Basically I have a java program which may fire. Then a separate one may fire later. How does the other java process learn about the first one? All of the queue examples I'm seeing assume that the multiple requests are all right there in front of you, and you need to divide them up. Which is why I ask, is there a way to grab on to a previously running class instance (so that I can learn of its instance variables to learn the order of the queue, enqueue it up, etc).
|
# ? Mar 23, 2009 20:09 |
|
I was saying that you should consider running your library code inside the same process as your servlet, setting up a thread to poll a concurrent queue being fed by multiple producers (the servlets). This should be rudimentary concurrency work, but you seem to be totally ignorant of threads, and possibly of basic OO design. In that case, I strongly suggest not doing what I previously recommended, because of the very real danger that you might get something to work. Threads are a very difficult problem, and if you want to learn to do them properly, you will need to actually study — not necessarily in a formal setting, but in some way where you really pick up the ideas.
|
# ? Mar 23, 2009 23:07 |
|
What's the simplest DOM style XML reader available in Java? I don't need to write XML files, just read them occasionally.
|
# ? Mar 24, 2009 16:57 |
|
Cloud Dog posted:What's the simplest DOM style XML reader available in Java? I don't need to write XML files, just read them occasionally. Can't really go wrong with JDOM and SAX
|
# ? Mar 24, 2009 18:10 |
|
This is for a school project, I've been staring at it too long so its all blending together and I can't workout why this only outputs the last name in the text file. I'll be checking back regularly if you have questions or need the other class posted.code:
|
# ? Mar 26, 2009 06:56 |
|
I have this assignment due tomorrow..quote:Fifteen numbered tiles are placed in a 4x4 grid, with one empty slot. Tiles are moved horizontally or vertically into the empty slot. The object is to slide the tiles to get to the above configuration. You can then mix up the tiles and try again. Tiles can only be moved by sliding into the empty location. (In the figure above, 12 can move down or 15 to the right. No other tiles may move.) I've been working on this for 6+ hours, just rewriting and rewriting the code. I'm totally stuck. I have to use somewhat basic java (I'm just using a simple JFrame button GUI and changing the labels.) Here is my most recent attempt: http://asfawdgfevgef32f32.pastebin.com/m5402843d I just have no idea how I should go about this. I don't know how I can let the numbers shift up and down, or to the right or left - yet not diagonally without having a ton of if statements in every action listener. Also, I have absolutely no idea on how I should go about changing the button labels every time. Can anybody point me in the right direction? Thanks in advance for any help with this.
|
# ? Mar 26, 2009 07:01 |
|
redfoxxx posted:
Meditate upon this passage, young one.
|
# ? Mar 26, 2009 08:05 |
|
rjmccall posted:Meditate upon this passage, young one. I'm not sure I understand what you mean. What's wrong with that snippet. What I was trying to do was pre-count the number of data lines read from a text file with 2 header lines.
|
# ? Mar 26, 2009 08:13 |
|
Huckle posted:I have this assignment due tomorrow.. Awesome. The significant problem here is that, when you click on a button, you need to know its position within the grid, as well as the position of the empty space. If you're going to do this by relabeling the buttons, you obviously can't use the button labels to figure out the button's positions, so you'll have to determine it based on something that doesn't change. Now, there are two relevant objects here: there is a button, and there is an action listener associated with the button. You will need to put this information on one of these objects. Pick. Changing the text of the label is easy; look at JButton's public API.
|
# ? Mar 26, 2009 08:15 |
|
redfoxxx posted:I'm not sure I understand what you mean. What's wrong with that snippet. What I was trying to do was pre-count the number of data lines read from a text file with 2 header lines. That'll teach me not to actually read your code — although, why are you actually doing this? What about this problem requires you to read the entire file first? Anyway, look at the code that prints out reports, and tell me why it always prints the name of the first student (i.e. the student at index 0).
|
# ? Mar 26, 2009 08:21 |
|
rjmccall posted:That'll teach me not to actually read your code — although, why are you actually doing this? What about this problem requires you to read the entire file first? That one is my bad, the 0 in that case is left in while i was testing. In the file we were given the program always prints the last name in the file. It should have read gc[i] just like the rest of the output block. I should have commented it out before posting it, and I should have used pastebin. [edit]also I should mention that we are reading data from a csv and populating an array of a class for student grades which is why I had to cheat and count the lines first. [/edit]
|
# ? Mar 26, 2009 08:40 |
|
Thanks. I've actually made a working puzzle that resets. http://wadawdfwegfwweg234g.pastebin.com/m5a373b5c Have any ideas for the randomization feature? I can't just randomize it all - I need the computer to make random legal moves. I'm lost here.
|
# ? Mar 26, 2009 10:25 |
|
Huckle posted:Have any ideas for the randomization feature? I can't just randomize it all - I need the computer to make random legal moves. I'm lost here. code:
|
# ? Mar 26, 2009 13:17 |
|
Little confused here. We have to have our user define how big they want the dataset to be then enter the numbers. We then have to calculate the sum, find the biggest one, and find how many times the biggest one appearscode:
int x[] = new int[k]; I still get a runtime error. I can manually set it to a maximum size(the teachers example used int a[]= new int[5] but if I enter a size bigger than 5 when running the program it crashes. I also get 0 for sum and 0 for biggest no matter what I would enter. Where am I going wrong?
|
# ? Mar 26, 2009 23:13 |
|
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 |
|
dvinnen posted: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. 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
|
# ? Mar 26, 2009 23:33 |
|
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 |
|
dvinnen posted:take a look at these lines: gah! As soon as I read that I found the problem. Does spotting little errors like this get easier as you do more programming?
|
# ? Mar 27, 2009 00:02 |
|
ayb posted:gah! As soon as I read that I found the problem. Does spotting little errors like this get easier as you do more programming? Sure does. As you make more stupid mistakes, you'll learn the ones that you make most often and hopefully look for those first when your program doesn't work right.
|
# ? Mar 27, 2009 00:04 |
|
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 code:
|
# ? Mar 27, 2009 00:46 |
|
Lysidas posted:Since it's very simple, I don't feel bad about helping you with this: it said quote:Exception in thread "main" java.long.ArrayIndexOutOfBoundsException: 5 I just doing the above code again and it is working. Literally the only thing I changed was cutting the int x[] = new int[5]; , making it int x[] = new int[k]; and then putting it after I ask the user how many spaces they want. It's working now but I literally didn't do anything different this time.
|
# ? Mar 27, 2009 00:58 |
|
ayb posted:
That "16" is the line number from which the exception was thrown. It was thrown because you were trying to set index k (i.e. the (k+1)th element) of an array with only k elements. It was fixed as a happy side-effect of fixing the bug dvinnen pointed out.
|
# ? Mar 27, 2009 01:08 |
|
I'm running into an OutOfMemoryError while I'm using a double buffer. It draws the first frame fine, but give me the error when it draws the second frame. I'm new to Java so I'm guessing that I'm missing something simple. Also, if I'm going about this all wrong, let me know. I'm trying to render only the visible portion of a large image to the screen and then apply a grid over it. x and y are the upper left coordinates on the large image. xres and yres indicate the screen resolution. So it should render only a screen sized portion of the image every time drawStuff() is called. What is the best method for limiting how many frames are rendered per second? Sleep doesn't seem like my best option. Code posted below. Twernmilt fucked around with this message at 17:37 on Mar 28, 2009 |
# ? Mar 28, 2009 00:09 |
|
Twernmilt posted:I'm running into an OutOfMemoryError while I'm using a double buffer. It draws the first frame fine, but give me the error when it draws the second frame. I'm new to Java so I'm guessing that I'm missing something simple. Also, if I'm going about this all wrong, let me know. This leads me to believe that you are allocating a new buffer or reloading the image each time without getting rid of the old copy. Post the rest of your code so we can see what's actually happening.
|
# ? Mar 28, 2009 15:36 |
|
Primary Classcode:
code:
|
# ? Mar 28, 2009 17:37 |
|
OK, I ran your code on my system, and... it just worked. Well, except for the keypress handling. In the Java spec, the keycode of a key even is only meaningful for KEY_PRESSED and KEY_RELEASED events, not KEY_TYPED. On my system, every time I pressed a key, getKeyCode returned VK_UNDEFINED. You should probably move that logic to keyPressed() rather than keyTyped. It works perfectly there. You can also catch the up and down arrow keys instead of using 0 and 1! Now, since the code seems to run fine, maybe there's something about the specific image you are using that causes the problem. Can you post your images please? Edit: I ran java with the -verbose:gc option to see if there were any memory leaks, and it doesn't look like it. Memory usage stayed around 55M as I panned around the image. If your image is sufficiently large, though, you might be running out of heap. Try running java with the -Xmx128M or even -Xmx256M option to give yourself more heap. Don't forget to put the options before the class name in the command line or they will be interpreted as arguments to main! Mill Town fucked around with this message at 16:16 on Mar 29, 2009 |
# ? Mar 29, 2009 16:04 |
|
Yea, I meant for that all to be key presses. It works when I increase my heap to 256. The image is just over 5mb, which I know is large, but that's why I'm only drawing small sections of it to the buffer. My plan was to have it load the image one time, when BackgroundImage is instantiated, and then have a much smaller buffer image rendered. It feels like the way I'm going about this is clunky, is there a more elegant way to pan over large images? I thought about breaking it up into pieces and only loading the ones I need, but that seems overly complicated.
|
# ? Mar 29, 2009 18:23 |
|
Twernmilt posted:Yea, I meant for that all to be key presses. It works when I increase my heap to 256. The image is just over 5mb, which I know is large, but that's why I'm only drawing small sections of it to the buffer. My plan was to have it load the image one time, when BackgroundImage is instantiated, and then have a much smaller buffer image rendered. It feels like the way I'm going about this is clunky, is there a more elegant way to pan over large images? I thought about breaking it up into pieces and only loading the ones I need, but that seems overly complicated. I'm certainly not aware of a good, clean way to do it. From reading your code, it looks like your image is 3750 pixels per side, which is about 40 MB when uncompressed (53 MB if you have an alpha channel). I think you're just going to have to live with it.
|
# ? Mar 29, 2009 19:20 |
|
Since my work computer doesn't have the jdk on it and I can't install any software, is there anywhere on the web I can go to see the output of my code? I found a compiler that tells me if there are any errors then gives me the .class file but I need to see the results. It's all pretty basic and should only have 5-6 lines out output.
|
# ? Mar 31, 2009 17:38 |
|
You might have Java installed, even if you don't have the JDK. Try dropping to a command line and running java.
|
# ? Mar 31, 2009 17:47 |
|
rjmccall posted:You might have Java installed, even if you don't have the JDK. Try dropping to a command line and running java. I tried and it gave me a whole host of errors. Exception in thread "main" java.lang.NoClassDefFoundError: Lab11a_me cause by: java.lang.ClassNotFoundException: Lab1a_me at java.net.URLClassLoader$1.run(Unknown Source) and so on for a few more lines
|
# ? Mar 31, 2009 17:51 |
|
ayb posted:I tried and it gave me a whole host of errors. Have you never run Java before? Try java -cp . Lab11a_me or something.
|
# ? Mar 31, 2009 18:06 |
|
ayb posted:I tried and it gave me a whole host of errors. This means there's either something wrong with your code or with the command line you're using to run it. Post both.
|
# ? Mar 31, 2009 18:06 |
|
My mistake guys, I had my .java file in the proper folder but never copied the the .class file in there. Code ran fine after I did that and boy do I feel dumb!
|
# ? Mar 31, 2009 18:12 |
|
What's a good way to profile my code? I'm using the hprof module now, and it works, but slows down my code by about 100x or something. Anyway, here's a snippet of output from hprof: code:
|
# ? Apr 1, 2009 02:45 |
|
Not a coding question, but are the first few links still relevant to learning Java? I'm taking a Programming in Java course this Fall and wouldn't mind getting a head start by learning over the summer before the course begins. http://math.hws.edu/javanotes/ is the main site I was wondering whether or not was still up to date with 2009, (technology evolves pretty quick) so I just wanted to make sure this site would benefit me before I began reading it.
|
# ? Apr 2, 2009 21:13 |
|
|
# ? May 9, 2024 15:10 |
|
kloa posted:Not a coding question, but are the first few links still relevant to learning Java? I'm taking a Programming in Java course this Fall and wouldn't mind getting a head start by learning over the summer before the course begins. Unless your class will be using the betas for Java 7 it looks like it'll cover just about everything you'll need to worry about. Java 6 added in annotations and a few other features that you probably won't run into in your intro to Java course.
|
# ? Apr 2, 2009 21:16 |