Create "firewalls" between different areas of the code. You do this by defining different areas or layers of code, and defining a single API (in Java, this is usually done with an interface) that each layer responds to. There should be bare-bones intefaces or classes that the API uses, but which "know" nothing about the internals of those layers. For instance, the gui should not know or care how you store data, and your database shouldn't know or care how the data is presented to the end user.
These APIs don't have to be cast in stone - you should be able to add things as necessary, as long as you make sure you aren't polluting the firewalls.