Advertisement
l_evandro

Principal

Oct 23rd, 2019
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.72 KB | None | 0 0
  1. package dev.evandro.swing;
  2.  
  3. import javax.swing.JFrame;
  4. import javax.swing.JMenu;
  5. import javax.swing.JMenuBar;
  6. import javax.swing.JMenuItem;
  7.  
  8. public class Principal {
  9.     private JMenu jmenuPrincipal;
  10.     private JMenuBar jmenuBar;
  11.     private JMenuItem jMenuItemCadastrar;
  12.     private JMenuItem jMenuItemConsultar;
  13.     private JMenuItem jMenuItemLogin;
  14.    
  15.     public JMenuItem getjMenuItemCadastrar() {
  16.         return jMenuItemCadastrar;
  17.     }
  18.  
  19.     public void setjMenuItemCadastrar(JMenuItem jMenuItemCadastrar) {
  20.         this.jMenuItemCadastrar = jMenuItemCadastrar;
  21.     }
  22.  
  23.     public JMenuItem getjMenuItemConsultar() {
  24.         return jMenuItemConsultar;
  25.     }
  26.  
  27.     public void setjMenuItemConsultar(JMenuItem jMenuItemConsultar) {
  28.         this.jMenuItemConsultar = jMenuItemConsultar;
  29.     }
  30.  
  31.     public Principal() {
  32.         JFrame frame = new JFrame();
  33.        
  34.         jmenuPrincipal = new JMenu("Principal");
  35.         jMenuItemLogin = new JMenuItem("Login");
  36.        
  37.         // Aqui eu passo a referencia de tela principal para o Login
  38.         // Assim consigo manipular os JMenuItems ou qualquer coisa na tela principal
  39.         jMenuItemLogin.addActionListener(e ->  new Login(this));
  40.        
  41.        
  42.         jMenuItemCadastrar = new JMenuItem("Cadastrar");
  43.         jMenuItemCadastrar.setEnabled(false);
  44.        
  45.         jMenuItemConsultar = new JMenuItem("Consultar");
  46.         jMenuItemConsultar.setEnabled(false);
  47.        
  48.        
  49.         jmenuPrincipal.add(jMenuItemLogin);
  50.         jmenuPrincipal.add(jMenuItemCadastrar);
  51.         jmenuPrincipal.add(jMenuItemConsultar);
  52.        
  53.         jmenuBar = new JMenuBar();
  54.         jmenuBar.add(jmenuPrincipal);
  55.        
  56.         frame.setJMenuBar(jmenuBar);
  57.        
  58.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  59.         frame.setSize(300, 300);
  60.         frame.setVisible(true);
  61.     }
  62.  
  63.     public static void main(String[] args) {
  64.         Principal p = new Principal();
  65.     }
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement