|
Mobius posted:I'd like to use a simple web framework on a personal project that I may make open-source in the future. I know Struts from work, but that's really overkill for this. I'm thinking about WEB4J. Has anyone here used it? Or have other recommendations, instead? I'm looking for something that will both get the job done and give me a chance to learn something practical. If you want something practical I would say SpringMVC if you don't know much about Spring. There is also Play if you want to learn Scala and the mentioned Grails if you want to learn Groovy.
|
# ? Apr 23, 2012 04:47 |
|
|
# ? May 10, 2024 19:37 |
|
Harold Ramis Drugs posted:Would that be using the "(Job)" cast in front of the call? If I do that, the program will compile but break when I try to run it with a Null Pointer Exception. Here's what I did: Then you have a null object in your node or the node being returned is null, you'll need to test for those before calling any object methods. You should also check for the job instance or use generics (the latter is probably beyond the scope of your class) code:
|
# ? Apr 23, 2012 04:51 |
|
Those loops are for code later on down the line. I'm just trying to get this one thing sorted out first. I tried your code in debug, and it skipped your entire block which leads me to believe that it doesn't even recognize the data as being a Job. However, when I put this print statement below it: code:
code:
|
# ? Apr 23, 2012 05:01 |
|
According to that, the node's data is... a node. The next two lines indicate that there's a Job somewhere down the chain. What happens if you do prime.data.data.getClass()? Also, this indicates there may be a problem when these Jobs are being inserted.
carry on then fucked around with this message at 05:13 on Apr 23, 2012 |
# ? Apr 23, 2012 05:09 |
|
carry on then posted:According to that, the node's data is... a node. The next two lines indicate that there's a Job somewhere down the chain. What happens if you do prime.data.data.getClass()? Also, this indicates there may be a problem when these Jobs are being inserted. The other side of the problem here is that the .next object variable on every node is returning a Job. Is Job a subclass of Node? If not, your list implementation is all hosed up. Also, when you say it skips over the entire block, are you still assigning prime.next, or is it just skipping over the first Node?
|
# ? Apr 23, 2012 05:22 |
|
There may have been a problem with an abstract method. I extended a separate class from LinkedList called LinkedQueue, and when I extended the add method I might have hosed something up. Investigating...
|
# ? Apr 23, 2012 06:03 |
|
If you want help post the whole thing to pastebin or something similar. People are generally willing to help but it's very hard for people to help you debug your linked list when you don't actually post the code from it.
|
# ? Apr 23, 2012 06:40 |
I want to use log4j for a console application I'm writing. In the class that has my main() method I'm adding a ConsoleAppender to my Logger instance. How do I get a Logger instance in a different class that has the same appender? Do I have to use an external log4j properties file? edit: ah, I just use my package name when instantiating the logger and add the ConsoleAppender, then all other loggers use it. http://logging.apache.org/log4j/1.2/manual.html quote:For example, the logger named "com.foo" is a parent of the logger named "com.foo.Bar". Similarly, "java" is a parent of "java.util" and an ancestor of "java.util.Vector". This naming scheme should be familiar to most developers. fletcher fucked around with this message at 19:49 on Apr 23, 2012 |
|
# ? Apr 23, 2012 19:33 |
|
This isn't really a java question per se but it involves java. For a class project (the class is unrelated to concurrency) I'm implementing an algorithm that I want to be parallelized, but I'm not really an expert on the subject. I know the basics, but am interested in how to implement this in the most efficient way. The algorithm is something like this (I've implemented a non-parallel version): ------- There are 100 nodes divided into 4 groups. At each iteration of the algorithm, the node calculates a direction and a distance to move. The direction can be calculated independently for each node, but the distance depends on the locations of all other nodes in the same group. After each node has been evaluated, some number of nodes get thrown out of each group and replaced with nodes from the other groups. ------- So I'm thinking of creating it in a master worker style, where 4 threads calculate the distance and direction, then the master does the switching of the nodes between each group. Would this be a good idea?
|
# ? Apr 24, 2012 04:20 |
|
You can do master slave to break down the 4 sections. But if you want to make it become truly scalable to as many cores as are present in the system then it will be a bit more complex of an algorithm. One question would be this: Does each node only care about where the other nodes are at the beginning of each calculation? At the end? Or at some point in between? (e.g. if node 1 carries out the distance computation, does the result effect node 2?) I would first write it out linearly and then look for sections of the code that can be broken out in to separate tasks.
|
# ? Apr 24, 2012 04:28 |
|
Pie Colony posted:This isn't really a java question per se but it involves java. For a class project (the class is unrelated to concurrency) I'm implementing an algorithm that I want to be parallelized, but I'm not really an expert on the subject. I know the basics, but am interested in how to implement this in the most efficient way. Consider using the Executor framework. Specifically: http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/Executors.html#newFixedThreadPool(int) http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/ThreadPoolExecutor.html You could just have a thread pool managed by the framework, and have the runnables schedule their successors. Or if you want to go full-blown overkill, use Quartz Scheduler with the in-memory task store. Then mavenize it. (I played around with Quartz recently and mixed Guice in for good measure too) If you really want to get to know parallelization/concurrency better, read Java Concurrency in Practice. It's *the* reference.
|
# ? Apr 24, 2012 04:29 |
|
Harold Ramis Drugs posted:Would that be using the "(Job)" cast in front of the call? If I do that, the program will compile but break when I try to run it with a Null Pointer Exception. Here's what I did: It would be waitJob = (Job)prime.data; right? Alternatively you can do ((Job)prime.data).run(100); if you don't want to store it in a variable.
|
# ? Apr 24, 2012 15:08 |
|
Hey all, I have been stuck on something that I thought would be easy, but it is turning out to be very problemantic. I have a text file that holds a user name, password, and account names. I am trying to remove a specific account name from the file... I already have the function finding the correct account name in the file, and creating a temp file for the new file, but i cant delete the old file and rename the temp file to what the old file was. (Thus just editing the file) Here is my code, I have tried everything I feel and cant figure it out. Any help is greatly Appreciated. code:
Thanks again!
|
# ? Apr 25, 2012 23:39 |
|
Kind of a weird development, I can get it to delete the old file and rename the temp file on a mac(my partners computer), but with the exact same code I cant get it to work on my PC. I am using windows 7 64bit, running java 1.7, and using eclipse.
|
# ? Apr 26, 2012 00:03 |
|
Helg56 posted:stuff I wonder if using FileUtils in Apache Common's io package might work better, if it's not overkill to pull the library in. It'll reduce your boilerplate there by a lot, I wager. printStackTrace prints to standard error (stderr). I generally use a logging framework such as log4j or logback in order to log the errors, because then you can redirect the logging output to log files, or filter stuff out as you like. It's definitely a staple of Java development.
|
# ? Apr 26, 2012 01:00 |
|
Doctor w-rw-rw- posted:I wonder if using FileUtils in Apache Common's io package might work better, if it's not overkill to pull the library in. It'll reduce your boilerplate there by a lot, I wager. I am omly allowed to use the java built in functions. It is a school project.
|
# ? Apr 26, 2012 01:20 |
|
Are you buy chance trying to carry this out on the root drive of your Windows install (a.k.a C:\)? If so, I suggest placing the file in your User directory and trying to run your program again. I also suggest you trim the ends off of that input. Edit: Also, if you want, google "java FilePermission". ComptimusPrime fucked around with this message at 02:37 on Apr 26, 2012 |
# ? Apr 26, 2012 02:28 |
|
file.delete() returns a success, which should help with your debugging.code:
http://stackoverflow.com/questions/991489/i-cant-delete-a-file-in-java You can also try file.setWritable(true); and see if it has any effect. Kruegel fucked around with this message at 04:15 on Apr 26, 2012 |
# ? Apr 26, 2012 04:05 |
|
Okay this is just driving me nuts. I'm trying to use a JOptionPane window to do something based on which button the user clicks, but it isn't doing jack poo poo and I can't figure out why. Here's the copy/paste of the code I'm dealing with: code:
What am I doing wrong here? EDIT: Okay, I just surrounded the b.showOptionDialog( ) line with JOptionPane.setValue( ) as a quick fix, and that seems to have solved the problem. Although I'm still curious as to whether there's a better way of going about this than that. I. M. Gei fucked around with this message at 02:54 on Apr 27, 2012 |
# ? Apr 26, 2012 22:39 |
|
New question time! Does anybody know how to make a JOptionPane window with drop-down menus? Or, more specifically, does anybody know how to make a JOptionPane window with MULTIPLE drop-down menus... preferably all lined up into rows and columns? And by "MULTIPLE" I mean 70. Yes, I am trying to put exactly 70 drop-down menus in a single JOptionPane window. Any help would be greatly appreciated. I. M. Gei fucked around with this message at 04:14 on Apr 27, 2012 |
# ? Apr 27, 2012 04:11 |
|
Dr. Gitmo Moneyson posted:Does anybody know how to make a JOptionPane window with drop-down menus? Or, more specifically, does anybody know how to make a JOptionPane window with MULTIPLE drop-down menus... preferably all lined up into rows and columns? And by "MULTIPLE" I mean 70. Other than making UI designers cry, why? As for your questions, first you need to look at the docs because you're not quite doing it right and you're calling a static method on your object instead of calling an instance method. code:
code:
|
# ? Apr 27, 2012 04:40 |
|
baquerd posted:As for your questions, first you need to look at the docs because you're not quite doing it right and you're calling a static method on your object instead of calling an instance method. baquerd posted:As for the 70 drop downs, you're going to want to make a JPanel and arrange the dropdowns using a LayoutManager like GridLayout or GridBagLayout. Have some example code: If you want, I can put together a rough MSPaint of what I want to make that might give you a better idea of what I'm trying to do.
|
# ? Apr 27, 2012 05:20 |
|
Dr. Gitmo Moneyson posted:Can you clarify what you mean here? I'm pretty new to Swing and I'm not sure what you mean by "calling an instance method" as opposed to calling a static one. Instance methods are methods that are called on a particular object instance (this terminology applies to any object, not just Swing objects). Static methods are methods that belong to a class and do not require an object instance. You are creating a JOptionPane, then ignoring the instance you just created and are calling the JOptionPane's class's static method via the object instance (which isn't great practice as it leads to confusion like this). I'd be happy to code such a UI for you, and I'd estimate this would cost around $100 to create a class that will allow you to conveniently set up and retrieve data from the option pane in whatever manner you desire. If you prefer, you might start here if you'd like to make your own UI: http://docs.oracle.com/javase/tutorial/uiswing/layout/index.html http://docs.oracle.com/javase/tutorial/uiswing/components/combobox.html
|
# ? Apr 27, 2012 05:34 |
|
baquerd posted:Instance methods are methods that are called on a particular object instance (this terminology applies to any object, not just Swing objects). Static methods are methods that belong to a class and do not require an object instance. You are creating a JOptionPane, then ignoring the instance you just created and are calling the JOptionPane's class's static method via the object instance (which isn't great practice as it leads to confusion like this). Assuming you mean what I think you do here, I'm using Eclipse, and anytime I call my b object instead of doing things straight from the JOptionPane class, Eclipse gives me warning messages saying the static field JOptionPane.whatever should be accessed in a static way. Is this just Eclipse being stupid or something?
|
# ? Apr 27, 2012 06:06 |
|
Dr. Gitmo Moneyson posted:Assuming you mean what I think you do here, I'm using Eclipse, and anytime I call my b object instead of doing things straight from the JOptionPane class, Eclipse gives me warning messages saying the static field JOptionPane.whatever should be accessed in a static way. Eclipse is trying to tell you what I told you, that accessing a static method via an object instance is bad practice. code:
baquerd fucked around with this message at 06:14 on Apr 27, 2012 |
# ? Apr 27, 2012 06:11 |
|
baquerd posted:Eclipse is trying to tell you what I told you, that accessing a static method via an object instance is bad practice. Soooooo would this code below count as bad practice or good practice? code:
|
# ? Apr 27, 2012 06:35 |
|
Dr. Gitmo Moneyson posted:Where do the "JOptionPane"s go? Everywhere the "b"s are now? Yes, that's the standard way of referring to class constants.
|
# ? Apr 27, 2012 06:39 |
|
MEAT TREAT posted:Yes, that's the standard way of referring to class constants. Cool, I think I've got it all corrected now. Now I gotta do that thing with the drop-down menus...
|
# ? Apr 27, 2012 06:48 |
|
Dr. Gitmo Moneyson posted:Cool, I think I've got it all corrected now. You can have Eclipse change all of those automatically every time you save the file. Look in Window->Preferences->Java->Editor->Save Actions and add "Change non static accesses to static members using declaring type" to the list of Additional Actions.
|
# ? Apr 27, 2012 09:48 |
|
Okay I think I got the drop-down menus set up. Is there a way to add a simple horizontal divider/boundary/line-thingy to a JOptionPane or JPanel window? So I can separate some of my drop-down menu rows and make the window a little easier to look at?
|
# ? Apr 27, 2012 10:42 |
|
Use a JSeparator
|
# ? Apr 27, 2012 10:56 |
|
Dr. Gitmo Moneyson posted:Soooooo would this code below count as bad practice or good practice? You're still missing the idea that you're actually creating two JOptionPanes. You have no need for a object instance at all: code:
|
# ? Apr 27, 2012 13:48 |
|
My software is all of the sudden uncompilable to NetBeans. Here is the error I get upon trying to run it:code:
|
# ? Apr 27, 2012 22:09 |
|
Hidden Under a Hat posted:My software is all of the sudden uncompilable to NetBeans. Here is the error I get upon trying to run it: If a clean a build fixes it, then that means your code is fine and NetBeans is at fault. Try closing NetBeans, and deleting the var/cache/index/ folder of NetBeans. It's normally stored in your home directory under .netbeans/version/
|
# ? Apr 27, 2012 23:04 |
|
baquerd posted:You're still missing the idea that you're actually creating two JOptionPanes. You have no need for a object instance at all: I assume the "b"s inside those parentheses should be "JOptionPane"s, then? Because Eclipse gives me warning messages anytime I type "b.something" instead of "JOptionPane.something" in the parentheses. So basically you're telling me that the b object was worthless all along. Good to know... Okay, EDIT: Actually nevermind my next question, I think I figured it out already. I just.... have to rewrite a bunch of the new code I typed last night. I. M. Gei fucked around with this message at 08:53 on Apr 28, 2012 |
# ? Apr 28, 2012 03:25 |
|
MEAT TREAT posted:If a clean a build fixes it, then that means your code is fine and NetBeans is at fault. Try closing NetBeans, and deleting the var/cache/index/ folder of NetBeans. It's normally stored in your home directory under .netbeans/version/ I can't find this folder anywhere. I'm using Mac OS X 10.6.
|
# ? Apr 28, 2012 19:21 |
|
Hidden Under a Hat posted:I can't find this folder anywhere. I'm using Mac OS X 10.6. On Linux systems, directories starting with a dot are hidden, maybe OS X is the same?
|
# ? Apr 28, 2012 20:22 |
|
MEAT TREAT posted:On Linux systems, directories starting with a dot are hidden, maybe OS X is the same? Yes, it is. Show hidden folders.
|
# ? Apr 28, 2012 22:00 |
|
Hidden Under a Hat posted:I can't find this folder anywhere. I'm using Mac OS X 10.6. In Finder just hit CMD+Shift+G and type in ~/.netbeans, should take you right to it.
|
# ? Apr 28, 2012 22:51 |
|
|
# ? May 10, 2024 19:37 |
|
Does Java have any kind of event handling / dispatching ala Actionscript 3? I know it doesn't have delegates so the C# system I was hoping to port over won't work. The only thing I can find on Google is the ActionListener interface, but that seems to be specifically for Swing? For reference, what I am trying to do is listen for events on a particular object. If I was coding a game, for example, I might want to listen for events for when the player jumps, takes damage or dies so the rest of my game can react accordingly.
|
# ? Apr 28, 2012 23:43 |