Advertisement
Guest User

Untitled

a guest
May 20th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 14.22 KB | None | 0 0
  1. package br.com.jogocartas.apresentacao;
  2.  
  3. import java.awt.Color;
  4.  
  5. import javax.swing.*;
  6.  
  7. import org.json.JSONException;
  8. import org.json.JSONObject;
  9.  
  10. import br.com.jogocartas.comunicacao.Transmissao;
  11. import br.com.jogocartas.modelo.PartidaLista;
  12. import br.com.jogocartas.modelo.Usuario;
  13.  
  14. public class JDesktopPanelPrincipal extends javax.swing.JFrame {
  15.    
  16.     private static final long serialVersionUID = 1L;
  17.    
  18.     private Usuario usuario;
  19.                        
  20.     private JButton jButtonEntrarPartida;
  21.     private JDesktopPane jDektopPanelPrincipal;
  22.     private JLabel jLabel1;
  23.     private JLabel jLabelCoinValue;
  24.     private JLabel jLabelEmail;
  25.     private JList<String> jListPartidas;
  26.     private JMenuBar jMenu;
  27.     private JMenuItem jMenuCriarPartida;
  28.     private JMenu jMenuPrincipal;
  29.     private JMenuItem jMenuSairJogo;
  30.     private JScrollPane jScrollPane1;
  31.     private JScrollPane jScrollPane2;
  32.     private JTree jTree1;
  33.     private javax.swing.JPanel jPanelCoinIcon;
  34.    
  35.       /**
  36.      * Creates new form FormPrincipal
  37.      */
  38.     public JDesktopPanelPrincipal(Usuario usuario) {
  39.         this.usuario = usuario;
  40.         initComponents();
  41.     }
  42.    
  43.     public JDesktopPanelPrincipal(){
  44.     }
  45.  
  46.     /**
  47.      * This method is called from within the constructor to initialize the form.
  48.      * WARNING: Do NOT modify this code. The content of this method is always
  49.      * regenerated by the Form Editor.
  50.      */
  51.     @SuppressWarnings("unchecked")
  52.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  53.     private void initComponents() {
  54.         jScrollPane2 = new javax.swing.JScrollPane();
  55.         jTree1 = new javax.swing.JTree();
  56.         jDektopPanelPrincipal = new javax.swing.JDesktopPane();
  57.         jLabelEmail = new javax.swing.JLabel();
  58.         jScrollPane1 = new javax.swing.JScrollPane();
  59.         jListPartidas = new javax.swing.JList<>();
  60.         jButtonEntrarPartida = new javax.swing.JButton();
  61.         jLabel1 = new javax.swing.JLabel();
  62.         jLabelCoinValue = new javax.swing.JLabel();
  63.         jMenu = new javax.swing.JMenuBar();
  64.         jMenuPrincipal = new javax.swing.JMenu();
  65.         jMenuCriarPartida = new javax.swing.JMenuItem();
  66.         jMenuSairJogo = new javax.swing.JMenuItem();
  67.         jPanelCoinIcon = new javax.swing.JPanel();
  68.        
  69.         jLabelCoinValue.setText(Integer.toString(this.usuario.getQuantidadeMoedasDisponivel()));
  70.  
  71.         jScrollPane2.setViewportView(jTree1);
  72.  
  73.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  74.  
  75.         jDektopPanelPrincipal.setBackground(new java.awt.Color(65, 105, 170));
  76.  
  77.         jLabelEmail.setFont(new java.awt.Font("Trebuchet MS", 0, 24)); // NOI18N
  78.         jLabelEmail.setForeground(new java.awt.Color(255, 255, 255));
  79.  
  80.         jListPartidas.setModel(new javax.swing.AbstractListModel<String>() {
  81.             private static final long serialVersionUID = 1L;
  82.            
  83.             String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
  84.             public int getSize() { return strings.length; }
  85.             public String getElementAt(int i) { return strings[i]; }
  86.         });
  87.         jScrollPane1.setViewportView(jListPartidas);
  88.  
  89.         jButtonEntrarPartida.setBackground(new java.awt.Color(255, 102, 102));
  90.         jButtonEntrarPartida.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
  91.         jButtonEntrarPartida.setForeground(new java.awt.Color(255, 255, 255));
  92.         jButtonEntrarPartida.setText("ENTRAR NA PARTIDA");
  93.  
  94.         jLabelCoinValue.setFont(new java.awt.Font("Tahoma", 3, 18)); // NOI18N
  95.         jLabelCoinValue.setForeground(new java.awt.Color(255, 255, 0));
  96.        
  97.         jPanelCoinIcon.setBackground(new java.awt.Color(65, 105, 170));
  98.         jPanelCoinIcon.setBackground(Color.BLACK); // só para mostrar onde esta o painel depois tirar quando colocar a img de fundo
  99.        
  100.         javax.swing.GroupLayout jPanelCoinIconLayout = new javax.swing.GroupLayout(jPanelCoinIcon);
  101.         jPanelCoinIcon.setLayout(jPanelCoinIconLayout);
  102.         jPanelCoinIconLayout.setHorizontalGroup(
  103.             jPanelCoinIconLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  104.             .addGap(0, 100, Short.MAX_VALUE)
  105.         );
  106.         jPanelCoinIconLayout.setVerticalGroup(
  107.             jPanelCoinIconLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  108.             .addGap(0, 100, Short.MAX_VALUE)
  109.         );
  110.  
  111.         jDektopPanelPrincipal.setLayer(jLabelEmail, javax.swing.JLayeredPane.DEFAULT_LAYER);
  112.         jDektopPanelPrincipal.setLayer(jScrollPane1, javax.swing.JLayeredPane.DEFAULT_LAYER);
  113.         jDektopPanelPrincipal.setLayer(jButtonEntrarPartida, javax.swing.JLayeredPane.DEFAULT_LAYER);
  114.         jDektopPanelPrincipal.setLayer(jLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);
  115.         jDektopPanelPrincipal.setLayer(jLabelCoinValue, javax.swing.JLayeredPane.DEFAULT_LAYER);
  116.         jDektopPanelPrincipal.setLayer(jPanelCoinIcon, javax.swing.JLayeredPane.DEFAULT_LAYER);
  117.  
  118.         javax.swing.GroupLayout jDektopPanelPrincipalLayout = new javax.swing.GroupLayout(jDektopPanelPrincipal);
  119.         jDektopPanelPrincipal.setLayout(jDektopPanelPrincipalLayout);
  120.         jDektopPanelPrincipalLayout.setHorizontalGroup(
  121.             jDektopPanelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  122.             .addGroup(jDektopPanelPrincipalLayout.createSequentialGroup()
  123.                 .addContainerGap()
  124.                 .addGroup(jDektopPanelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  125.                     .addComponent(jButtonEntrarPartida, javax.swing.GroupLayout.PREFERRED_SIZE, 249, javax.swing.GroupLayout.PREFERRED_SIZE)
  126.                     .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 552, javax.swing.GroupLayout.PREFERRED_SIZE))
  127.                 .addGroup(jDektopPanelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  128.                     .addGroup(jDektopPanelPrincipalLayout.createSequentialGroup()
  129.                         .addGroup(jDektopPanelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  130.                             .addGroup(jDektopPanelPrincipalLayout.createSequentialGroup()
  131.                                 .addGap(31, 31, 31)
  132.                                 .addComponent(jLabelEmail))
  133.                             .addGroup(jDektopPanelPrincipalLayout.createSequentialGroup()
  134.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  135.                                 .addComponent(jPanelCoinIcon, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  136.                                 .addGap(31, 31, 31)
  137.                                 .addComponent(jLabel1)))
  138.                         .addGap(92, 92, 92))
  139.                     .addGroup(jDektopPanelPrincipalLayout.createSequentialGroup()
  140.                         .addGap(369, 369, 369)
  141.                         .addComponent(jLabelCoinValue, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
  142.                         .addContainerGap())))
  143.         );
  144.         jDektopPanelPrincipalLayout.setVerticalGroup(
  145.             jDektopPanelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  146.             .addGroup(jDektopPanelPrincipalLayout.createSequentialGroup()
  147.                 .addGroup(jDektopPanelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  148.                     .addGroup(jDektopPanelPrincipalLayout.createSequentialGroup()
  149.                         .addGroup(jDektopPanelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  150.                             .addGroup(jDektopPanelPrincipalLayout.createSequentialGroup()
  151.                                 .addGap(33, 33, 33)
  152.                                 .addGroup(jDektopPanelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  153.                                     .addComponent(jLabel1)
  154.                                     .addComponent(jLabelCoinValue, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)))
  155.                             .addGroup(jDektopPanelPrincipalLayout.createSequentialGroup()
  156.                                 .addContainerGap()
  157.                                 .addComponent(jPanelCoinIcon, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
  158.                         .addGap(103, 103, 103)
  159.                         .addComponent(jLabelEmail))
  160.                     .addGroup(jDektopPanelPrincipalLayout.createSequentialGroup()
  161.                         .addGap(54, 54, 54)
  162.                         .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 447, javax.swing.GroupLayout.PREFERRED_SIZE)))
  163.                 .addGap(28, 28, 28)
  164.                 .addComponent(jButtonEntrarPartida, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
  165.                 .addContainerGap(38, Short.MAX_VALUE))
  166.         );
  167.  
  168.         jMenu.setBackground(new java.awt.Color(153, 153, 153));
  169.         jMenu.setToolTipText("Jogo de Cartas");
  170.  
  171.         ImageIcon image = new ImageIcon("file:///C:/Users/andrev/Documents/projeto-integrado-c/Cliente/imagens/menu_icon.png");
  172.         jMenuPrincipal.setIcon(image);
  173.         //jMenuPrincipal.setIcon(new javax.swing.ImageIcon(getClass().getResource("/projeto-integrado-c/Cliente/imagens/menu_icon.png"))); // NOI18N
  174.         jMenuPrincipal.setText("Menu");
  175.  
  176.         //jMenuCriarPartida.setIcon(new javax.swing.ImageIcon(getClass().getResource("/projeto-integrado-c/Cliente/imagens/add_icon.png"))); // NOI18N
  177.         jMenuCriarPartida.setText("Criar nova Partida");
  178.         jMenuCriarPartida.addActionListener(new java.awt.event.ActionListener() {
  179.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  180.                 jMenuCriarPartidaActionPerformed(evt);
  181.             }
  182.         });
  183.         jMenuPrincipal.add(jMenuCriarPartida);
  184.  
  185.         //jMenuSairJogo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/projeto-integrado-c/Cliente/imagens/exit.png"))); // NOI18N
  186.         jMenuSairJogo.setText("Sair do Jogo");
  187.         jMenuSairJogo.addActionListener(new java.awt.event.ActionListener() {
  188.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  189.                 jMenuSairJogoActionPerformed(evt);
  190.             }
  191.         });
  192.         jMenuPrincipal.add(jMenuSairJogo);
  193.  
  194.         jMenu.add(jMenuPrincipal);
  195.  
  196.         setJMenuBar(jMenu);
  197.  
  198.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  199.         getContentPane().setLayout(layout);
  200.         layout.setHorizontalGroup(
  201.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  202.             .addComponent(jDektopPanelPrincipal)
  203.         );
  204.         layout.setVerticalGroup(
  205.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  206.             .addComponent(jDektopPanelPrincipal)
  207.         );
  208.        
  209.        
  210.         // ESTOU IMPLEMENTANDO AINDA ESSA PARTE PARA PEGAR TODAS AS PARTIDAS CADASTRADAS
  211.         /*try {
  212.             JSONObject jsonObject = new JSONObject();
  213.             jsonObject.put("protocolo", "PART");
  214.             Transmissao transmitor = new Transmissao(jsonObject);
  215.             Object obj = transmitor.enviaSolicitacao();
  216.         } catch (JSONException e) {
  217.             // TODO Auto-generated catch block
  218.             e.printStackTrace();
  219.         }*/
  220.  
  221.         pack();
  222.     }                    
  223.  
  224.     /**
  225.      * Esse botão eh responsável por abrir a tela para cadastrar uma nova partida.
  226.      *
  227.      *
  228.      */
  229.     private void jMenuCriarPartidaActionPerformed(java.awt.event.ActionEvent evt) {                                                  
  230.         JNovaPartidaFrame jNonaPartidaFrame = new JNovaPartidaFrame(this.usuario);
  231.         jDektopPanelPrincipal.add(jNonaPartidaFrame);
  232.         jNonaPartidaFrame.setVisible(true);
  233.     }                                                
  234.  
  235.     private void jMenuSairJogoActionPerformed(java.awt.event.ActionEvent evt) {                                              
  236.         JLoginFrame jLoginFame = new JLoginFrame();
  237.         dispose();
  238.         jLoginFame.setLocationRelativeTo(null);
  239.         jLoginFame.setVisible(true);
  240.     }                                            
  241.  
  242.     /**
  243.      * @param args the command line arguments
  244.      */
  245.     public static void main(String args[]) {
  246.         /* Set the Nimbus look and feel */
  247.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  248.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  249.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  250.          */
  251.         try {
  252.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  253.                 if ("Nimbus".equals(info.getName())) {
  254.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  255.                     break;
  256.                 }
  257.             }
  258.         } catch (ClassNotFoundException ex) {
  259.             java.util.logging.Logger.getLogger(JDesktopPanelPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  260.         } catch (InstantiationException ex) {
  261.             java.util.logging.Logger.getLogger(JDesktopPanelPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  262.         } catch (IllegalAccessException ex) {
  263.             java.util.logging.Logger.getLogger(JDesktopPanelPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  264.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  265.             java.util.logging.Logger.getLogger(JDesktopPanelPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  266.         }
  267.         //</editor-fold>
  268.         //</editor-fold>
  269.  
  270.         /* Create and display the form */
  271.         java.awt.EventQueue.invokeLater(new Runnable() {
  272.             public void run() {
  273.                 new JDesktopPanelPrincipal().setVisible(true);
  274.             }
  275.         });
  276.     }
  277. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement