解答例 - 実習課題2 - 1.ウィンドウの作成
(実習課題2)
実習課題1のプログラムに追加し、6.2のサンプルプログラムと同様のものを実現しなさい。
解答例
package com.techscore.ui.chapter1.exercise2;
/**
* SampleFrame.java
* TECHSCORE Javaユーザインタフェース1章 実習課題2
*
* Copyright (c) 2004 Four-Dimensional Data, Inc.
*/
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
public class SampleFrame extends JFrame {
public SampleFrame() {
super("SampleFrame");
super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
super.setSize(400, 400);
//MenuBarの作成
JMenuBar menuBar = new JMenuBar();
super.setJMenuBar(menuBar);
//Menuを作成
JMenu fileMenu = new JMenu("file");
menuBar.add(fileMenu);
JMenuItem openMenu = new JMenuItem("open");
fileMenu.add(openMenu);
}
public static void main(String args[]) {
SampleFrame frame = new SampleFrame();
frame.setVisible(true);
}
}

