更新时间:2023-02-05 23:37:43
一个主要问题:你的Squares JPanels首选大小只有20乘20,实际上可能是那个大小,因为它似乎被添加到FlowLayout使用容器中。接下来,您似乎正在绘制超出此组件边界的位置,因此可能永远不会看到图纸。考虑允许Squares对象更大,并确保仅在此组件的范围内绘制。
One major problem: Your Squares JPanels preferred size is only 20 by 20, and will likely actually be that size since it seems to be added to a FlowLayout-using container. Next you seem to be drawing at locations that are well beyond the bounds of this component, and so the drawings likely will never be seen. Consider allowing your Squares objects to be larger, and make sure to only draw within the bounds of this component.
请注意,代码没有意义,包括:
Note also there is code that doesn't make sense, including:
private int myID;
private JTextField row, column, instru draft saved // ???
package question2;ction1, instruction2, seatLabel, rowLabel; // ???
我猜它是
private int myID;
private JTextField row, column, instruction1, instruction2, seatLabel, rowLabel;
这不会为我们编译:
int rows = AircraftSeatReservation.getRows();
int seatsInRow = AircraftSeatReservation.getSeatsInRow(); // and shouldn't this take an int row parameter?
因为我们没有你的AircraftSeatReservation类(希望你真的没有静态方法) ()
since we don't have your AircraftSeatReservation class (hopefully you don't really have static methods in that class).
我们无法编译或运行您当前的代码。我们不希望看到您的整个程序,而是您应该将代码压缩到仍然编译的最小位,没有与您的问题无关的额外代码,但仍然可以证明您的问题。正如Andrew Thompson所建议的,为了获得更好的帮助,请创建并发布您的最小,完整和可验证的示例或简短,自包含,正确的例子。
And we can't compile or run your current code. We don't want to see your whole program, but rather you should condense your code into the smallest bit that still compiles, has no extra code that's not relevant to your problem, but still demonstrates your problem. So as Andrew Thompson recommends, for better help, please create and post your Minimal, Complete, and Verifiable example or Short, Self Contained, Correct Example.
我会尽可能地尝试OOP-ify你的问题,让你分而治之。这可能涉及:
I would try to OOP-ify your problem as much as possible, to allow you to divide and conquer. This could involve:
SeatClass
枚举,一个可能有两个元素, FIRST和COACH。 getBackground(...)
,这样它的颜色将取决于座位是保留还是没有。SeatClass
enum, one with possibly two elements, FIRST and COACH.getBackground(...)
so that it's color will depend on whether the seat is reserved or not.