作者andy801119 (泰坦)
看板NTUE-CS103
标题[课业] 视窗程式考古题 2010期末文字档
时间Fri Dec 16 17:51:08 2011
1. 下列程式执行时会发生例外而中止执行,请在b=0及a/b不变的情况下,修改本程式使
不会因例外发生而中断执行。(10%)
public class app
{
public static void main(String args[])
{
int a=4,b=0;
System.out.println(a+"/"+b+"="+a/b);
}
}
-
2. 简单说明 public, private 及 protected 对类别成员及建构元存取的作用。(10%)
-
3. 下列程式执行的结果会不正确,请说明原因及如何修正。(10%)
class CBank
{
private static int sum=0;
public static void add(int n)
{
int tmp=sum;
tmp=tmp+n;
try
{
Thread.sleep((int)(1000*Math.random()));
}
catch(InterruptedException e){}
sum=tmp;
System.out.println("sum= "+sum);
}
}
class CCustomer extends Thread
{
public void run()
{
for(int i=1;i<=3;i++)
CBank.add(100);
}
}
public class app
{
public static void main(String args[])
{
CCustomer c1=new CCustomer();
CCustomer c2=new CCustomer();
c1.start();
c2.start();
}
}
-
4. 下面的程式希望产生乱数并将其写到档案 randow.txt,但实际执行时 random.txt并
没有存下任何内容,请说明如何修改程式使执行结果正确。(10%)
import java.io.*;
public class app
{
public static void main(String args[])
{
try
{
FileWriter fw=new FileWriter("c:\\random.txt");
BufferedWriter bfw=new BufferedWriter(fw);
for(int i=1;i<=5;i++)
{
bfw.write(Double.toString(Math.randow()));
bfw.newLine();
}
fw.close;
}
catch(IOException e){}
}
}
-
5. 请简要说明 Java 的"委派事件模式"的运作流程。(10%)
-
6. 若一个视窗物件其中包含一个按钮 (button) 物件及一个功能表的 MenuItem 物件,
这两个物件均会触发 ActionEvent 事件,假设有一个ActionEvent 事件被触发,请说
明如何设计程式使能区分是由何物件所触发。(10%)
-
7. 以 Java 绘图时,若需要重画时常会呼叫 update(),但是若图形会移动且呼叫很频繁
时会感觉会面闪烁,请说明其原因及解决方式。(10%)
-
8. 下列程式希望按按钮时会将视窗的背景颜色改为黄色,但程式尚有欠缺,请予以完成
。(10%)
import java.awt.*;
import java.awt.event.*;
public class app extends Frame implements ActionListener
{
static app frm=new app();
static Button btn=new Button("Click Me");
public static void main(String args[])
{
btn.addActionListener(frm);
frm.setLayout(new FlowLayout());
frm.setTitle("Action Event");
frm.setSize(200,150);
frm.setBackground(Color.blue);
frm.add(btn);
frm.setVisible(true);
}
}
-
9. 简单注解下列程式加底线粗体部分其意义。(10%) (这里用红字代替底线粗体)
import java.net.*;
import java.io.*;
public class app
{
public static void main(String args[])
{
try
{
ServerSocket svs=new ServerSocket(2525); //
Socket s=svs.accept(); //
OutputStream out=s.getOutputStream();
String str="Honor shows the man.";
out.write(str.getBytes());
out.close();
s.close(); //
}
catch(Exception e){}
}
}
-
10. 请简单画出下面 applet 及 html 程式合并执行的结果。(10%)
import java.awt.*;
import java.applet.Applet;
public class App extends Applet
{
public void paint(Graphics g)
{
g.drawString(getParameter("str1"),30,40);
g.drawString(getParameter("str2"),30,60);
}
}
<APPLET
CODE = "App.class"
WIDTH = "250"
HEIGHT = "120" >
<PARAM NAME = "str1" VALUE = "Repentance is a bitter physic." >
<PARAM NAME = "str2" VALUE = "Laughter is the best medicine." >
</APPLET>
--
不知道有没有打错或其他什麽的问题
之後有空再排版吧
系学会考古题快更新吧 嘿嘿
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 120.127.47.94
1F:推 NTUE:十二万分感谢你体谅迷有脸书的人 (〒皿〒) 12/17 08:22
2F:→ andy801119:发在这边有人看的感觉真好 12/19 03:22
3F:推 bennyt6182:没有问题 12/20 03:39
4F:推 dosomethnig:谢拉 12/21 16:11