Skip to content
Snippets Groups Projects
Select Git revision
  • dfb5090f2e31e4e33b9032ed9666bcb693afea27
  • master default protected
2 results

game.py

Blame
  • ApplicationMain.java 3.65 KiB
    package GUI;
    
    import client.Client;
    
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.rmi.RemoteException;
    import java.util.ArrayList;
    
    public class ApplicationMain extends JPanel {
        private Client client;
        private ChatScreen chatScreen;
        private PaintGUI paintGUI;
        private JFrame frame;
    
        public ChatScreen getChatScreen() { return chatScreen; }
    
        public PaintGUI getPaintGUI() { return paintGUI; }
    
        public JFrame getFrame() {
            return frame;
        }
    
        public ApplicationMain(Client client) {
            this.client = client;
            this.chatScreen = new ChatScreen(client);
            this.paintGUI = new PaintGUI(client);
        }
    
        public void createAndShowGUI()
        {
            frame = new JFrame("Application Main");
            JFrame.setDefaultLookAndFeelDecorated(true);
            Container content = frame.getContentPane();
            content.setLayout(new BorderLayout());
            content.add(paintGUI.getGlobal(), BorderLayout.WEST);
            content.add(chatScreen.panel2, BorderLayout.EAST);
            chatScreen.setUserName(client.getUserName());
    
    
            try {
                // Update canvas
                ArrayList<Shape> shapeList = client.getDrawingController().getShapeList();
                ArrayList<Color> colorList = client.getDrawingController().getColorList();
                ArrayList<Integer> strokeSizeList = client.getDrawingController().getStrokeSizeList();
    
                ArrayList<String> textList = client.getDrawingController().getTextList();
                ArrayList<Font> fontList = client.getDrawingController().getFontList();
                ArrayList<Point> textStartPointList = client.getDrawingController().getTextStartPointList();
    
                Graphics2D g2 = paintGUI.getDrawingArea().getG2();
    //            for (int i = 0; i < textList.size(); i++) {
    //                g2.setFont(fontList.get(i));
    //                g2.drawString(textList.get(i), textStartPointList.get(i).x, textStartPointList.get(i).y);
    //                client.getApplicationMain().getPaintGUI().getDrawingArea().repaint();
    //            }
    
                for (int i = 0; i < shapeList.size(); i++) {
                    g2.setStroke(new BasicStroke(strokeSizeList.get(i)));
                    g2.setColor(colorList.get(i));
                    g2.draw(shapeList.get(i));
                    paintGUI.getDrawingArea().repaint();
                }
            }
            catch (RemoteException e) {
                e.printStackTrace();
            }
    
    
            SwingUtilities.getRootPane(chatScreen.getSendButton()).setDefaultButton(chatScreen.getSendButton());
            frame.addWindowListener(new WindowAdapter()
            {
                @Override
                public void windowClosing(WindowEvent arg0)
                {
                    int reply = JOptionPane.showConfirmDialog(null,
                            "Are you sure you want to quit the session?",
                            "Shut down session", JOptionPane.YES_NO_OPTION);
    
                    if( reply == JOptionPane.YES_OPTION )
                    {
                        try
                        {
                            client.getClientController().quit(client.getUserName());
                        }
                        catch (RemoteException e)
                        {
                            StartScreen.showErrorMessage("Error in quitting the server");
                            //e.printStackTrace();
                        }
    
                        System.exit(0);
                    }
                }
            });
    
            frame.setSize(1200, 700);
            frame.setLocationRelativeTo( null );
            frame.setResizable(false);
            frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
            frame.pack();
            frame.setVisible(true);
        }
    }