-2
私はVehiclePanelというコンストラクタでCarのインスタンスを作成しようとしていますが、どうやってそれを行うのか分からないようです。誰でもこれを手伝うことができますか?Javaのパブリッククラスでプライベートクラスのインスタンスを作る
public class VehiclePanel extends JPanel {
//variables here
public VehiclePanel() {
// somehow need to create a new instance of Car class and add it to the VehiclePanel
}
private class Car extends JPanel {
// Car code here, not important
}
}
なぜ単に 'Car car = new Car();' - そしてあなたの車の変数を使用していませんか?問題がどのような問題か分かりませんので、あなたの質問は私を混乱させます。 –
'this.add(new Car());' – 4castle
'Car'が' VehiclePanel'の状態にアクセスする必要がない場合は、 '' static''ネストされたクラス(https://docs.oracle)にすることを検討してください。 com/javase/tutorial/java/javaOO/nested.html)。 – 4castle