java如何在swing中创建多维数据集?
我试图创建一个类,当被JPanel
调用时,它会创建一个多维数据集。我看到的是一种叫做ColorCube
的方法,它需要某种类型的“{Canvas
,尽管我没有发现这种方法与JPanel
兼容
为了澄清,我不是问如何创建自定义JComponent
(确切地说),也不是问如何添加颜色或旋转它,而是问如何创建一个类,当JPanel
调用该类时,该类会将多维数据集呈现到屏幕上
你可以在下面搜索框中键入要查询的问题!
我试图创建一个类,当被JPanel
调用时,它会创建一个多维数据集。我看到的是一种叫做ColorCube
的方法,它需要某种类型的“{Canvas
,尽管我没有发现这种方法与JPanel
兼容
为了澄清,我不是问如何创建自定义JComponent
(确切地说),也不是问如何添加颜色或旋转它,而是问如何创建一个类,当JPanel
调用该类时,该类会将多维数据集呈现到屏幕上
# 1 楼答案
您真正需要的是
x, y, and size
传递给Cube
类,然后获取这些参数,并为第一个正方形和第二个移位正方形构建一个角点数组。请参阅
Cube
类中的方法getCubeOnePoints
和getCubeTwoPoints
方法画第一个正方形。绘制第二个正方形,并连接点阵列中的点。请参阅
Cube
类中的drawCube
方法创建传递必要参数的
Cube
类的实例,并绘制多维数据集。参见CubePanel
构造函数和paintComponent
方法更新
只需创建方法来移动
x
或y
并调用它,然后重新绘制。该方法可能类似于在下面的例子中,我只是用←键
# 2 楼答案
现在为主文件创建另一个类
如果更改窗口的尺寸,则立方体的大小也将增大/减小