java

How can I serialise a javabean to be loaded by Spring's DataBinder?

I need to serialise a javabean (with arbitrary nested beans) to plain text, and then later restore as an Object graph. For the purposes of this question I am not interested in XML, JSON, etc. but rather name/value pairs. The Spring DataBinder is great for turning a list of name/value pairs into a real Object. For example we can supply:...

Making a component less sensitive to Dragging in Swing

A JComponent of mine is firing a mouseDragged event too vigorously. When the user is trying to click, it interprets is as a drag even if the mouse has only moved 1 pixel. How would I add a rule for a particular component that amounted to: Do not consider it a drag event unless the mouse has moved 10 pixels from the point at whi...

Checking whether all enum values are mapped?

Is there a convenience method available in the java standard libraries to check whether all possible keys in an EnumMap are mapped to a value? I can write my own method like: public static <T extends Enum<T>> boolean areAllValuesMapped(EnumMap<T, ?> map, Class<T> enumClass) { return map.keySet().equals(EnumSet.allOf(enumClass)); } ...

Getting Raw XML From SOAPMessage in Java

I've set up a SOAP WebServiceProvider in JAX-WS, but I'm having trouble figuring out how to get the raw XML from a SOAPMessage (or any Node) object. Here's a sample of the code I've got right now, and where I'm trying to grab the XML: @WebServiceProvider(wsdlLocation="SoapService.wsdl") @ServiceMode(value=Service.Mode.MESSAGE) public c...

Basic Spring help

I'm trying out my first Spring project and must be doing something really stupid because I can't figure out how to get the following simple snippet of code to work: Here is my definition file: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSche...

Android TextView Timer

For my Android application there is a timer that measures how much time has passed. Ever 100 milliseconds I update my TextView with some text like "Score: 10 Time: 100.10 seconds". But, I find the TextView only updates the first few times. The application is still very responsive, but the label will not update. I tried to call .invalidat...

How do I round up currency values in Java?

Okay, here's my problem. Basically I have this problem. I have a number like .53999999. How do I round it up to 54 without using any of the Math functions? I'm guessing I have to multiply by 100 to scale it, then divide? Something like that? Thanks guys! EDIT: more info The issue is with money. let's say I have $50.5399999 I know ho...

URL routing and relative links in Tomcat 5.5

I'm trying to add URL routing to a web application running in Tomcat 5.5. I want to make the dynamic page URLs more friendly, changing main.jsp?type=test&group=info to main/test/info as is all the rage. I have set up the following in the web.xml <servlet> <servlet-name>main</servlet-name> <jsp-file>/main.jsp</jsp-file> </s...

Cohesion Metrics

Can someone give me the java code for LCOM(lack of cohesion) or any other cohesion metrics which takes a class as input and gives a numerical value for cohesion. ...

How to set or export display variable through java code?

We are required to add export DISPLAY=:0.0 in tomcat's startup file and batch server's startup file. This is to make java see the X11 Display libraries on Unix and run our applet. Without this export in the startup files, the applet throws a Headless Exception. Though this explicit export makes the java applet run, it disrupts the other...

manipulating audio and drawing waveform using java sound in real-time

I am currently developing an application that helps the user to tune his guitar and generate guitar effects. This is in real-time. I've been looking through java applications that could give an idea to generate guitar effects such as overdrive and delay but I couldn't find any. Also a source on creating a waveform in real time is needed....

Fast transcendent / trigonometric functions for Java

Since the trigonometric functions in java.lang.Math are quite slow: is there a library that does a quick and good approximation? It seems possible to do a calculation several times faster without losing much precision. (On my machine a multiplication takes 1.5ns, and java.lang.Math.sin 46ns to 116ns). Unfortunately there is not yet a way...

Simulation in java

Hi, I am novice to the simulation world, and want to learn how programmers develop real simulation projects in java. I would use eclipse. Could anyone point to other things that I need to know (e.g. other packages, software etc. and their purposes)? I am afraid the question might seem a bit vague as it is not clear which type of project...

Is there a way to improve multicore / multiprocessor performance of the Java compiler?

My coworker noticed that when javac is compiling it only utilizes a single core. Is there anything like the -j command with the gcc for Java that will allow us to distribute the compiler workload across cores or processors? If not, do you think that this will ever be possible or is there some sort of fundamental restriction as a result o...

How to set background image in Java?

I am developing a simple platform game using Java using BlueJ as the IDE. Right now I have player/enemy sprites, platforms and other items in the game drawn using polygons and simple shapes. Eventually I hope to replace them with actual images. For now I would like to know what is the simplest solution to setting an image (either URL or...

Best way to concatenate List of String objects?

I am thinking of doing this way: List sList = new ArrayList(); // Add elements. if (sList != null) { String listString = sList.toString; listString = listString.subString(1, listString.length() - 1); } I somehow found this to be neater than using the StringBuilder/StringBuffer approach. Any tho...

BAT file to create Java CLASSPATH

I want to distribute a command-line application written in Java on Windows. My application is distributed as a zip file, which has a lib directory entry which has the .jar files needed for invoking my main class. Currently, for Unix environments, I have a shell script which invokes the java command with a CLASSPATH created by appending...

How can I change the color of a DecoratorPanel in GWT?

I see that it uses png images for the rendering, so I am assuming that means I need to provide my own version of these images, with colors changed appropriately. Where do I put these images, and how do I apply them in the CSS? ...

Cross-Compiling JRE/JDK

Have somebody experiences with cross-compiling the sun-java5 source package (debian) from i386/i586 to the hppa architecture? Or know a source for java for PA-RISC? I've found only the Package for HP-UX. Kaffe/gcj are not able to run my third-party java application ...

FileChannel & RandomAccessFile don't seem to work

To put it simple: a swing app that uses sqlitejdbc as backend. Currently, there's no problem launching multiple instances that work with the same database file. And there should be. The file is locked (can't delete it while the app is running) so the check should be trivial. Turns out not. File f = new File("/path/to/file/db.sqlite"...