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:
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?
First, I'd be sure to follow the Swing tutorials:
Then, I'd revisit your approach a little: I would use Swing components.
paintComponent
method there to draw your grid. paintComponent
method for those to draw the appearance of your objects. paintComponent
- calling repaint
if necessary to force a redraw. 请不要使用public void paint(Graphics g){}
void paintComponent(Graphics g){}
此方法适用于AWT Components
和BasicXxxUI
, Swing JComponents
是否可以使用Graphics教程中的方法public void paintComponent(Graphics g){}
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...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.