程序设计综合题
(程序填空和编程题)
一、程序填空,阅读下列程序并完成程序填空
1、 Java Applet小应用程序完成下列填空 3.2
import java.applet.*;
import java.awt.*;
public class test1_1 extends Applet
{
  public void paint(Graphics g)
{
  int x=2,y=1;
  switch (x+y)
  {
case 1:
  g.d);
  g.drawString(“我是红510)
  break;
case 2:
  g.setColor(Color.blue);
  g.drawString(“我是蓝510)
  break;
case 3:
  g.);
  g.drawString(“我是绿510)
  break;
default:
  g.drawString(“没有设置颜510)
}
}
}
<1>awt  <2> Applet  <3> Graphics  <4> switch  <5> default
2、 3.2
import java. applet .*;
import java.awt.*;
public class test1_1extends Applet
{
  public void paint(Graphics g)
  intsum=0 ;
for(int i=1; i<=100;i++)
    sum=sum+i;
g.drawString(“sum=”+sum,10,20);
}
<1> applet  <2> extends  <3> sum=0  <4> i<=100  <5> drawString
3  3.2
publicclass test1_1
{
  publicstaticvoid main(Stringargs[])
  {
int i,j;
panefor(j=2;j<=50;j++)
  for(i=2;i<=j/2;i++)
{if( j%i)  break;}
if(i>j/2)
System.out.pritnln(j+”是素数”);
}
}
<1> public  <2> static  <3> String  <4> j%i==0  <5> out
4  4.5
import java. applet.*;
import java.awt.*;
classChengji
{
  float f(float x,float y)
  {
return x*y;
}
}
class Xiangjia extendsChengji
{
  float f(float x,float y)
  {return x+y;}
}
public class test1_1 extends Applet
{
  Xiangjia  sum;
  public void init( )
  {sum=new Xiangjia( );}
  public void paint(Graphicsg)
  {g.drawString(“sum=”+sum.f(4,6),5,20);}
}
<1> applet  <2> class  <3> extends  <4> init( )  <5> Graphics
54.5
classStudent
{
  int number;String name;
  Student (int number,String name)
{this.number=number;this.name=name;
Systemout.println(“I am ”+name+”My number is”+number);}
}
class Univer_StudentextendsStudent
{
  boolean 婚否;
  Univer_Student(int number,String name,boolean b)
  {
  super (number,name);
  婚否=b;
  System.out.pritnln(“婚否=”+婚否);
}
}
public class test1_1
{
public static void main(String args[])
{
Univer_Student zhang=newUniver_Student(9901,”和小林”,false);}
}
<1> class  <2> Student  <3> extends  <4> super  <5> new
6  5.7
import java.applet.*;import java.awt;
class test1_extendsApplet
{Stringtom;
public voidinit( )
{
tom=”2203026206209021”;
}
public void paint(Graphicsg)
{
  if((tom.startsWith(“”220))&&(dsWith(“1”)||dsWith(“3”)))
  g.drawString(“tom 是吉林人,男性”,10,10);
}
}
<1> Applet  <2> String  <3> init()  <4> Graphics  <5> statsWith
75.11
import java.applet.*;
import java. awt .*;
public class test1_1 extendsApplet
{ Stringtom=”I am a good cat”;
int x,y,z;
public void paint(Graphics g)
{
x=tom.indexOf (“a”);y=tom.indexOf(“good”,2);z=tom.indexOf(“a”,7);
g. setColor(d);
g.drawString(“ ”+x+”:”+y+”:”+z,20,20);
}
}
<1> awt  <2> Applet  <3> String  <4> indexOf  <5> setColor
88.1
importjava.applet.*;
import java.awt.*;
public class test1_1 extends Applet
{
  TextFieldtext1, text2;
  public voidinit( )
  {
  text1=new TextField(“输入密码:10)text1.setEditable(false);
  text2=new TextField(10);
  text2. setEchoChar (‘*’);
  add(text1);add(text2);
}
}
<1> import  <2> Applet  <3> TextField  <4> init()  <5> setEchoChar
89.1
importjava.applet.*;
import java.awt.*;
public class test1_1 extendsApplet
{
Button button1,button2;
public void init( )
{
  button1=new Button();
  button2=new Button(“确定”);
  add (button1);add(button2);
}
}
<1> import  <2> Applet  <3> Button  <4> init()  <5> add
910.1
  import java. applet  .*;
  import java.awt.*;
  public class Test1_1 extendsApplet
  {
Labellabe1;
TextFieldtext1;
public void init()
{
  label1=new Label(“输入姓名”);
  label1. setBackgound(d);
  text1=new TextField(10);
add(label1);add(text1);
}
}
<1> applet <2> extends <3> Label <4> TextField  <5> setBackgroud
1011.1
import java.awt.*;
import java.applet.*;
public class test1_1 extends Applet
{
  panelp;
Scrollpanescrollpane;
  public void init( )
{
  p=newPanel();
  scrollpane=new Scrollpane(Scrollpane.SCROLLBARS_ALWAYS)
}
}
<1>extends  <2> Panel  <3> ScroolPane  <4> init()  <5> new
11 13.1
import java.applet.*; import java.awt.*;
class Mypanel1 extendsPanel
{
Checkbox box1,box2;
Mypanel1()
{
  box1=new Checkbox("女生");
  box2=new Checkbox("男生");
  add(box1);add(box2);
}
}
public class Test1_2 extendsApplet

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。