类的继承与接口

本文介绍了Java中的类继承和接口概念,包括普通类、抽象类和接口的区别,以及extends的单继承和implements的多实现特性。此外,还提到了在实践中使用JRadioButton创建图形画板,并通过构造函数解决类间传值的问题。
摘要由CSDN通过智能技术生成

今天上午左哥给我补课,讲了类的继承和接口。

方法有三种:普通,构造和抽象。类也有三种:普通,抽象和接口。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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值