問1. (a) Component (b) Frame (c) Checkbox (d) TextField (e) FlowLayout
問2. b1 = new Button("Push me");
問3. g.fillOval(50,50,100,100);
問4. (a) mouseDragged (b) mouseReleased (c) mouseMoved (d) mouseEntered
問5. (a) javax.swing.* (b) JFrame (c) getContendPane() (d) add(b1) (e) new ButtonTestFrame()
配点: 問1 各6点 問2 10点 問3 10点 問4 各5点 問5 各6点 合計 100点
問1. 以下はAWTに関する説明である。説明している内容を以下の選択肢から選べ。
問2. 以下のプログラムを修正して、 ボタンに表示される文字を "Push me" になるようにせよ。 解答欄にはプログラムのうち変更した一行のみを書け。
import java.awt.*; import java.awt.event.*; class MyFrame extends Frame { Button b1; public MyFrame() { setTitle("My Button Application"); setSize(300, 200); setLayout(new FlowLayout()); b1 = new Button("Button1"); add(b1); addWindowListener(new MyWindowAdapter()); } } class MyWindowAdapter extends WindowAdapter { public void windowClosing(WindowEvent e) { System.exit(0); } } public class MyButtonTest { public static void main(String[] args) { MyFrame f = new MyFrame(); f.setVisible(true); } }
問3. 以下は、グラフィック描画を行うプログラムの一部である。 円の中を塗り潰すように、一行を書き変えよ。 解答欄には書き変えた一行だけを書け。
public void paint(Graphics g) { g.drawLine(50,50,150,150); g.drawLine(50,150,150,50); g.drawRect(70,70,60,60); g.drawOval(50,50,100,100); }
問4. 以下の説明に合うイベント処理メソッドの名前を選択肢から選べ
問5. 以下はSwingを使ったプログラムの例である。空欄[[[a]]]〜[[[e]]]を埋めよ。
import java.awt.*; import java.awt.event.*; import [[[a]]]; class ButtonTestFrame extends [[[b]]] implements ActionListener { JButton b1, b2, b3; public ButtonTestFrame() { Container contentPane = [[[c]]] ; setTitle("My Button Application"); setSize(300, 200); addWindowListener(new MyWindowAdapter()); contentPane.setLayout(new FlowLayout()); b1 = new JButton("Button1"); b2 = new JButton("Button2"); b3 = new JButton("Button3"); b1.addActionListener(this); b2.addActionListener(this); b3.addActionListener(this); // ボタン1をコンテントペインに追加 contentPane.[[[d]]]; // ボタン2を追加 contentPane.[[[省略]]]; // ボタン3を追加 contentPane.[[[省略]]]; } public void actionPerformed(ActionEvent ae){ } } class MyWindowAdapter extends WindowAdapter { public void windowClosing(WindowEvent e) { System.exit(0); } } public class MyButtonTest2n { public static void main(String[] args) { ButtonTestFrame f = [[[e]]]; f.setVisible(true); } }