Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package dev.evandro.swing;
- import javax.swing.JFrame;
- import javax.swing.JMenu;
- import javax.swing.JMenuBar;
- import javax.swing.JMenuItem;
- public class Principal {
- private JMenu jmenuPrincipal;
- private JMenuBar jmenuBar;
- private JMenuItem jMenuItemCadastrar;
- private JMenuItem jMenuItemConsultar;
- private JMenuItem jMenuItemLogin;
- public JMenuItem getjMenuItemCadastrar() {
- return jMenuItemCadastrar;
- }
- public void setjMenuItemCadastrar(JMenuItem jMenuItemCadastrar) {
- this.jMenuItemCadastrar = jMenuItemCadastrar;
- }
- public JMenuItem getjMenuItemConsultar() {
- return jMenuItemConsultar;
- }
- public void setjMenuItemConsultar(JMenuItem jMenuItemConsultar) {
- this.jMenuItemConsultar = jMenuItemConsultar;
- }
- public Principal() {
- JFrame frame = new JFrame();
- jmenuPrincipal = new JMenu("Principal");
- jMenuItemLogin = new JMenuItem("Login");
- // Aqui eu passo a referencia de tela principal para o Login
- // Assim consigo manipular os JMenuItems ou qualquer coisa na tela principal
- jMenuItemLogin.addActionListener(e -> new Login(this));
- jMenuItemCadastrar = new JMenuItem("Cadastrar");
- jMenuItemCadastrar.setEnabled(false);
- jMenuItemConsultar = new JMenuItem("Consultar");
- jMenuItemConsultar.setEnabled(false);
- jmenuPrincipal.add(jMenuItemLogin);
- jmenuPrincipal.add(jMenuItemCadastrar);
- jmenuPrincipal.add(jMenuItemConsultar);
- jmenuBar = new JMenuBar();
- jmenuBar.add(jmenuPrincipal);
- frame.setJMenuBar(jmenuBar);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setSize(300, 300);
- frame.setVisible(true);
- }
- public static void main(String[] args) {
- Principal p = new Principal();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement