java

How can I split up paint swing method in java?

I'm developing a fair sized hospital simulation game in java. Right now, my pain method is starting to look a little big, and I need a way to split it up into different sections... I have an idea, but I'm not sure if this is the best way. It starts by painting the grass, then the hospital building, then any buildings, then people, then a...

Creating dynamic data entry forms

Hi, I have a small project where I would like to generate dynamic data entry forms with a little bit of logic behind them. A simple use case might be a Football resulting form, so you have a button for a goalscorer, and when clicked the user will be prompted for a player. The form will then send a message (probably to a webservice, but...

Elegant ways to handle database views on hibernate entities?

One of the main reasons I use Hibernate is that it provides the flexibility to switch to another database without having to rewrite any code. But until now I did not figure out a good way to define additional views on the tables to which my hibernate entities are matched; I am still using simple SQL scripts for that. Is there a more el...

Best way to find value in List when list is sorted

Let's say I have a Java ArrayList, that is sorted. Now I would like to find the index of value x. What would be the fastest (without more than 30 lines of code) way to do this? Use of the IndexOf() method? Iterate through all values in a simple for loop? Use of some cool algorithm? We are talking about around let's say 50 integer keys. ...

Why doesn't AspectJ compile-time weaving of Spring's @Configurable work?

Update 5: I've downloaded the latest Spring ToolsSuite IDE based on the latest Eclipse. When I import my project as a Maven project, Eclipse/STS appears to use the Maven goals for building my project. This means AspectJ finally works correctly in Eclipse. Update 4: I have ended up just using Maven + AspectJ plugin for compile-time weavi...

Java Generate Random number {-1,0,1}

Hi- I need a function that will return a random integer that can be only -1, 0, or 1. Thanks? ...

How to get the ip of the computer on linux through Java ?

Hello, How to get the ip of the computer on linux through Java ? I searched the net for examples, I found something regarding NetworkInterface class, but I can't wrap my head around how I get the Ip address. What happens if I have multiple network interfaces running in the same time ? Which Ip address will be returned. I would reall...

Conversion of text to picture-message?

Friends, I need to know how to convert a text to a picture-message(.ota) format in JAVA for sending through mobiles? I am developing a software that sends the picture-message to another mobile via serial-port. Could anyone help for creating a routine for the conversion process? I need that routine to converts the given text/picture to a...

Implement binary search in objects

Is there any way to implement binary search in a ArrayList with objects? In this example the ArrayList will be sorted with the field 'id'. class User{ public int id; public string name; } ArrayList<User> users = new ArrayList<User>(); sortById(users); int id = 66 User searchuser = getUserById(users,id); How would the "User getUse...

Mutation error in Berkeley DB

I am using Berkely DB and I have an error which says that mutations are missing. What does this mean? Exception: com.sleepycat.persist.evolve.IncompatibleClassException: Mutation is missing to evolve class: TopMoveDAO.TopMoveClass version: 0 Error: java.lang.ClassNotFoundException: TopMoveDAO.TopMoveClasscom.sleepycat.persist.evolve.Inc...

How does JVM Classfile verifier works?

How does JVM classfile verifier perform class verification ? Could anyone please tell me the steps ? ...

EnumSet 'and' operation

I'm porting some old code that uses the int enum pattern to Enum and EnumSet. It is very easy but I don't know how translate the following code to EnumSet: : int mask = (kind == 'C' ? CLASS_MODIFIERS : kind == 'F' ? FIELD_MODIFIERS : kind == 'M' ? METHOD_MODIFIERS : (CLASS_MODIFIERS | FIELD_MODIFIERS ...

How to implement multilanguage in Java/Swing applications?

What are the different ways of implementing multilingual support in Swing applications? Are you using ResourceBundle with property file and implementing it in every frame? Does it work good for you? What if you use some kind of GUI editor? Is there any other way around? At work we are using Matisse4MyEclipse and the code gets regenerat...

Set property for all child components

I've never used Java AWT before and now I've got a piece of code that displays a JFrame and sets the font property for all child components to the same value. I'd like to set the property in one place only. How can I do this? In .NET/WinForms, child controls inherit from their parent controls, thus it would be enough to set the font for...

Exam Question <Java>

I was wondering if someone could look through my answers and tell me if i got it vaguely right or wrong, bearing in mind this was a written exam opposed to on a computer if not then thanks anyway a) The interface called selector has a single method called matches the method takes a single parameter of type object and returns a boolean...

How to I determine if an object exists for a given key in the Google AppEngine datastore using Java?

I'm trying to port the Sharding Counters example (code.google.com/appengine/articles/sharding_counters.html) to Java. The only problem is that the Java API does not have a call similar to Python's 'get_by_key_name'. This is the basic idea: Transaction tx = pm.currentTransaction(); Key key = KeyFactory.createKey(C...

Has anyone used ServiceLoader together with Guice?

I keep wanting to try this on a larger scale with our app + build system, but higher priorities keep pushing it to the back burner. It seems like a nice way to load Guice modules and avoids the common complaint about "hard coded configuration". Individual configuration properties rarely change on their own, but you will almost always hav...

healthy garbage collection metrics?

i profiled a jdbc/hibernate batch-importer. it takes a csv transforms it slighly and imports it to the database sitting at localhost. to my surprise the operation was not I/O bound but rather cpu-bound. according to jmx/jconsole as well as the netbeans profiler it looked like 60% of the cpu time was spent in the "old gen" garbage colle...

Is there a successor to Ant and Maven?

I ask out of ignorance. It's been over two years since I heard James Duncan Davidson say that Ant needed a successor, something more like a scripting language. It seemed that Maven 1/Jelly tried to do that, and Maven 2 has tried again in its way ("or the highway"), but without overwhelming success. Ant seems still to be the default an...

Access to report parameters from a custom JRDataSource

I wrote a JRDataSourceProvider and a JRDataSource in order to access a "crippled" JDBC resource from iReport (it's an HP3000 database and the JDBC driver I am using does not support parameters in PreparedStatements, which iReport's standard JDBC datasource seems to require). My JRDataSource needs to access report parameters. How do I do...