【发布时间】:2021-07-16 19:41:28
【问题描述】:
我被要求使用课本中的代码进行作业。 如何将数据从 Frame 转换为 Canvas? 例如,
public class test extends Frame {
public static void main(String[] args) {new DefPoly();}
int position = -1;
test() {
xxxxx
});
setSize(500, 300);
Button button1 = new Button("lower end points");
Button button2 = new Button("upper end points");
button1.setBounds(20, 30,100,20);
button2.setBounds(20, 60,100,20);
add(button1);
add(button2);
add("Center", new Cvtest());
setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
setVisible(true);
}
}
class CvTest extends Canvas {
CvTest(){
xxxxxxx
}
int position=1;
int x1, y1, x2, y2;
public void paint(Graphics g) {
g.drawLine(position*x1, y1, x2, y2);
}
}
代码只是一个例子,我想通过position来控制线的方向。因此,我在 Frame 中添加了actionListener,但未能更改position 的值。我需要了解更多关于 MCV 的信息吗?
【问题讨论】: