/** @version 1.0 06-05-2008 @author Agustin J. Gonzalez */ import java.awt.*; import javax.swing.*; import javax.swing.border.*; /** A panel with two tanks and a control system. A simulation to practice with applets. */ public class PlantPanel extends JPanel { public PlantPanel() { setLayout(new BorderLayout()); menuPanel= new Box(BoxLayout.X_AXIS); menuPanel.setBorder(new EmptyBorder(5,3,1,3)); view= new PlantView(); view.setPreferredSize(new Dimension(900,400)); dt=0.05F; // 50 ms is the delta t of the simulation. TimePace timer = new TimePace(this); menuPanel.add(timer.getGUI()); menuPanel.add(Box.createRigidArea(new Dimension(10,0))); Tank tank1= new Tank(new Point(180,110), view, 1); menuPanel.add(tank1.getGUI()); menuPanel.add(Box.createRigidArea(new Dimension(10,0))); view.addEquipment(tank1); Tank tank2= new Tank(new Point(240,215), view, 2); menuPanel.add(tank2.getGUI()); menuPanel.add(Box.createRigidArea(new Dimension(10,0))); view.addEquipment(tank2); tank1.setReceiver(tank2); Controller control = new Controller(new Point(2,250), tank2); view.addEquipment(control); menuPanel.add(Box.createRigidArea(new Dimension(10,0))); menuPanel.add(control.getGUI()); add(menuPanel, BorderLayout.NORTH); add(view, BorderLayout.CENTER); timer.start(); } public void simulationTick(){ view.timeTick(dt); view.repaint(); } private JComponent menuPanel; private PlantView view; private float dt; }