如何解决我可以在其他类别中调用Stroke函数吗?
我正在尝试在已创建的网格上打印行,我有2个类Controller
和Model
这是我Controller
班上的
grid.gridx = 1;
grid.gridy = 0;
JButton input = new JButton("Press Me");
input.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("INPUT: forward");
m.getGraphics().drawLine(250,250,25);
}
});
当我按下按钮时,我希望在相应坐标的网格顶部打印一行,但是我无法在.setStroke
上调用getGraphics().
这是我的Model
班
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D graphics2d = (Graphics2D) g;
int width = getWidth();
int height = getHeight();
drawSimpleGrid(g,width,height);
}
我是否必须使用控制器类,当按下按钮时它会更改模型类内部的某些内容?如果是,请细分,因为我遇到困难
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。