更多"阅读下列程序,请写出该程序的功能 。 import java. aw"的相关试题:
[简答题]阅读下列程序,请写出该程序的功能。
import java. awt. *;import java. awt. event. *;import java. applet. *;
public class Test34 extends Applet implements ActionListener
String msg=" ";Button bList[]=new Button[3];
public void init( )
Button yes=new Button("Yes");Button no=new Button("No");
Button maybe=new Button("Undecided");
bList[0]=(Button)add(yes);bList[1]=(Button)add(no);
bList[2]=(Button)add(maybe);
for(int i=0;i<3;i++) bList[i].addActionListener(this);
public void actionPerformed(ActionEvent ae)
for(int i=0;i<3;i++)
if(ae.getSource( )==bList[i])
msg="You pressed"+bList[i].getLabel( );
repaint( );
public void paint(Graphics g)g.drawString(msg,6,100);
[简答题]阅读下列程序,请写出该程序的功能。
import Java. applet.*;import javax. swing.*;
import java. awt.*;import Java. awt. event.*;
public class Test34 extends Applet implements ActionListener
JTextField text;int r;JPanel panel;
public void paint(Graphics g)
Graphics gc=panel. getGraphics( );
gc. clearRect(0,0, panel. getWidth( ),panel. getHeight( ));
gc. setColor(Color.red);gc.fillOval(10,10,r,r);
public void init( )
text=new JTextField(10);panel=new JPanel( );
setSize(200,100);setLayout(new GridLayout(2,1));
add(text);add(panel);text.addActionListener(this);
public void actionPerformed(ActionEvent e)
if(e. getSource( )==text)
r=Integer. parseInt(text. getText( ));
repaint( );
[简答题]阅读以下程序,请写出该程序的输出结果。
class CurrentThreadDemo
public static void main(String args[])
Thread t=new Thread( );System. out. println("Current thread");
t.setName("My Thread");System. out. println("After name change");
try for(int n=3;n>0;n--)
System. out. println(n);Thread. sleep(1000);
catch(InterruptedException e)
System.out.prindn("Main thread interrupted");
[简答题]阅读下列程序,请写出该程序的输出结果。
class MyThread extends Thread
String message,int s;
MyThread(String message,int sec)this. message=message;s=sec;
public void run( )
trysleep(s);catch(InterruptedException e)
System. out. println(message+" "+getPriority( ));
class ThreadTest
public static void main(String args[])
Thread foo=new MyThread("Foo",1000);
foo. setPriority(Thread.MIN_PRIORITY);foo.start( );
Thread bar=new MyThread("Bar",800);
bar.setPriority(3);bar.start( );
Thread gar=new MyThread("Gar",400);
gar. setPriority(7);gar.start( );
Thread kar=new MyThread("Kar",100);
kar. setPriority(Thread.MAX_PRIORITY);kar.start( );
注:假设处理机中没有其他线程占用资源。
[简答题]阅读下列程序,请写出该程序的输出结果。
class Tree
private String name;public boolean flower;
public int birthYear;
Tree(String n,boolean f,int y)name=n;flower=f;birthYear=y;
public void setName(String n)name=n;
public String getName( ) return name;
public void printTree (String str)
System. out. println(str);System. out. println("Name:"+name);
System. out.println("Birth Year:"+birthYear);
System. out. println("Flower:"+flower);
class PineTree extends Tree
public boolean coniferous=true;
PineTree(String n,boolean f,int y,boolean c)super(n,f,y);coniferous=c;
public void printTree(String str)
super. printTree (str);
System. out. println("Coniferous:"+coniferous);
class Test32
public static void main(String[] args)
Tree fOb=new Tree("May Flower",true,1980);
PineTree sOb=new PineTree("Pine",false,2000,true);
fOb. printTree("fOb:");sOb. printTree("sOb:
[简答题]阅读下列程序,请写出该程序的输出结果。
class Test33
String myString="1";
public static void main(String args[])
Test33 myObj=new Test33( );
myObj. stringModifier(myObj. myString);
System. out. println(" "+myObj. myString);
void stringModifier(String theString)
theString=theString+"2";System. out. print(theString);
[简答题]阅读下列程序,请写出该程序的输出结果。
class Test32a
String name;int age;long number;
Test32a(long number,String name,int age)
System. out. println("Name:"+name);
System. out. println("Age:"+age);
System. out. println("Tel:"+number);
class Test32b extends Test32a
Test32b(long number,String name,int age,boolean b)
super(number,name,age);System. out. println("Married:"+b);
public class Test32
public static void main(String args[])
Test32b abc=new Test32b(4747,"Tony",29,true);
[简答题]阅读下列程序,请写出该程序的输出结果。
class Test33
static void s(int b[],int k)
int i,j,t;
for(i=1;i<k;i++)
for(t=b[i],j=i-1;j>=0&&t<b[j];j--)
b[j+1]=b[j];
b[j+1]=t;
public static void main(String[]args)
inti,a[]=6,12,7,11,5;
s(a,5);
for(i=0;i<a.length;i++)System. out. print(a[i]+¨¨);
System. out. Println( );
[填空题]下面程序段是从对象流中读取对象,请将程序补充完整。
import java. util.*;
import java. io.*;
public class UnSerializaDate
Date d=null;
UnSerializaDate( )
try
FileInputStream f=new FileInputStream("date. ser");
ObjectInputStream s=new ObjectInputStream(f);
【13】
f. close( );
catch(Exception e)
e. printStackTrace( );
public static void main(String args[])
UnSerializaDate a=new UnSerializaDate( );
System. out. println("The date read is:" +a.d.toString( ));
[填空题]请写出下面程序的运行结果:
public class Test extends TT
public static void main(String args[])
Test t=new Test("Tom.");
public Test(String s)
super(S);
System.out.print("How are you");
public Test( )
this("I am Jack.");
class TT
public TT( )
System.out.print("Hi!");
public TT(String s)
this( );
System.out.print("I am" +s);
结果:______。
[填空题]请写出下面程序的运行结果:
public class Test extends TT{
public static void main(String args[]
Test t=new Test ("Tom.");
}
public Test(String s){
super (s);
System.out.print("How are you");
}
public Test( ){
this("I am Jack.");
}
}
class TT{
public TT( ){
System.Out.print ("Hi!");
}
public TT(String s){
this ( );
System.out.print("I am"+s);
}
}
结果: 【15】 。
[填空题]请写出下面程序的运行结果:
public class Test extends TT{
public static void main(String args[]){
Test t=new Test("Tom.");
}
public Test(String s){
super(s);
System.out.print("How are you");
}
public Test( ){
this("I am Jack.");
}
}
class TT{
public TT( ){
System.out.print("Hi!");
}
public TT(String s){
this( );
System.out.print("I am"+s);
}
}
结果【 】。
[简答题]请写出下列程序段的输出结果,并说明理由。
X=2
Y=3
X, Y
DO SUB1
X, Y
PROCEDURE SUB1
PRIVATE Y
X=4
Y=5
RETURN
[简答题]请写出在Windows中,启动应用程序的两种方法。
[简答题]请写出Java语言中编写事件处理程序的两种方案。
[简答题]请写出下面C语言程序输出结果。
#include<stdio.h>
int x=3;
void main( )
{int i;
for(i=1;i<x;i++)incre( );)
void incre( )
{ static int x=1;
x=x+1;
printf("%d",x);
}
[简答题]当Client程序和Server程序需要通信时,可以用Socket类建立套接字连接,请写出双方实现通信的两种方式。
[简答题]请写出TCP/IP网络的层次结构,并简述数据链路层的功能。