public class n00767255 {
public static void main(String[] args) {
CarFrame frame = new CarFrame();
frame.setSize(600,480);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
while(true)
{
frame.repaint();
}
}
}
class CarFrame extends JFrame {
CarFrame() {
setLayout(new GridLayout(3,1));
final CarPanel car1 = new CarPanel();
car1.initCar(10,50,2,150,70,40);
add(car1);
final CarPanel car2 = new CarPanel();
car2.initCar(10,50,2,150,70,40);
add(car2);
JButton startCar1 = new JButton("Start Car 1");
JPanel panel = new JPanel();
panel.setSize(600,40);
panel.add(startCar1);
add(panel);
startCar1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(!car1.getMovingF())
{
car1.modifyMovingF();
}
}
});
}
}
What I want this to do is to create the two CarPanels with the basic car shape and for those both to by 600X200 and be spaced properly so the full objects can be seen. Under that I want to paste the panel with a bunch of different buttons that do different things. Here my problem is that the cars never have enough space to be seen entirely, and using different layout managers hasn't helped.
EDIT
After numerous changed this code is not working at all the way I would expect. At this point the first car is the only one shown and the start car button is at the top of the frame.