henderunal
henderunal

Reputation: 749

how to implement java awt/swing application

I want to implement a java awt/swing application but i am new to awt/swing. I need to draw a grid like panel. Than drag and drop some objects on it. Later than objects can be clickable and resizable. My application should look like this:

desired output

I am able to draw object with :

public void paint(Graphics g){}

but its too far away from what i want to do.

How can i implement this kind of application? What should i read and know to do this?

Upvotes: 1

Views: 687

Answers (3)

Darwly
Darwly

Reputation: 344

Do you need to develop everything from scratch?

For painting, clicking mechanics etc you can use PlayN only the java part...

But if you want to use the swing capabilities to... I am not sure if you can mix playN with swing...

But if you only relly on the GraphicsAPI awt.... than you will need to look up couple of things.

small graphics enigne for drawing with the pinpoint capability (simple collision detection) so you can check each object on click. Movement and repainting are easely managed with simple engine...

Here is really good page

Upvotes: 2

ziesemer
ziesemer

Reputation: 28687

First, I'd be sure to follow the Swing tutorials:

Then, I'd revisit your approach a little: I would use Swing components.

  • Start with a JPanel on a JFrame.
  • Add a JComponent to the panel for your grid. Override the paintComponent method there to draw your grid.
  • Add other JComponents on top of that for your objects. Again, override the paintComponent method for those to draw the appearance of your objects.
  • You can then use the built-in functionalities provided by JComponent to allow for clicking, resizing, etc. With each event, you can then redraw the component to account for any changes you need to display in the next call to paintComponent - calling repaint if necessary to force a redraw.

Upvotes: 2

mKorbel
mKorbel

Reputation: 109815

please don't use public void paint(Graphics g){} this method is for AWT Components and BasicXxxUI, for Swing JComponents is there method public void paintComponent(Graphics g){} more in Graphics tutorial

Upvotes: 2

Related Questions