我需要将jzy3d
canvas强制转换为java.awt.component,我想使用JCombobox和按钮在框架中显示图表,但是当我要将画布强制转换为component时,程序被删除。谢谢您的回答。我已经尝试过了,对我没有帮助。
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException:
org.jzy3d.plot3d.rendering.canvas.VoidCanvas cannot be cast to
java.awt.Component
at cz.bia.Launcher.lambda$setComponents$0(Launcher.java:63)
at java.awt.Button.processActionEvent(Button.java:409)
at java.awt.Button.processEvent(Button.java:377)
Launcher.java:
package cz.bia;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import cz.bia.model.IFunction;
import cz.bia.Yao.*;
import java.awt.*;
public class Launcher extends JFrame {
IFunction[] funs = {new FirstYao(), new SecondYao(), new ThirdYao(), new FourthYao(), new FifthYao(), new SixthYao(), new SeventhYao(), new EighthYao(), new NinthYao(), new TenthYao(),
new EleventhYao(), new TwelfthYao(), new ThirteenthYao(), new FourthteenthYao(), new FifteenthYao(), new SixteenthYao(), new SeventeenthYao(), new EighteenthYao(),
new NineteenthYao(), new TwentiethYao(), new TwentyFirstYao()};
String[] funsToMenu = {"1 Yao", "2 Yao", "3 Yao", "4 Yao", "5 Yao", "6 Yao", "7 Yao", "8 Yao", "9 Yao", "10 Yao", "11 Yao", "12 Yao", "13 Yao", "14 Yao NI",
"15 Yao NI", "16 Yao", "17 Yao", "18 Yao", "19 Yao NI", "20 Yao NI", "21 Yao NI" };
private JPanel contentPane;;
JPanel southPanel;
JPanel leftPanel;
private ChartModel chart;
public static void main(String[] args) throws Exception {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
new Launcher().setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public Launcher() throws Exception {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(600,600);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
southPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 50, 5));
leftPanel = new JPanel(new FlowLayout(FlowLayout.LEFT,0,0));
setComponents();
setContentPane(contentPane);
setContentPane(southPanel);
setContentPane(leftPanel);
}
private void setComponents() {
Button drawIt = new Button("Draw it");
JComboBox functions = new JComboBox(funsToMenu);
functions.setForeground(Color.gray);
functions.setFont(new Font("Arial", Font.PLAIN, 14));
functions.setMaximumRowCount(21);
leftPanel.add(functions);
drawIt.setVisible(true);
chart = new ChartModel(funs[functions.getSelectedIndex()]);
leftPanel.add(drawIt);
drawIt.addActionListener( e -> {
add( (Component) chart.getChart().getCanvas());
});
}
}
ChartMode.java:
package cz.bia;
import java.awt.Component;
import cz.bia.model.IFunction;
import org.jzy3d.chart.Chart;
import org.jzy3d.colors.Color;
import org.jzy3d.colors.ColorMapper;
import org.jzy3d.colors.colormaps.ColorMapRainbow;
import org.jzy3d.maths.Range;
import org.jzy3d.plot3d.builder.Builder;
import org.jzy3d.plot3d.builder.Mapper;
import org.jzy3d.plot3d.builder.concrete.OrthonormalGrid;
import org.jzy3d.plot3d.primitives.Shape;
import org.jzy3d.plot3d.rendering.canvas.Quality;
/**
* Created by Jakub on 11.10.2016.
*/
public class ChartModel extends Component {
private IFunction function;
private Chart chart;
private Mapper mapper;
public Shape surface;
public ChartModel(IFunction function){
this.function = function;
init();
}
public void init(){
Range range = new Range(-100,300);
int steps = 50;
surface = Builder.buildOrthonormal(new OrthonormalGrid(range, steps, range, steps), this.getMapper(this.function));
surface.setColorMapper(new ColorMapper(new ColorMapRainbow(), surface.getBounds().getZmin(), surface.getBounds().getZmax(), new Color(1, 1, 1, .5f)));
surface.setFaceDisplayed(true);
surface.setWireframeDisplayed(true);
surface.setWireframeColor(Color.BLACK);
this.chart = new Chart(Quality.Advanced, "swing");
chart.getScene().getGraph().add(surface);
}
private Mapper getMapper(IFunction function){
Mapper mapper = new Mapper() {
public double f(double x, double y) {
double [] param = {x,y};
return function.calculate(param);
}
};
this.mapper = mapper;
return mapper;
}
public Chart getChart() {
return chart;
}
public void setChart(Chart chart) {
this.chart = chart;
}
}
这为我工作。简单的解决方案,当我将jzy3d画布放到画布上并放入面板中时。
Chart chart = AWTChartComponentFactory.chart(Quality.Advanced, IChartComponentFactory.Toolkit.swing);
ChartScene scene = chart.getScene();
AWTCameraMouseController controller = new AWTCameraMouseController(chart);
Component canvas = (Component) chart.getCanvas();
canvas.addMouseListener(controller);
canvas.addMouseMotionListener(controller);
canvas.addMouseWheelListener(controller);
centerPanel.add(canvas, BorderLayout.CENTER);
问题内容: 我想从数据库中获取价值,就我而言,我曾经从数据库中获取价值,但是却遇到了这个错误 这是我的代码 任何帮助将是荣幸:) @raffian,你的意思是这样吗? 问题答案: 问题是 这将返回一个 对象数组 列表 (Object []), 其中包含表中每一列的标量值。Hibernate将使用ResultSetMetadata推断返回的标量值的实际顺序和类型。 解 相关连结 使用迭代器
问题内容: 为什么在我的程序中触发java.lang.ClassCastException? java.lang.ClassCastException:[Ljava.lang.Object; 无法转换为com.App.Equip] 该查询返回已回答(在CheckLists calsse中找到)但尚未由Equip对象回答的清单的列表 -这是代码: -我的java类: 我想将我的SQl查询的结果格式化
本文向大家介绍Swift投射,包括了Swift投射的使用技巧和注意事项,需要的朋友参考一下 示例 将函数应用于集合/流并创建新的集合/流称为投影。
问题内容: 调用以下代码时,试图将“ self”快速传递给C函数: 在这里将“自我”转换为UnsafeMutablePointer类型的理想方法是什么? 问题答案: 一个对象的指针(即,实例 引用类型 )可以被转换为一个(的夫特映射,在夫特3)和背部。在Objective-C中,您将编写 (有关这些转换的确切含义,请参见Clang ARC文档中的3.2.4桥接转换。) Swift 为此具有一种类型
问题内容: 我知道更新语句将不起作用,因为ID是INT类型,并且我正在那里替换varachar值。我如何更改查询,以便它实际上像这样执行? 谢谢你 问题答案: Op没有提到数据库,因此我将仅使用SQL Server,因为问题中的示例SQL看起来像TSQL。在SQL Server中有很多分割字符串的方法。本文介绍了几乎每种方法的优点和缺点: Erland Sommarskog撰写的“当表值参数无法剪
这个类用于进行raycasting(光线投射)。 光线投射用于进行鼠标拾取(在三维空间中计算出鼠标移过了什么物体)。 代码示例 const raycaster = new THREE.Raycaster(); const mouse = new THREE.Vector2(); function onMouseMove( event ) { // 将鼠标位置归一化为设备坐标。x 和 y 方向的