文字列配列の参照
●サンプル
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class Figure extends JFrame implements ActionListener{
public Figure(String name) {
setTitle(name);//フレームタイトル
setLocation(300,200);//フレーム位置
setSize(300,200);//フレーム大きさ
getContentPane().setBackground(Color.CYAN );
getContentPane().setLayout(new FlowLayout());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//フレーム閉じるボタン
}
public void actionPerformed ( ActionEvent e){//ボタン押下時
if(getContentPane().getBackground() == Color.CYAN) {
getContentPane().setBackground(Color.GREEN);
}else{
getContentPane().setBackground(Color.CYAN);
}
}
}
public class sample {
public static void main(String[] args){
Figure figure = new Figure("Frame");
JButton bt1 = new JButton("Change Color");//ボタン
figure.getContentPane().add(bt1);
bt1.addActionListener(figure);
figure.setVisible(true);//フレーム表示
}
}
●実行結果