15.6(改进FigurePane1)程序清单15-3中的FigurePane1类可以显示直线、矩形、圆角矩形和椭圆。在类中添加合适的新代码来显示弧形和多边形。使用新的FigurePanel类编写测试程序,显示如图15-29a所示的图形。
程序代码;

package code;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class blogTryProject {
	public static void main(String[] args){
		TestPaintComponent tpc = new TestPaintComponent();
		tpc.main(args);
	}
}
class TestPaintComponent extends JFrame{
	public TestPaintComponent(){
		add(new NewPanel());
	
	}
	public static void main(String[]args){
		TestPaintComponent frame = new TestPaintComponent();
		frame.setTitle("Exerxise15_6");
		frame.setSize(260,190);
		frame.setLocationRelativeTo(null);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
	}
}
class NewPanel extends JPanel{
	protected void paintComponent(java.awt.Graphics g){
		super.paintComponent(g);
		g.fillArc(40, 100, 50,50, 0, 30);
		g.fillArc(40, 100, 50,50, 90, 30);
		g.fillArc(40, 100, 50,50你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