📄 mycanvas.java
字号:
import java.awt.*;
import javax.swing.*;
class MyCanvas extends JPanel
{
int shape;
public MyCanvas(){shape=3;}
public void setShape(int shape){ this.shape=shape;}
public void paint(Graphics g)
{
if(shape==1)
{
Polygon filledPolygon=new Polygon();
filledPolygon.addPoint(50,50);
filledPolygon.addPoint(100,100);
filledPolygon.addPoint(0,100);
g.drawPolygon(filledPolygon);
}
if(shape==2)
{
/*Polygon filledPolygon=new Polygon();
filledPolygon.addPoint(50,50);
filledPolygon.addPoint(100,50);
filledPolygon.addPoint(100,100);
filledPolygon.addPoint(50,100);
g.drawPolygon(filledPolygon);*/
g.drawRect(5,50,100,100);
}
if(shape==3)
{
g.drawOval(50,50,100,100);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -