石田修二 > コンピュータメモ > Java > (サイト内検索)
次のプログラムを修正し、2つのラベルを配置して下さい。なお、名前は MainFrame.java とすること。
String の配列を使い、for 文で処理する
import java.awt.Button; // ボタンの作成
import java.awt.Color;
import java.awt.Frame;
import java.awt.Label;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; // ボタンクリックのイベントを受信する
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
public class MainFrame extends Frame implements WindowListener, ActionListener {
private Panel panel;
private Button deleteButton; // 削除ボタン
/* コンストラクタ */
public MainFrame() {
panel = new Panel();
panel.setBackground(Color.LIGHT_GRAY);
add(panel, "North");
deleteButton = new Button("削除");
deleteButton.addActionListener(this);
panel.add(deleteButton);
Label label = new Label("緑の色");
panel.add(label);
addWindowListener(this);
}
/* ActionListener */
public void actionPerformed(ActionEvent arg0) {
if (arg0.getSource() == deleteButton) {
System.out.println("削除ボタンが押されました。");
}
}
/* WindowListener */
public void windowClosing(WindowEvent arg0) {
dispose(); // ウィンドウを閉じる
}
public static void main(String[] args) {
MainFrame frame = new MainFrame();
frame.setTitle("図形描画ツール"); // ウィンドウのタイトル
frame.setLocation(300, 200); // ウィンドウの表示位置
frame.setSize(640, 480); // ウィンドウサイズの指定
frame.setVisible(true); // ウィンドウを表示
}
public void windowActivated(WindowEvent arg0) {
}
public void windowClosed(WindowEvent arg0) {
}
public void windowDeactivated(WindowEvent arg0) {
}
public void windowDeiconified(WindowEvent arg0) {
}
public void windowIconified(WindowEvent arg0) {
}
public void windowOpened(WindowEvent arg0) {
}
}
リンクはご自由にどうぞ。
【石田修二トップページ】 【コンピュータメモ】 【Java】
Last modified: 2016-03-09 14:50:19