我可以在其他类别中调用Stroke函数吗?

问题描述

我正在尝试在已创建的网格上打印行,我有2个类ControllerModel

这是我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 (将#修改为@)