|
I'd like to experiment with SWT. Is there anyway I can code with it using NetBeans 5.5, or do I have to use Eclipse?
|
# ? Apr 24, 2008 06:04 |
|
|
# ? May 8, 2024 05:28 |
|
You can code with it fine in Netbeans, just reference the JAR and the libraries that it requires. The Netbeans visual designer is based on Swing and it's very unlikely you'll find an SWT designer for Netbeans, though.
|
# ? Apr 24, 2008 09:31 |
|
I have a question about traversing a class hierarchy. Let's say I have these classes:code:
code:
|
# ? Apr 24, 2008 21:11 |
|
Save the whales posted:What do I put in the "getAggregateDescription" method of ExtendableThing to make it behave like this? You might want to read up on downcasting objects, because at the moment the System.out.println statements will throw a ClassCastException. Maybe someone else who has a way with words will try and explain why (if not, read up on polymorphism). But as far as your problem goes you could do something like: code:
Twitchy fucked around with this message at 22:41 on Apr 24, 2008 |
# ? Apr 24, 2008 22:25 |
|
Twitchy posted:You might want to read up on downcasting objects, because at the moment System.Out.Println statements will throw a ClassCastException. Maybe someone else who has a way with words will try and explain why (if not, read up on polymorphism). I don't see why a ClassCastException would get thrown. foo is a BlueThing, a ColoredThing, and an ExtendableThing so I don't see a problem there. edit: I'm starting to think this isn't possible because getDescription is overwritten by each subclass. drat it. Save the whales fucked around with this message at 22:43 on Apr 24, 2008 |
# ? Apr 24, 2008 22:39 |
|
Save the whales posted:I don't see why a ClassCastException would get thrown. foo is a BlueThing, a ColoredThing, and an ExtendableThing so I don't see a problem there. Oops yeah you're right there, thought it was the abstract class. My apologies, always jumping the gun and looking the fool . There's nothing else you need to put in the ExtendableThing getAggregateDescription(), since it will always call the most specific method. So for example in ColoredThing you could have: code:
code:
code:
Twitchy fucked around with this message at 22:55 on Apr 24, 2008 |
# ? Apr 24, 2008 22:42 |
|
I was hoping that I could avoid having to put the method in each subclass. This code is supposed to go in a shared library at my company and I want to make it really easy to use. So, when my coworkers are making a new kind of ExtendableThing in their projects, all they have to do is make sure it extends ExtendableThing and it works magically. If it were only one method ("getAggregateDescription") then I might have been able to deal with that, but the problem is that there are many methods that need to use a similar strategy (going up the class hierarchy). This is what I have so far, but it's not working like I expected (it appears to cause infinite recursion): code:
|
# ? Apr 24, 2008 23:05 |
|
I discovered something awesome about java today! Labeled loops I had a triple nested loop and the two inner loops were traversing the same data structure. I wanted to be able to break out of two loops and using a flag for this kind of stuff annoys me. I did a quick search and found the labeled loops. After reading some more I realized that you can label any block of code and effectively have a goto! It seems like it could be misused, but I'm happy with what I used it for. code:
|
# ? Apr 24, 2008 23:06 |
|
Save the whales posted:This is what I have so far, but it's not working like I expected (it appears to cause infinite recursion): I'm not sure if this is the root of the problem but even when you upcast a ShineyBlueThing to say a BlueThing, it will still call the ShineyBlueThing getDescription() method, rather than the upcasted version (i.e. it will always print "shiny"). I think you mentioned this above, so i'm gonna have a look over it, but I don't see any "easy" way of it being done . The reason it doesn't work (at least part of it) is that you're saying getClass() << ShinyBlueThing .getSuperClass() << BlueThing .getMethod("getAggregateDescription") << which doesn't exist in the BlueThing class. Even then I don't think it's quite right, you're attempting to call the same method recursivly, while at the same time not actually changing anything that would make the method path any different. The problem may just lie in the fact that you are upcasting instead of using a new object, as in: code:
Also stupid little thing but I don't think: code:
Edit: Jesus christ, sorry this post is all over the place :| Twitchy fucked around with this message at 23:47 on Apr 24, 2008 |
# ? Apr 24, 2008 23:33 |
|
I think I've got it! At least, this solution appears to work. I avoid the problem of the method being overwritten by declaring new instances of the super classes and abandoning recursion.code:
|
# ? Apr 24, 2008 23:47 |
|
Save the whales posted:I think I've got it! At least, this solution appears to work. I avoid the problem of the method being overwritten by declaring new instances of the super classes and abandoning recursion. I actually thought of something like that aswell, whether it's usable depends on how often it'll be called, and any memory restrictions etc, since it's hacked together code. Another option would be to make the getDescription() static, since it looks like the value would be a constant anyway. It would also mean you wouldn't clutter up space with immediately discared objects. Just food for thought. That would have to be a stated requirement though, so if it wasn't implemented it could cause trouble. Twitchy fucked around with this message at 00:18 on Apr 25, 2008 |
# ? Apr 25, 2008 00:06 |
|
Alright, apparently I don't understand how primitives and objects are passed to methods in Java. I thought Java only passes values to methods. But if I pass in an object like array, the object's content will change. For example:code:
code:
|
# ? Apr 25, 2008 00:19 |
|
Twitchy posted:I actually thought of something like that aswell, whether it's usable depends on how often it'll be called, and any memory restrictions etc, since it's hacked together code. Another option would be to make the getDescription() static, since it looks like the value would be a constant anyway. It would also mean you wouldn't clutter up space with immediately discared objects. Just food for thought. Yeah, it's not the greatest solution but it fits my specific needs. The "getDescription" method isn't static but it returns a static value. I wish I could make it static but unfortunately that method I'm overwriting wasn't originally written by me. It's in that code base used by my company in all of our projects, and I can't go changing that now. Luckily, it happens that the constructors for these things are extremely cheap (they're empty). Thanks for your help, Twitchy.
|
# ? Apr 25, 2008 00:20 |
|
CrusaderSean posted:Alright, apparently I don't understand how primitives and objects are passed to methods in Java. I thought Java only passes values to methods. But if I pass in an object like array, the object's content will change. For example: Arrays are themselves Objects, and so are passed by reference. The array may contain primitives (ints, doubles etc), but the structure that holds them is an Object. Twitchy fucked around with this message at 00:27 on Apr 25, 2008 |
# ? Apr 25, 2008 00:25 |
|
Twitchy posted:Arrays are themselves Objects, and so are passed by reference. The array may contain primitives (ints, doubles etc), but the structure that holds them is an Object. but if I change the scaleLine method to the following, the line array doesn't change... so if object parameters are really passed in as reference, shouldn't it point to the new int[] newLine? or is the following code just changing where the reference variable is pointing to and has no effect on the caller? code:
CrusaderSean fucked around with this message at 00:39 on Apr 25, 2008 |
# ? Apr 25, 2008 00:32 |
|
CrusaderSean posted:but if I change the scaleLine method to the following, the line array doesn't change... so if object parameters are really passed in as reference, shouldn't it point to the new int[] newLine? Hah, I think this same question was just asked on the last page, and being a master of words made a mess off explaining it, but basically: When you call scaleLine2, the REFERENCE (i.e. a place in memory where the object can be found) of l in the main method is assigned to a new variable called l. So when you say "l = newLine" you're basically saying "forget that last reference I gave you, use this one instead". So now your temporary variable l refers to the new int[] you made, where as l in the main method still refers to the same location as before.
|
# ? Apr 25, 2008 00:37 |
|
Twitchy posted:Hah, I think this same question was just asked on the last page, and being a master of words made a mess off explaining it, but basically: So in terms of programming practice, which of the following is better? void someMethod(Object obj...) { ... passed in object value may change ... } or Object someMethod(Object obj...) { ... explicitly return changed object ... } I see people using the first one because they want to change multiple objects in a method and can't return multiple objects. But in reality it is not really "void" in the sense that inputs can change in value so it might be misleading. Maybe this is a non-issue and everyone knows how reference works in Java... I was just really confused the first time I saw someone do that.
|
# ? Apr 25, 2008 00:51 |
|
CrusaderSean posted:So in terms of programming practice, which of the following is better?
|
# ? Apr 25, 2008 00:55 |
|
ahhhh! quick question How can I add 2 things into the same JFrame! Both will work seperately, but when I try and add both in at the same time one will overwrite the other. im hoping this will be something somewhat simple. quote:
Component2 will show, but component wont show up at all. By themeselves, they will be up and working just fine, just not together... Drumstick fucked around with this message at 06:59 on Apr 25, 2008 |
# ? Apr 25, 2008 06:55 |
|
Drumstick posted:Component2 will show, but component wont show up at all. By themeselves, they will be up and working just fine, just not together... With some layouts you need to pass the "position" where the item should appear as well - with BorderLayout you can choose NORTH, SOUTH, EAST, WEST, or CENTER, for example.
|
# ? Apr 25, 2008 07:31 |
|
okay thanks! i will look into that right away. I havent had to add two components into a frame before, thanks again
|
# ? Apr 25, 2008 07:45 |
|
Drumstick posted:okay thanks! i will look into that right away. I havent had to add two components into a frame before, thanks again
|
# ? Apr 25, 2008 08:04 |
|
* IMPORTANT: Performance is very important, please make the method efficient * I am making an app right now and could use the following Graphics2D wrapper methods (I don't know a thing about Graphics2D) 1.) I want a method called applyOpacity(Image,Double) where it accepts an Image type and a double specifying the opacity. It will then use Graphics2D to apply the opacity to the Image and return the new Image. I don't know if this is possible or not, if it can't be stored in an image and instead needs to be stored in a Graphics object then return that instead. 2.) applyLighting(Image,Int) I send it an image with a brightness 0 being completely black and 100 being completely white? It then returns the resulting Image. The useage would be if I wanted to bring something ot the foreground I would draw my background on offscreen image, pass it to the lighting method and darken it. Then I would take my 2nd image thats foreground send it to opacity and drawImage onto the offscreen image. Thanks!
|
# ? Apr 25, 2008 15:20 |
|
PianoDragn posted:* IMPORTANT: Performance is very important, please make the method efficient * I have no idea of the performance of this method, but this is how I got it working: code:
code:
There's more info on this kind of method here: http://java.sun.com/docs/books/tutorial/2d/images/drawimage.html Twitchy fucked around with this message at 17:02 on Apr 25, 2008 |
# ? Apr 25, 2008 16:57 |
I'm looking to implement some charts on a Java web application. Right now I'm reading about JFreeChart. What are some others worth looking into? I'd prefer to go down either the static images route or possibly flash based for some user interaction, no applet type stuff.
fletcher fucked around with this message at 23:58 on Apr 25, 2008 |
|
# ? Apr 25, 2008 23:44 |
|
fletcher posted:I'm looking to implement some charts on a Java web application. Right now I'm reading about JFreeChart. What are some others worth looking into? I'd prefer to go down either the static images route or possibly flash based for some user interaction, no applet type stuff. Tow questions: what kind of charts, and can you run other programs on your server as well? Such as, for instance, gnuplot? Just asking. Also, since it's web, I'm guessing you want to output at least PNG or something (perhaps have support for PDF and PostScript as well)? More specs, please.
|
# ? Apr 26, 2008 17:35 |
|
PianoDragn posted:* IMPORTANT: Performance is very important, please make the method efficient * Read up on VolatileImage, it is supposedly faster and stored in video RAM (according to this). Perhaps that could speed things up for you?
|
# ? Apr 26, 2008 18:31 |
|
Does anyone know of good resources to learn hot to use Project Darkstar (Sun Game Server) as the things I can find on the official site seems pretty confusing.
|
# ? Apr 27, 2008 15:51 |
|
I'm playing with java.util.Observer and Observable for MVC GUI design. I don't really understand how the listener/observers determine if the state has changed. I know you can run dataModel.hasChanged() to explicitly mark the data state as changed, but when is it necessary to do this? Does java automatically mark observable state as changed or do I have to do it manually? I redid this simple temperature program here. So when the temperature is raised or lowered, the GUI will call setTemperature function in the model. The model's setTemp function will in turn call the notifyObserver function. The temperature model does not call hasChanged() at all and it works just fine. So Java must have determined temperature state has changed somehow... Then I created my own example with a more complicated data structure. I'm using the same basic concept for observer and observable. I tried the following two variations: case 1: update state parameters, run notifyObserver => observer.update() doesn't run and nothing changes case 2: update state parameters AND set model.hasChanged(), run notifyObserver => will run observer.update() and GUI will reflect changes So does this mean I need to set model.hasChanged() manually for more complicated data models? CrusaderSean fucked around with this message at 03:25 on Apr 29, 2008 |
# ? Apr 29, 2008 03:22 |
|
CrusaderSean posted:The temperature model does not call hasChanged() at all and it works just fine. No, but is does call setChanged(), which means that any subsequent calls to hasChanged() will return true until clearChanged() is called. Observable API posted:public void notifyObservers(Object arg) Edit: To clarify, for now, you probably want to call setChanged before every call to notifyObservers. the onion wizard fucked around with this message at 10:09 on Apr 29, 2008 |
# ? Apr 29, 2008 10:02 |
|
triplekungfu posted:No, but is does call setChanged(), which means that any subsequent calls to hasChanged() will return true until clearChanged() is called. Hmm.. how did I miss that setChanged() line.. thanks for the clarification. edit: actually I was using setChanged(), I guess I'm illiterate that late in the night... CrusaderSean fucked around with this message at 16:11 on Apr 29, 2008 |
# ? Apr 29, 2008 14:48 |
|
Okay, I have a question similar to the MultiMap one last page. I have a grid of devices laid out, with each device taking up (possibly) several grid cells, and in addition devices can be layered so that there are several on a single cell. I want to be able to go from a cell to the devices on said cell, and from a device to all cells covered by that device. Is there anything better than just using two HashMaps/MultiMaps for this, one for each direction?
|
# ? Apr 29, 2008 17:45 |
|
I am making an application and need it to be skinnable, to the extent that someone could add extra JTextFields to the form for extra inputs. Much of the code is in javascript using mozilla rhino so this will need to be able to access the extra JTextFields to work with the input. What would be my best option for this? I've looked into SwiXML but couldn't get far because for some reason I can't get it to build on OSX, before I mess around with it to get it to build I want to know if there are any better options?
|
# ? Apr 30, 2008 13:54 |
|
The other day I was thinking, is there any reason why Java doesn't have return type polymoprhism? I mean like having public String foo() and public int foo() and then the one that gets called depends on what kind of type of return value the caller expects. This works really nicely in languages like Haskell and I see nothing in Java that prevents it form having this feature.
|
# ? Apr 30, 2008 14:12 |
|
Bonus posted:The other day I was thinking, is there any reason why Java doesn't have return type polymoprhism? I mean like having public String foo() and public int foo() and then the one that gets called depends on what kind of type of return value the caller expects. This works really nicely in languages like Haskell and I see nothing in Java that prevents it form having this feature. code:
code:
code:
|
# ? Apr 30, 2008 14:22 |
|
FYI, the JVM has no such restriction on overloaded return types. Only the JLS does. You can do this in Jaskell and possilby Scala, IIRC.
|
# ? Apr 30, 2008 15:28 |
|
I'm fairly sure you cannot do this in Scala, for what it's worth. I'll have a look tonight if I remember though. Also the fact that you can do it in Jaskell does not mean that the bytecode or the JVM supports it directly. A lot of JVM languages encode such concepts (the multiple inheritance in Scala, for example, is not something that JVM bytecode supports directly).
|
# ? Apr 30, 2008 15:56 |
|
zootm posted:I'm fairly sure you cannot do this in Scala, for what it's worth. I'll have a look tonight if I remember though. I understand what you mean, but the JVM docs specifically state that it does not restrict overloaded method returns.
|
# ? Apr 30, 2008 18:46 |
|
TRex EaterofCars posted:I understand what you mean, but the JVM docs specifically state that it does not restrict overloaded method returns.
|
# ? Apr 30, 2008 19:43 |
|
|
# ? May 8, 2024 05:28 |
|
zootm posted:Cool, just checking. Is that how Jaskell works? It seems strange to have a JVM language that Java can't call. I actually do not know how Jaskell is implemented. I kinda wrote that post quickly and should have put the word "also" in there somewhere. :p
|
# ? Apr 30, 2008 20:36 |