源代码
package Experiments
;
import javax
.swing
.*
;
import java
.awt
.*
;
public class Experiment76 {
public static void main(String
[] args
) {
new PaintShape();
}
}
class PaintShape extends JFrame{
public PaintShape(){
setTitle("绘制图形");
setSize(300, 200);
JPanel pan
= new MyPanel();
add(pan
);
pan
.setBounds(0, 0, 300, 200);
setDefaultCloseOperation(JFrame
.EXIT_ON_CLOSE
);
setVisible(true);
}
class MyPanel extends JPanel{
public void paintComponent(Graphics g
){
g
.setColor(Color
.black
);
g
.drawRect(50, 50, 50, 50);
g
.fillRect(120, 50, 50, 50);
g
.drawOval(50, 120, 50, 50);
g
.fillOval(120, 120, 50, 50);
}
}
}
运行结果
转载请注明原文地址:https://ipadbbs.8miu.com/read-45275.html