文档介绍:课程名称: 《面向对象java语言程序设计》
指导老师:王建民
学号: 姓名: 班级:
实验目的与要求:
1、学习Java的applet类以及他的基本方法。
2、掌握异常处理的基本方法;基本的异常类;能创建自己的异常。3、用已学知识编制程序。
实验内容与步骤
:通过参数给Applet程序传递不同字号、不同颜色、文本内容的例子。
:
<html>
<Applet code= width=300 height=100>
<param name=text value="带有颜色的文本">
<param name=size value=30>
<param name=color value=007000>
</Applet>
</html>
:
import .*;
import .*;
public class AP3 extends Applet
{
private String text;
private int size,color;
public void init()
{
text = getParameter("text") //获得文本参数
size = (getParameter("size")); //获得字体大小
color= (getParameter("color"),16);//获得颜色值
}
public void paint(Graphics g)
{
Color c = new Color(color);
(c);
Font f=new Font("",1,size);
(f);
(text, 10, 50); //显示指定大小颜色的字符串
}
}
2、验证程序,输入6个整数后会出现什么异常? 并对下列程序进行注释。
import .*;
public class ExceptionClass1
{
public ExceptionClass1 ()
{
}
public static void main(String[] args)
{
int[] nArray = new int[5];
int n;
try
{
("请输入6个整数,看看会发生什么?");
for (n =0;n<+1;