###前提・実現したいこと
グローバル変数としてflagを宣言し、メソッドpublic void actionPerformed(ActionEvent e)において、どのボタンが押されたかをflagに登録した後、repaint()により、 メソッドpublic void paint(Graphics g)を呼び出すこと。
メソッドpublic void paint(Graphics g)においてflagの値によりif文の判別を行い、旗を描画すること。
###発生している問題・エラーメッセージ
国旗を描いたファイル(Germany.java)などを用意したのですが表示されません。正しく表示されるようになるソースコードを教えていただきたいです。よろしくお願いします。
###ソースコード
///Button
import java.awt.;
import java.awt.event.;
class ColorButton extends Frame implements ActionListener{
Button[] btn;
String[] ttl={"Germany","Indonesia","Romania","Exit"};
final int N=4;
ColorButton(String s, int w, int h){
super(s);
int i;
setSize(w,h);
btn=new Button[N]; for(i=0;i<N;i++){ btn[i]=new Button(ttl[i]); btn[i].addActionListener(this); } Panel p=new Panel(); for(i=0;i<N;i++) p.add(btn[i]); p.setBackground(Color.pink); add(p,BorderLayout.SOUTH); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e){ System.exit(0);} }); } public void actionPerformed(ActionEvent e){ if(e.getSource()==btn[0]) ;Germany.java else if(e.getSource()==btn[1]) ;Indonesia.java else if(e.getSource()==btn[2]) ;Romania.java else System.exit(0); } public static void main(String[] args){ ColorButton a=new ColorButton("National flag",300,200); a.setVisible(true); }
###補足情報(言語/FW/ツール等のバージョンなど)
java
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/01/13 02:58