简体   繁体   English

哪个是此设计的更好的顶级容器,JFrame与Jpanels,或JDesktop与JInternalFrames

[英]Which is a better top level container for this design, JFrame with Jpanels, or JDesktop with JInternalFrames

I'm a beginner with Swing and AWT, I'm looking to build a GUI using Netbeans. 我是Swing和AWT的初学者,我正在寻找使用Netbeans构建GUI。 My GUI requires three areas, that I'm currently thinking of as JPanels on a JFrame. 我的GUI需要三个区域,我目前正在考虑将其作为JFrame上的JPanels。 I require a "Drawing" panel that will listen for mouse input and draw Java2D shapes. 我需要一个“绘图”面板,它将监听鼠标输入并绘制Java2D形状。 The drawing panel will be anchored to the top left. 绘图面板将固定在左上角。 The other two areas are a "Properties" scroll pane, and a "Controller" scroll pane. 另外两个区域是“属性”滚动窗格和“控制器”滚动窗格。 The controller pane will determine which drawn elements will be displayed via buttons, and the properties scroll pane will show details about any shape object that is clicked in the drawing pane (endpoints, color, etc..). 控制器窗格将确定将通过按钮显示哪些绘制元素,属性滚动窗格将显示有关在绘图窗格中单击的任何形状对象的详细信息(端点,颜色等)。

A typical use case for the drawing area is such that the first click in the drawing area will be the first set of co-ordinates for a shape, IE: a line. 绘图区域的典型用例是绘图区域中的第一次点击将是形状的第一组坐标,IE:一条线。 That click will be captured as a point2d object. 该点击将被捕获为point2d对象。 The second click will be the second point2D object, and a line will be built between the two. 第二次单击将是第二个point2D对象,并且将在两者之间构建一条线。 The controller area will have buttons like "Circle" "Line" "Elipse", etc. Depending on which controller button is clicked, only shapes of that type will be drawn in the drawing area. 控制器区域将具有“圆形”,“线”,“椭圆”等按钮。根据单击的控制器按钮,将仅在绘图区域中绘制该类型的形状。 The controller and properties scroll panes will not be moveable, they will be locked and resizable to the bottom and right sides of the GUI, respectively. 控制器和属性滚动窗格将不可移动,它们将分别锁定并可调整到GUI的底部和右侧。

As a beginner, I'm struggling with the best components to use. 作为初学者,我正在努力使用最好的组件。 I've been reading up on JDesktop and JInternalFrame, but it seems like I don't really need all that. 我一直在阅读JDesktop和JInternalFrame,但似乎我并不真的需要这一切。 A simple JFrame with three JPanels should suffice, right? 一个简单的JFrame有三个JPanel就足够了吧? More specifically, I think I need a top level JFrame, with a JPanel for the drawing frame and two JScrollPanels. 更具体地说,我认为我需要一个顶级JFrame,一个JPanel用于绘图框架和两个JScrollPanels。 I'll need a mouse listener on the drawing pane to capture the co-ordinates of each click, and listeners for each button in the control pane. 我需要在绘图窗格上使用鼠标监听器来捕获每次单击的坐标,以及控制窗格中每个按钮的监听器。 Can I put a mouse listener on a JPanel, and draw Java2D shapes to it, or will I need a different (better?) container inside the JPanel to do my drawing? 我可以在JPanel上放置一个鼠标监听器,并为其绘制Java2D形状,还是需要在JPanel内部使用不同的(更好的?)容器来进行绘图?

GraphPanel may give you some ideas for constructing such an application. GraphPanel可能会为您提供构建此类应用程序的一些想法。

GraphPanel截图

JInternalFrames typically have titlebars, go-away boxes etc. example here which doesn't seem to fit your model. JInternalFrames通常有标题栏,外带盒等。 这里的示例似乎不适合您的模型。 (Unless you want users to be able to move the panels anywhere they want, or make them go away?) So I'd suggest the simpler JFrame with JPanels. (除非你希望用户能够将面板移动到他们想要的任何地方,或者让它们消失?)所以我建议使用JPanels更简单的JFrame。

Consider two JSplitPanes to separate the drawing area, control area, and properties area. 考虑两个JSplitPane来分离绘图区域,控制区域和属性区域。 JSplitPane allows the user to resize the areas by clicking and dragging the split line with the mouse. JSplitPane允许用户通过单击并使用鼠标拖动分割线来调整区域的大小。

在此输入图像描述

(Use a JFrame for the top level component.) (将JFrame用于顶级组件。)

As a beginner, if you don't need resizing and scrolling, you will have a much easier time if you make an app that doesn't resize or scroll. 作为初学者,如果您不需要调整大小和滚动,那么如果您制作的应用程序不会调整大小或滚动,您将会更容易。

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

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