私のアプリケーションにいくつかの問題があります。私はAWTコンポーネントだけでJButtonを作成しようとしています。主な問題は、例外があることです.QButton.QButton.addActionListener(QButton.java:83)です。 もし私が//this.addActionListener行にコメントすると、すべてがOKです。私のオブジェクトは、私はUI事に慣れていないんだけど、あなたのプログラムが自分自身を呼び出すするメソッドを呼び出そうとするので、あなたがStackOverflowException
取得する理由は、あるパネルaddActionListenerメソッドのStackoverflow例外
public class QButton extends Panel implements MouseListener,ActionListener{
public Label text;
ImagePanel image;
ActionListener listener;
public QButton(String text){
Label l = new Label(text);
this.add(l);
this.text=l;
this.setLayout(new GridBagLayout());
this.setBackground(Color.gray);
TextButtonActions ac1=new TextButtonActions(this);
this.addMouseListener(ac1);
this.text.addMouseListener(ac1);
}
public QButton(ImagePanel img){
this.setLayout(new GridLayout());
this.image=img;
this.add(image);
PictureButtonActions ac2=new PictureButtonActions(this);
this.image.addMouseListener(ac2);
}
public QButton(String text, ImagePanel img){
this.setBackground(Color.gray);
this.setLayout(new GridLayout());
Label l = new Label(text);
this.add(l);
this.text=l;
this.image=img;
this.add(image);
TAndPButtonActions ac3=new TAndPButtonActions(this);
this.image.addMouseListener(ac3);
this.text.addMouseListener(ac3);
}
public void setText(String txt)
{
this.text.setText(txt);
}
public String getText()
{
return(text.getText());
}
public void setImage(ImagePanel i)
{
this.remove(image);
this.image=i;
this.add(i);
//System.out.println("setImage");
this.validate();
}
public ImagePanel getImage()
{
return(image);
}
void addActionListener(ActionListener listener)
{
this.listener=listener;
this.addActionListener(listener);
}
}
ah別のスタックオーバーフローの問題stackoverflow !! – Gautam
あなたは何を期待していますか? 'this.addActionListener(listener);'は無条件に自分自身を – artistoex