·

Engenharia de Software ·

Banco de Dados

Send your question to AI and receive an answer instantly

Ask Question

Preview text

Parte III JAVA SWING Profs Edrian da Silva Joice Wolfrann Willian Bogler Hierarquia javaxswing Class JMenu javalangObject javaawtComponent javaawtContainer javaxswingJComponent javaxswingAbstractButton javaxswingJMenuItem javaxswingJMenu 19062024 Menu JMenuBar que representa a barra de menu localizada no topo da aplicação JMenu responsável pelos menus inseridos na barra de menu como Arquivo Editar Exibir etc JMenuItem os itens internos de um menu como Novo Abrir Salvar etc Todas essas classes pertencem ao pacote javaxswing 19062024 Menu Servem para centralizar a chamada das funcionalidade do sistema Normalmente estão localizados em lugar destacado Para a criação de um menu não utilizamos apenas um componente 19062024 Prática 01 public ExemploMenu setDefaultCloseOperationJFrameEXITONCLOSE setBounds100 100 450 300 JMenuBar jMenuBar new JMenuBar criação dos menus JMenu jMenuArquivo new JMenuArquivo JMenu jMenuEditar new JMenuEditar JMenu jMenuExibir new JMenuExibir JMenu jMenuConf new JMenuConfigurações JMenu jMenuHelp new JMenuHelp criação dos itens do menu arquivo JMenuItem jMenuItemNovo new JMenuItemNovo JMenuItem jMenuItemAbrir new JMenuItemAbrir JMenuItem jMenuItemSalvar new JMenuItemSalvar JMenuItem jMenuItemSalvarComo new JMenuItemSalvar Como JMenuItem jMenuItemSair new JMenuItemSair 19062024 Prática 01 add menusa barra de menu jMenuBaraddjMenuArquivo jMenuBaraddjMenuEditar jMenuBaraddjMenuExibir jMenuBaraddjMenuConf jMenuBaraddjMenuHelp add itens de menu ao menu arquivo jMenuArquivoaddjMenuItemNovo jMenuArquivoaddSeparator separador jMenuArquivoaddjMenuItemAbrir jMenuArquivoaddjMenuItemSalvar jMenuArquivoaddjMenuItemSalvarComo jMenuArquivoaddSeparator jMenuArquivoaddjMenuItemSair add no app supersetJMenuBarjMenuBar contentPane new JPanelnull contentPanesetBordernew EmptyBorder5 5 5 5 setContentPanecontentPane 19062024 Prática 01 19062024 jMenuItemSairaddActionListenernew ActionListener public void actionPerformedActionEvent e JOptionPaneshowMessageDialognull Você saiu dispose Prática 01 JRadioButtonMenuItem jrbmnExemplo011 new JRadioButtonMenuItemExemplo jrbMn01 jMenuEditaraddjrbmnExemplo011 JRadioButtonMenuItem jrbmnExemplo02 new JRadioButtonMenuItemExemplo jrbMn02 jMenuEditaraddjrbmnExemplo02 jMenuBaraddjMenuExibir JCheckBoxMenuItem jcheckExemplo01 new JCheckBoxMenuItemItem 1 jMenuExibiraddjcheckExemplo01 JCheckBoxMenuItem jcheckExemplo2 new JCheckBoxMenuItemItem 2 jMenuExibiraddjcheckExemplo2 19062024 Prática 01 DesktopPane É um recipiente utilizado para criar uma interface de documentos múltiplos ou uma área de trabalho virtual Você cria objetos JInternalFrame e adicionálos ao JDesktopPane A classe JDesktopPane estende o JLayeredPane para gerenciar os quadros internos potencialmente sobrepostos Ele também mantém uma referência a uma instância de DesktopManager que é definido pela classe UI para o Look and Feel da aplicação JInternalFrame Um objeto leve que fornece muitas das características de uma estrutura nativa incluindo arrastar fechar mostrar um ícone redimensionar exibir títulos e também possui suporte para uma barra de menus 19062024 JInternalFrame Select a wizard Create an empty JInternalFrame Next Absolute layout Layout with absolute positioning components Para fechar o JInternalFrame 19062024 Abrindo a janela interna no Menu Principal jMenuItemNovoaddActionListenernew ActionListener public void actionPerformedActionEvent e ExemploCadastroInternal jcadastro new ExemploCadastroInternal contentPaneaddjcadastro jcadastrosetVisibletrue 19062024 Prática 02 Cadastro de Pessoa em Array public class CadastroPessoa extends JFrame private JTextField txtNome private JTextField txtIdade private DefaultTableModel tableModel public static void mainString args EventQueueinvokeLaternew Runnable public void run try CadastroPessoa frame new CadastroPessoa framesetVisibletrue catch Exception e eprintStackTrace 19062024 Prática 02 Cadastro de Pessoa em Array public CadastroPessoa setTitleCadastro de Pessoas setDefaultCloseOperationJFrameEXITONCLOSE setBounds100 100 500 300 getContentPanesetLayoutnull JLabel lblNewLabel new JLabelNome lblNewLabelsetBounds33 35 46 14 getContentPaneaddlblNewLabel txtNome new JTextField txtNomesetBounds80 32 86 20 getContentPaneaddtxtNome txtNomesetColumns10 JLabel lblNewLabel1 new JLabelIdade lblNewLabel1setBounds33 70 46 14 getContentPaneaddlblNewLabel1 txtIdade new JTextField txtIdadesetBounds80 67 36 20 getContentPaneaddtxtIdade txtIdadesetColumns10 19062024 Prática 02 Cadastro de Pessoa em Array JButton btnCadastro new JButtonCadastrar btnCadastroaddActionListenernew ActionListener public void actionPerformedActionEvent e cadastrarPessoa btnCadastrosetBounds80 111 118 23 getContentPaneaddbtnCadastro table JTable table new JTable tableModel new DefaultTableModel tableModeladdColumnNome tableModeladdColumnIdade tablesetModeltableModel JScrollPane scrollPane new JScrollPanetable scrollPanesetBounds220 30 250 200 getContentPaneaddscrollPane 19062024 Prática 02 Cadastro de Pessoa em Array private void cadastrarPessoa String nome txtNomegetText String idade txtIdadegetText String rowData nome idade add tabela tableModeladdRowrowData txtNomesetText cls txtIdadesetText 19062024 Nome Idade Cadastrar Nome Idade Joice 20 Willian 18 Edrian 17 19062024 Para construir o gráfico usaremos o jar JFreeChart disponivel no link httpsrepo1mavenorgmaven2orgjfreejfreechart153 19062024 Exemplo de DashBoard 19062024 package modelentities public class Covid private int totalInfectados private int casosAtivos private int recuperados private int obitos public Covidint totalInfectados int casosAtivos int recuperados int obitos thistotalInfectados totalInfectados thiscasosAtivos casosAtivos thisrecuperados recuperados thisobitos obitos getters and setters 19062024 public class JFrameCovid extends JFrame private JLabel totalLabel private JLabel ativalabel private JLabel recuperadosLabel private JLabel mortosLabel private Covid covid public JFrameCovidCovid covid thiscovid covid setDefaultCloseOperationJFrameEXITONCLOSE setTitleCOVID19 Dashboard setSize1000 800 aqui tamanho que vc desejar setLayoutnew BorderLayout layout como border Panel para os dados JPanel dataPanel new JPanelnew GridLayout4 2 10 10 vamos colocar em um gridLayout totalLabel new JLabelStringvalueOfcovidgetTotalInfectados ativalabel new JLabelStringvalueOfcovidgetCasosAtivos recuperadosLabel new JLabelStringvalueOfcovidgetRecuperados mortosLabel new JLabelStringvalueOfcovidgetObitos Estilizando os títulos Font titleFont new FontFontSANSSERIF FontBOLD 16 JLabel totalTitleLabel new JLabelTotal de Infectados totalTitleLabelsetFonttitleFont JLabel activeTitleLabel new JLabelCasos Ativos activeTitleLabelsetFonttitleFont JLabel recupdTitleLabel new JLabelRecuperados recupdTitleLabelsetFonttitleFont JLabel mortosTitleLabel new JLabelÓbitos mortosTitleLabelsetFonttitleFont 19062024 add os componentes dataPaneladdtotalTitleLabel dataPaneladdtotalLabel dataPaneladdactiveTitleLabel dataPaneladdativalabel dataPaneladdrecupdTitleLabel dataPaneladdrecuperadosLabel dataPaneladdmortosTitleLabel dataPaneladdmortosLabel dados vão ficar no lado esqyerdo adddataPanel BorderLayoutWEST cria o gráfico com a biblioteca JFreeChart link disponivél em httpsrepo1mavenorgmaven2orgjfreejfreechart153 JFreeChart barChart createBarChart ChartPanel chartPanel new ChartPanelbarChart chartPanelsetPreferredSizenew javaawtDimension500 400 Tamanho do gráfico addchartPanel BorderLayoutCENTER Centralizando a janela setLocationRelativeTonull setVisibletrue private JFreeChart createBarChart DefaultCategoryDataset dataset new DefaultCategoryDataset datasetsetValuecovidgetTotalInfectados Dados Total de Infectados datasetsetValuecovidgetCasosAtivos Dados Casos Ativos datasetsetValuecovidgetRecuperados Dados Recuperados datasetsetValuecovidgetObitos Dados Óbitos JFreeChart barChart ChartFactorycreateBarChartDados COVID19 Categoria Quantidade dataset PlotOrientationVERTICAL true true false return barChart public static void mainString args Covid covid new Covid1000 500 400 100 dados fecticios vc pode colocar os dados do seu banco EventQueueinvokeLater try JFrameCovid frame new JFrameCovidcovid framesetVisibletrue catch Exception e eprintStackTrace COVID19 Dashboard Total de Infectados 1000 Casos Ativos 500 Recuperados 400 Óbitos 100 Dados COVID19 Quantidade Total de Infectados Casos Ativos Recuperados Óbitos 19062024