我希望在一个名为VehiclePanel的构造函数中创建一个Car实例,但我似乎无法弄清楚如何去做,所以我在这里。有人能帮忙解决这个问题吗?
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
}
}
答案 0 :(得分:0)
public VehiclePanel() {
Car car = new Car();
add(car);
}
请注意,由于Car在VehiclePanel中声明,因此它是私有的并不重要。