问题描述
我是Swing and Awt的初学者,我希望使用NetBeans建造GUI.我的GUI需要三个领域,我目前在jframe上认为是jpanels.我需要一个"绘图"面板,该面板将收听鼠标输入并绘制JAVA2D形状.绘图面板将固定在左上方.其他两个区域是"属性"滚动窗格,还有一个"控制器"滚动窗格.控制器窗格将确定将通过按钮显示哪些绘制元素,并且属性滚动窗格将显示有关绘图窗格中单击的任何形状对象的详细信息(端点,颜色等).
绘图区域的典型用例是,在绘图区域中的第一次单击将是形状的第一组坐标,即:一条线.该点击将被捕获为Point2D对象.第二次点击将是第二个点2D对象,并且将在两者之间构建一条线.控制器区域将具有"圆""线"" Elipse"等按钮.取决于单击哪个控制器按钮,仅在图纸区域中绘制该类型的形状.控制器和属性滚动窗格将不可移动,它们将分别锁定并分配到GUI的底部和右侧.
作为初学者,我正在努力使用最佳的组件.我一直在阅读Jdesktop和Jinternalframe,但似乎我真的不需要所有这些.带有三个Jpanels的简单Jframe应该足够了,对吗?更具体地说,我认为我需要一个顶级jframe,带有jpanel的绘图框架和两个JSCrollpanels.我需要在绘图窗格上的鼠标侦听器来捕获每次点击的坐标,以及控制窗格中每个按钮的侦听器.我可以将鼠标侦听器放在jpanel上,并绘制java2d的形状,还是我需要在jpanel内部使用一个不同的(更好的?)容器才能进行绘图?
推荐答案
GraphPanel 可能会给您一些想法应用. "它具有可移动的,可重大的,可通过边缘连接的彩色节点."
其他推荐答案
jinternalframes通常具有titlebars,go-away盒子等" rel =" nofollow">此处的示例似乎不适合您的模型. (除非您希望用户能够将面板移动到他们想要的任何位置,或者让他们离开?)所以我建议使用JPanels更简单的Jframe.
其他推荐答案
考虑两个JSplitpanes,以分离图形区域,控制区域和属性区域. JSPlitpane允许用户通过使用鼠标单击和拖动拆分线来调整区域大小.
(使用Jframe作为顶级组件.)
作为初学者,如果您不需要调整和滚动大小,那么如果您制作不调整或滚动大小的应用程序,您将有更轻松的时间.
问题描述
I'm a beginner with Swing and AWT, I'm looking to build a GUI using Netbeans. My GUI requires three areas, that I'm currently thinking of as JPanels on a JFrame. I require a "Drawing" panel that will listen for mouse input and draw Java2D shapes. 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. That click will be captured as a point2d object. The second click will be the second point2D object, and a line will be built between the two. 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.
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. A simple JFrame with three JPanels should suffice, right? More specifically, I think I need a top level JFrame, with a JPanel for the drawing frame and two 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?
推荐答案
GraphPanel may give you some ideas for constructing such an application. "It features moveable, resizable, colored nodes connected by edges."
其他推荐答案
JInternalFrames typically have titlebars, go-away boxes etc. example here which doesn't seem to fit your model. (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.
其他推荐答案
Consider two JSplitPanes to separate the drawing area, control area, and properties area. JSplitPane allows the user to resize the areas by clicking and dragging the split line with the mouse.
(Use a JFrame for the top level component.)
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.