I'm having an issue with maven I can't figure out.

I have two local projects, project1 and project2. Project1 has project2 as a dependecy as you would have any dependecy in maven declared. Everytime I make a change in project2 I have to install it into the local repository and run mvn eclipse:eclipse on project1 to get it up to date. When i debug project1 (in eclipse) and hit project2 code, the source is not avaliable (of course, unless I install with sources).

So what I want is project1 to know that project2 is a local project so that I don't have to install project2 every time I make a change. Is this possible? How is it done?



First step to unit testing is to make your code testable. I'll give you one example. In your mouseReleased method you have a lot of code that does some calculations and set some variables. What you could do here to make the code more testable is to move out the code into a new method that takes some input and procudes some output that is used to set the variables you want to set. It is best if the method does not have any side effects, i.e. everything that the method does has a local scope.

Then when you write your unit test you can test that single method to see if the input produces the desired output using relevant input data and expected outcome.

This is just a quick observation of your code, I'm not sure if what i suggested is applicable in this exact case. You can of course unit test without doing this but it might make life paintful as you will need to mock mouse events etc...

What you need to do is to download junit (junit4 preferably), how it is used depends on your dev environment. To write a junit test, simply create a test class, call it whatever you like and create your test method. In junit4 you annotate your method to tell junit that it is a test. For example

public class ATestClass {

