How best to keep code and gui separated but harmonious

R

RichT

Hello,

I am wishing to create an image model class and will need some way to
display images.

I know that JFrame, JPanel and Canvas support displaying images and are
ideal candidates.

Rather than put all the code for image related functionality in one of
these components, I want to be able to create an image model class
separately taking one of these components or even a subclass of these
components but only this range of components and perform operations on
it I guess like an MVC but only two classes not three.

So as an example I have JFrame but do not want to display the image
directly on it but instead want to use a JPanel or a Canvas inside a
scroll pane and have my image model class perform the operations on the
JPanel or Canvas or subclass of.

So I know that the image model class would take a reference to the
JPanel, Canvas or a subclass of these but nothing else and the JFrame
would have a reference to the image model class.

Selecting menu or button items from the JFrame would invoke a command,
passed to the image model class which would execute the command and
apply changes to the JPanel, Canvas or subclass of one of these.

How would I even start I have read information on Generics and
Interfaces and can see either of these could be used but not sure where
to start.

I am not trying to create a photoshop clone :) but want basics like zoom
in out and area, rotate and flip. In time I will probably add new image
related functionality, but don't want to be tied to a JPanel or a Canvas
or anything, especially if a new component appears in the future which
maybe better suited?

I hope someone can understand what I am trying to achieve here I sort of
do but it is still a bit hazy and vague and not sure where to start or
how to start.

Thanks
Rich
 
S

Stefan Ram

RichT said:
So as an example I have JFrame but do not want to display the
image directly on it but instead want to use a JPanel or a
Canvas inside a scroll pane and have my image model class
perform the operations on the JPanel or Canvas or subclass of.

In MVC, the model does not act on the view, because
of the separation via the observer pattern.

The model only sends a message to notify the componente of the
changes. It does not tell the component what to do.
How would I even start I have read information on Generics and
Interfaces and can see either of these could be used but not
sure where to start.

Interfaces (and to some extend, type arguments) are
fundamentals of Java one always needs.
I hope someone can understand what I am trying to achieve here I sort of
do but it is still a bit hazy and vague and not sure where to start or
how to start.

You can read about the Swing architecture.

http://java.sun.com/products/jfc/tsc/articles/architecture/
 
J

Jeff Higgins

RichT said:
Hello,

I am wishing to create an image model class and will need some way to
display images.

I hope someone can understand what I am trying to achieve here I sort of
do but it is still a bit hazy and vague and not sure where to start or how
to start.

You might have a look at:
G - 2D Graphics Library and Rendering Engine for Java
Its author has graciously provided a free of charge
LPGL licenced easy to use and understand, with source.
<http://geosoft.no/graphics/>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,836
Latest member
BuyBlissBitesCBD

Latest Threads

Top