}
30、仔细阅读下面的程序代码,若经编译和运行后,请写出打印结果。 class myException extends Exception{} public class Sample{ public void foo(){ try{
System.out.print(1); bar();
System.out.print(2); }catch(myException e){ System.out.print(3); } finally{
System.out.print(4); } }
public void bar() throws myException{ throw new myException(); }
public static void main(String args[]){ Sample s=new Sample(); s.foo(); } }
31、请简要画出编译运行下面程序的界面效果图。 import java.awt.*; import javax.swing.*;
public class ColorSelect extends JFrame { private JButton ok, cancel;
private JCheckBox background, foreground; private JComboBox colorList; private JPanel panel, panel2; private Container c; public ColorSelect(){
super( \ c=getContentPane();
c.setLayout(new BorderLayout());
colorList = new JComboBox(); colorList.addItem( \
c.add( colorList, BorderLayout.NORTH ); panel = new JPanel();
第 31 页 共 48 页
background = new JCheckBox( \ foreground = new JCheckBox( \ panel.add( background ); panel.add( foreground );
c.add( panel, BorderLayout.CENTER ); ok = new JButton( \
cancel = new JButton( \ panel2 = new JPanel(); panel2.add( ok ); panel2.add( cancel );
c.add( panel2, BorderLayout.SOUTH ); setSize( 300, 125 ); setVisible(true); }
public static void main ( String args[] ){ ColorSelect app = new ColorSelect();
app.setDefaultCloseOperation( EXIT_ON_CLOSE ); } }
32、仔细阅读下面的程序,简单的画出GUI的界面 import java.awt.*;
public class Test extends Frame { public Test() { super(\
setLayout(new BorderLayout());
add(new Button(\ add(new Button(\ add(new Button(\ add(new Button(\ add(new Button(\ }
public static void main(String args[]){ Test t=new Test(); t.pack(); t.show(); } }
33、仔细阅读下面的程序,写出程序的执行顺序(写出编号): public class UsingExceptions {
public static void main( String args[] ){ try{
method1(); // 1
第 32 页 共 48 页
}catch(Exception e){
System.err.println(e.getMessage()); // 2 }
finally{
System.out.println(\ } }
public static void method1() throws Exception { method2(); //4 }
public static void method2() throws Exception { method3(); //5 }
public static void method3() throws Exception{
throw new Exception( \ } }
34、阅读下面的程序:
public class Timer extends Thread{ int time=0;
public Timer(int time) { this.time=time; }
public void run(){ try{
for(int i=0;i