// // HotelFrame.java : // Environnement graphique pour les TP1 et TP2 de IFT6802 // Jean Vaucher ( janv. 2004) import java.lang.*; import java.util.*; import java.io.*; import java.net.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; public class HotelFrame extends JFrame implements ActionListener { int DELTA = 28; JPanel canvas ; Vector agents ; JList agentList ; JButton ok, quit ; JTextField coups = new JTextField(5) ; int LIM; HotelServer3 hotel; public HotelFrame( HotelServer3 hotel, int LIM ) { this.hotel = hotel; this.LIM = LIM; Border paneEdge = BorderFactory.createEmptyBorder(0,10,10,10); Border blackline = BorderFactory.createLineBorder(Color.black); Border raisedetched = BorderFactory.createEtchedBorder(EtchedBorder.RAISED); setTitle("Hotel - TP2 (1.2)"); JPanel base = new JPanel(); base.setBorder(new EmptyBorder(5,5,5,5)); base.setLayout(new BorderLayout(10,10)); getContentPane().add(base); canvas = new myCanvas( hotel, DELTA ); base.add(canvas, BorderLayout.CENTER); canvas.setBorder( blackline ); JPanel rPane = new JPanel(); base.add(rPane, BorderLayout.EAST); rPane.setLayout(new BorderLayout(10,10)); // rPane.add( new JLabel("Scores"), BorderLayout.NORTH); JPanel topRight = new JPanel(new GridLayout(3, 1)); topRight.add(new JLabel("Coups")); topRight.add( coups ); topRight.add(new JLabel("Scores")); rPane.add( topRight, BorderLayout.NORTH); agentList = new JList( hotel.score ); agentList.setBorder( raisedetched ); rPane.add( agentList, BorderLayout.CENTER); // JPanel pane = new JPanel(); JPanel p = new JPanel( new FlowLayout()); p.add(quit = new JButton("QUIT")); quit.addActionListener(this); rPane.add( p, BorderLayout.SOUTH); p = new JPanel( new FlowLayout()); p.add( new JLabel("Note: adresse multicast = " + hotel.multiPort) ); base.add(p, BorderLayout.SOUTH); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); pack(); setResizable(false); setVisible( true ); } public void actionPerformed(ActionEvent ae) { // --------------------------------------------- if (ae.getSource() == quit) { System.exit(0); } } } // --------- HotelWorld ------------ class myCanvas extends JPanel // implements ActionListener { HotelServer3 hotel; int delta; int LIM; Random rnd = new Random(); javax.swing.Timer timer; public myCanvas( HotelServer3 hotel, int dd) { this.hotel = hotel; LIM = hotel.LIM; delta = dd; setPreferredSize( new Dimension( delta*LIM+1, delta*LIM+1) ); } public void paintComponent(Graphics g) { super.paintComponent(g); Vector v ; synchronized (hotel.props) { v = (Vector) hotel.props.clone(); } for (Iterator it=v.iterator(); it.hasNext(); ) { Piece p = (Piece) it.next(); if (p instanceof Dirt) p.paint( this, g ); } for (Iterator it=v.iterator(); it.hasNext(); ) { Piece p = (Piece) it.next(); if (! (p instanceof Dirt)) p.paint( this, g ); } } }