今天上午左哥给我补课,讲了类的继承和接口。
方法有三种:普通,构造和抽象。类也有三种:普通,抽象和接口。extends只能单继承,但implements可多实现接口。
今天还做了图画板.可以实现画直线、矩形、椭圆和实心椭圆。
package draw;
import java.awt.FlowLayout;
import java.awt.Graphics;
import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JRadioButton;
public class Draw extends JFrame{
public static void main(String[] args) {
//创建一个当前类的对象
Draw draw = new Draw();
//调用对象的方法
draw.initFrame();
}
public void initFrame(){
this.setTitle("图画板");
this.setSize(500, 500);
this.setDefaultCloseOperation(3);
FlowLayout ly = new FlowLayout();
this.setLayout(ly);
//设置JRadioButton单选按钮
JRadioButton j1 = new JRadioButton("直线",true);
//逐个按钮设置名称
j1.setActionCommand("li