Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Java的公共类中生成私有类的实例_Java_User Interface - Fatal编程技术网

在Java的公共类中生成私有类的实例

在Java的公共类中生成私有类的实例,java,user-interface,Java,User Interface,我想在一个名为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 C

我想在一个名为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
}
}
请注意,因为汽车是在VehiclePanel内声明的,所以它是私人的这一事实并不重要

为什么不干脆把车=新车;-然后用你的汽车变量?你的问题把我弄糊涂了,因为我不知道你遇到了什么问题;如果汽车不需要进入车辆面板的状态,就考虑把它做成一个。
public VehiclePanel() {
  Car car = new Car();
  add(car);
}