简体   繁体   English

如何实现java awt / swing应用程序

[英]how to implement java awt/swing application

I want to implement a java awt/swing application but i am new to awt/swing. 我想实现一个Java awt / swing应用程序,但是我是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: 首先,我将确保遵循Swing教程:

Then, I'd revisit your approach a little: I would use Swing components. 然后,我将稍微回顾一下您的方法:我将使用Swing组件。

  • Start with a JPanel on a JFrame. 从JFrame上的JPanel开始。
  • Add a JComponent to the panel for your grid. 将JComponent添加到网格面板。 Override the paintComponent method there to draw your grid. 覆盖那里的paintComponent方法来绘制网格。
  • Add other JComponents on top of that for your objects. 在该对象的顶部添加其他JComponent。 Again, override the paintComponent method for those to draw the appearance of your objects. 再次,为那些绘制对象外观的对象重写paintComponent方法。
  • 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. 然后,您可以使用JComponent提供的内置功能来允许单击,调整大小等。在每个事件中,您都可以重新绘制组件,以解决您在下次调用paintComponent需要显示的任何更改-如果需要repaint调用强制重画。

请不要使用public void paint(Graphics g){} void paintComponent(Graphics g){}此方法适用于AWT ComponentsBasicXxxUISwing 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... 对于绘画,单击机制等,您只能使用Java部分的PlayN ...

But if you want to use the swing capabilities to... I am not sure if you can mix playN with swing... 但是,如果您想将Swing功能用于...我不确定是否可以将playN与Swing混合使用...

But if you only relly on the GraphicsAPI awt.... than you will need to look up couple of things. 但是,如果您仅依赖GraphicsAPI awt ....,那么您将需要查找几件事。

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 这里真的很好

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM