Baixe o app para aproveitar ainda mais
Esta é uma pré-visualização de arquivo. Entre para ver o arquivo original
package br.unip.sicc.trabalho.view; import br.unip.sicc.trabalho.app.Aplicativo; import br.unip.sicc.trabalho.dao.DaoException; import br.unip.sicc.trabalho.model.GerenciadorUf; import br.unip.sicc.trabalho.model.Uf; import java.awt.BorderLayout; import java.awt.FlowLayout; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.text.ParseException; import java.util.Date; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JSpinner; import javax.swing.JTextField; import javax.swing.SpinnerModel; import javax.swing.SpinnerNumberModel; public class PainelCadastroUf extends JPanel { private JLabel lblId; private JTextField txtId; private JLabel lblNomeOficial; private JTextField txtNomeOficial; private JLabel lblPopulacao; private JSpinner spiQtdeItens; private JButton butOk; private JButton butCancelar; private Uf uf; public PainelCadastroUf() { BorderLayout layout = new BorderLayout(); this.setLayout(layout); this.add(criaPainelDeCadastro(), BorderLayout.CENTER); this.add(criaPainelDeBotoes(), BorderLayout.SOUTH); } private JPanel criaPainelDeCadastro() { JPanel painel = new JPanel(); GridLayout layout = new GridLayout (7,2,5,5); painel.setLayout(layout); lblId = new JLabel ("Id:"); txtId = new JTextField(); txtId.setEditable(false); lblNomeOficial = new JLabel("NomeOficial:"); txtNomeOficial = new JTextField(); lblPopulacao = new JLabel("Populacao:"); SpinnerModel model = new SpinnerNumberModel(0, 0, 100, 1); spiPopulacao = new JSpinner(model); painel.add(lblId); painel.add(txtId); painel.add(lblNomeOficial); painel.add(txtNomeOficial); painel.add(lblPopulacao); painel.add(spiPopulacao); return painel; } private JPanel criaPainelDeBotoes() { JPanel painel = new JPanel (new FlowLayout (FlowLayout.RIGHT, 10, 10)); butCancelar = new JButton ("Cancelar"); butCancelar.setMnemonic(KeyEvent.VK_C); butCancelar.addActionListener (new ActionListener() { public void actionPerformed(ActionEvent e) { Aplicativo.getInstance().setUfNaTelaDeCadastro(uf); } }); butOk = new JButton("Ok"); butOk.setMnemonic(KeyEvent.VK_O); butOk.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Uf uf = getUfDaTela(); try { GerenciadorUf.getInstance().salvar(uf); Aplicativo.getInstance().atualizaTabela(); } catch (DaoException ex) { JOptionPane.showMessageDialog( null, "Não foi possível salvar!", "Atenção", JOptionPane.ERROR_MESSAGE); } } }); painel.add(butCancelar); painel.add(butOk); return painel; } public Uf getUfDaTela() { int idInt = Integer.parseInt(txtId.getText()); uf.setId(idInt); uf.setNomeOficial(txtNomeOficial.getText()); Number itens = (Number) spiPopulacao.getValue(); pedido.setPopulacao(itens.intValue()); return uf; } public void setUfNaTela(Uf uf) { this.uf = uf; String idStr = String.valueOf(uf.getId()); txtId.setText(idStr); txtUf.setText(uf.getNomeOficial()); spiPopulacao.setValue(uf.getPopulacao()); } }
Compartilhar