    // This is one test, you can make as many as you like
    public void testSomething() {
        .... ...

This is a super non-trivial problem. Not just a matter of providing an algorithm. But I'm guessing your looking for a library providing eye tracking implementations. A quick google of "eye tracking java" gave me this:


which lead me to this:


which might be interesting.

First off, use of JApplet is prefferable over Applet since it supports Swing component architecture. So let your BallWorld class extend JApplet instead, it is essentially the same thing.

Then you should maybe override the init() method in your BallWorld class to set up you applet. You should instansiate your variables in init() instead of where you declare them.

I noticed that you call Thread.sleep in your paint method and then call repaint. This is not how you should set up animations. Have a look at the class javax.swing.Timer which lets you define a timer that will call a method a given number of times per second or something. You can then directly call paint or repaint each time the timer calls your callback method.

I don't know exactly why you get the error. Do you have a stack trace?

Well, for example a get method that, if the object that one asks for is null, creates that objects, and inserts it into some datastructure, populates its values etc..

I've also come across get methods that persists stuff to the database as a side effect. Theres nothing inherently wrong with this, but its simply bad code practice and makes everyone confused.

Can you be more specific? How do you setup your JTable? I'm pretty sure there is no limitation to how many rows a JTable can display.

something like this should work...

File rootDir = new File("/Path/to/dir/");
File[] filesAndDirectories = rootDir.listFiles();

the filesAndDirectories array contains everything in rootDir. You can search for filename given a regexp or something, go down to another directory etc...

I'm working with a huge software system with a lot of people being involved in the coding through many years. I'm noticing more and more that there is a lot of bad code, especially get methods here and there with huge side effects, which you totally not expect.

So it crossed my mind that it would be great with a unit test that detects side effects in get methods and reports them so we can clean up that bad code. But it seems kind of difficult, you would have to analyze the code somehow and make sure that nothing but returning of objects takes place.

Anyone have any experience of this and how to detect bad coding practices like these?





under "Writing a Custom Cell Renderer"

First of, do you have to implement your own list? There a many list implementations in java.

Recursive printing could look something like this.

public void print(SinglyLinkedList list) {
if ( list.size() == 0 ) return;
// print first element in list
// call print with a new list where the first element is removed from input list.

To print the list in reverse, you just need to switch the print and call line.

In the reverse list case you could maybe do something like this. You want to take out the first element and append it to the end of the rest of the reversed list.

public SinglyLinkedList reverse(SinglyLinkedList list) {
if ( list.size() == 0 ) return empty list;
reverse( rest of list ).appendToEnd( firstElement );

I think the title is quite clear, but is there a way (I'm using Xcode 4) to auto generate the methods defined in a c++ header file to a cpp file? I just want empty methods that are compatible with the definitions in the header. Can't find anything on this.


Hello Daddy! A couple of days might actually be enough. Gonna try this. Thanks!

Hmm, it sound like it might work, but would I really be able to shift the time as much as I want back and forward?

I think you can use AspectJ to inject code anywhere, but will require some setup, which I want to avoid. I found something on replacing bytecode that might do the trick also.


Yes I know that would work, but It's not possible. Its a huge system used in production with jars that it depend on that I don't have the sources to.

I would have to change all Date references to point to the new Date class.

Writing my own date class insn't an option at the moment. there's a lot of code already creating date and Calendar object in various ways that I don't know anything about. I want to set the system date and time externally without touching any code that accesses dates.

I was wondering if there is a way to mock Date and Calendar objects for testing purposes. In other words I want to programatically be able to change what new Date() and new Calendar() etc. returns independent of the system date. Something like setting the date for the jvm or something. I have no clue how it could be done.

Any thoughts?

I work at a software company that makes retail enterprise systems. I started hereright out of the university and have been working for about a year. The first couple of moths they gave me some time to familiarize myself with the systems and the code. I started of with minimal help/education from other engineers and then a lot of bugfixing, which they thought was a good way for me to learn and for them to evaluate if I was good enough.

Now after the learning period the work can be quite varying. Our requirements and roadmap team gathers info from different sources (customers, engineers...) and prioritizes work that needs to be done. In our team we look at the roadmap and plan sprints (we work with scrum). At the scrum meetings we divide up the work between ourselves and then do the work. It can be anything from bug fixing, buissness logic implementation, country customization, refactoring old (bad) code, researching new ideas, making implementation proposals, updating/writing documents, helping customer customiziation teams, making unit tests and other tests...

Our boss (The product manager) doesn't tell us directly what to do, he is responsible for what comes into the release/sprints and other stuff. While planning sprints we try to break down tasks into subtaskt and determine as good as we can the time it will take, and we only put in as much tasks in the sprint that we think we have time to do. More often that not we underestimate the ...

I'm searching for a java library/framework that makes printing easier. By easier I mean something that makes it possible to layout and format text/images and other elements in a document by defining layouts in html/xml or something. I also want the layout to be decoupled from rendering so the document can be printed to a screen, a4 printer, receipt-printer, or in general any arbitrary device that can show a document (But mostly different kind of printers).

Does anyone know of something like this? Are there any widely used libraries? Javas internal printing capabalities doesn't do much good. Have googled it for some time now and can't find anything that seems good enough. Any thoughts?


Call what from which other class?

You should explain what it is your trying to do. This makes no sense.

What do you mean by ArrayList of three classes?

You could create an ArrayList which hold Objects. Or maybe an interface class that the three classes have incommon.


public interface GeneralType {
public void someMethod();

// Use Object as the generic type and cast to something else later.
List theList = new ArrayList();

// Use an Interface as the generic type which the three classes inherit from.
List the List = new ArrayList();


Oh, I must have started answering before the posts were posted, did not see them.

Your problem description is a little unclear, but, first I'm noticing that the program only will terminate if "N" is typed, everything else is going to result in another game loop.

Secondly, the number you're guessing is going to be the same for every replay since a new number is not generated in the loop. You need to put the random number generation inside the while loop.

Can you elaborate on exactly what the problem is?

Well there is a java matlab interface:


I haven't tried it myself but it looks promising. What is that you want to do with matlab that needs more user interface than matlab provides? Matlab has alot of plotting and presentation tools. You will still need to have a matlab session running on the computer, so the program wont be standalone.

The first thing I'm noticing is that all your code is en the paint method. This method should only be overriden if you want to do custom painting like the painting you are doing in the beginning of the method. You should not add swing components to layouts etc. in this method. You should do it once when the program is started.

So move out the layout code for the radiobuttons and other swing components to another method that is called once by the constructor or something. The layout of the components will conform to their parent containers depending on what layout manager you use.

The paint(Graphics g) method will be called constantly while you are resizing a window or anytime anything needs to be painted onto the screen. So if you add new components for each time the method is called, you will get a hell of a lot buttons. And will probably be out of memory pretty fast.

On another note, you should preferrably override paintComponent(Graphics g) instead of paint(Graphics g). paint paints borders and children and stuff, and is calling paintComponent, while paintComponent is only responsible for painting itself.

Something like this...

String input = "123";
int parsedInput = 0;
try {
parsedInput = Integer.parseInt(input);
} catch(NumberFormatException nfe) {
// Handle incorrect input

stultuske commented: no idea why this should be negative, since it is an answer to what the OP originally asked +14

I took a shortcuts by assuming that the length of a label is never gonna get wider than the viewport, if it does, we'll burn that bridge when we come to it. I stumbled upon another weird thing while trying to layout components using GridBagLayout for one of the cards in the cardLayout. The GridBagLayouts contents where set to fill hor. and ver. and the scrollpane/viewport had no preferred size or max size set. What happened was that the card panels in the card layout started getting wider and wider. I Overrode paintComponent just to print out getBounds().width. The values where growing constantly every time paintComponent was called. Bug? Feature? Must one always set preferred size?

I have a JScrollPane that contains a JPanel with a CardLayout, which in turn contains two JPanels with some labels and stuff. I want the contents of the ScrollPane/ViewPort to never exceed the width of the viewport.

The problem I'm having is that when a label holds a lot of text, the components inside of the scroll are not completely visible, they dissapear a little on each side. Is there a way of forcing a max size for the scrollpane or something so its contens never gets larger that the scrollspanes horizontal width?

mKorbel commented: nice qurstio +11