サブクラスがありますが、何らかの理由でメインクラスのフィールドを継承しないという問題があります。私はプライベートではなくパブリックを作成しようとしましたが(とにかくサブクラスからプライベートフィールドにアクセスできるはずですが)、それでもうまくいきませんでした。サブクラスが親クラスフィールドを継承していません
package com.testfoler;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Fenetre extends JFrame {
private Panneau pan = new Panneau();
public JButton bouton = new JButton("Go");
public JButton bouton2 = new JButton("Stop");
private JPanel container = new JPanel();
private JLabel label = new JLabel("Le JLabel");
public Fenetre() {
this.setTitle("Animation");
this.setSize(300, 300);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
container.setBackground(Color.white);
container.setLayout(new BorderLayout());
container.add(pan, BorderLayout.CENTER);
bouton.addActionListener(new BoutonListener());
bouton.setEnabled(false);
bouton2.addActionListener(new Bouton2Listener());
JPanel south = new JPanel();
south.add(bouton);
south.add(bouton2);
container.add(south, BorderLayout.SOUTH);
Font police = new Font("Tahoma", Font.BOLD, 16);
label.setFont(police);
label.setForeground(Color.blue);
label.setHorizontalAlignment(JLabel.CENTER);
container.add(label, BorderLayout.NORTH);
this.setContentPane(container);
this.setVisible(true);
}
}
// Those are the subclasses
class BoutonListener implements ActionListener {
public void actionPerformed(ActionEvent arg0) {
bouton.setEnabled(false);
bouton2.setEnabled(true);
}
}
class Bouton2Listener implements ActionListener {
public void actionPerformed(ActionEvent e) {
bouton.setEnabled(true);
bouton2.setEnabled(false);
}
}
サブクラス*はスーパークラスの 'private'メンバにアクセスできません。 – cybersam
いいえ、そうではありません。私は彼らも公開しようとしました。 – Zerox029
*あなたの*サブクラス*と*スーパークラス*のコードを私たちのために投稿してください。 –