import java.awt.*; import jova.awt.event.*; import java.io.*; import javax.swing.*; public class ImageViewer { public stratic void main(String[]args) { JFrame frame=new ImageViewer Frame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.show(); } } class ImgeViewerFrame extends JFrame { public ImageViewerFrame() { setTitle("ImageViewer"); setSize(DEFAULT_WIDTH,DEFAULT_HEIGTH); label = new JLAbel(); Container contentpane = getContentpane(); contentpane.add(label.BorderLayout.CENTER); chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(".")); Button button = new Button("open"); contentpane.add(button,BorderLayout.SOUTH); button.addActionListener(new ActionListener() { public void actionperformed(ActionEvent evt) { int r = chooser.showOpenDialog(null)); if(r = = JFilechooser.APPROVE_OPTLON) { String name =________________ _______________ } } }); } private JLabel label; private JFileChooser chooser; private static final int DEFAULT_WIDTH = 300; private static final int DEFAULT_HEIGHT = 400; } 3.下面是一个Applet程序,其功能是接收用户输入的两个整数,比较它们的大小,并在用户按下“比较”按钮后,将Applet中显示的“请先输入两个待比较的整数”,改为“两个整数中最大值是:x”,x是两个数中的最大值.请改正程序中的错误(有下划线的语句),使程序能输出正确的结果. 注意:不改动程序的结构,不得增行或删行. import java.applet.*; import java.awt.*; import java.awr.event.*; public class FindMax extends Applet implements ActionListener{ Label result; TextField in1,in2; Button btn; int a=0,b=0,max; public void init(){ result = new Label"请先输入两个待比较的整数"); in1=new TextField(5); in2=new TextField(5); btn=new Button("比较"); add(in1); add(in2); add(btn); add(result); btn.addActionListener(this); } public void actionperformed(ActionEvent e){ a=in1; n=in2; if(a>b) max=a; else max=b; btn.setText("两个数中最大值是:"+max); } } findmax.html: 参考答案
公共基础知识
一:选择题: (1) D (2) C (3) D (4) B 二:填空题: |