简体   繁体   English

在Eclipse中创建GUI类

[英]Creating a GUI Class in Eclipse

What I'm thinking of doing is creating a class for my little subview, so I can use it over and over again. 我想做的是为我的小子视图创建一个类,因此我可以一遍又一遍地使用它。 Specifically, in my project, I need a colored rectangular and a label, and between those subviews those are the ones gonna change. 具体来说,在我的项目中,我需要一个彩色的矩形和一个标签,在这些子视图之间,这些将要更改。 Thus, I want a class that represent that two components as one component. 因此,我想要一个将两个组件表示为一个组件的类。

I'm trying to use swing. 我正在尝试使用秋千。 Before, I used acm package which gave me convenient way of doing it, but I can't solve that problem with swing. 以前,我使用acm包为我提供了方便的实现方法,但我无法通过swing解决该问题。 So, the problem starts here, I couldn't figure out how to create a custom GUI class for a subview. 因此,问题从这里开始,我无法弄清楚如何为子视图创建自定义GUI类。

I want to put them in a for loop later, so I want to handle the case in once rather than writing for 20 times manually. 我想稍后将它们放入for循环中,因此我想一次处理该情况,而不是手动编写20次。

Any help would be appreciated, 任何帮助,将不胜感激,

Create your custom class so that it extends a JPanel . 创建您的自定义类,以便它扩展JPanel From there, you can add your common subcomponents, which sets each one up by passing parameters through the constructor, and then implement any common behaviours with methods on that class. 从那里,您可以添加您的公共子组件,该子组件通过将参数传递给构造函数来设置每个子组件,然后使用该类上的方法实现任何常见行为。

You could try Window Builder plugin for eclipse for drag and drop editor. 您可以尝试使用Eclipse的Window Builder插件进行拖放编辑器。 You could try to figure what's going wrong by organizing you objects. 您可以尝试通过组织对象来找出问题所在。

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

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