Estrutura de dados - Aplicação com árvore

1 resposta
G

Estou com um problema pra resolver…
Será q alguém poderia me ajudar a implementar as funções para
os botões deste ambiente gráfico…
Valew pessoal…

import java.awt.BorderLayout;

import javax.swing.JPanel;

import javax.swing.JFrame;

import javax.swing.JMenuBar;

import javax.swing.JMenu;

import javax.swing.JMenuItem;

import java.awt.GridLayout;

import javax.swing.BorderFactory;

import javax.swing.border.TitledBorder;

import java.awt.Font;

import java.awt.Color;

import java.awt.FlowLayout;

import javax.swing.JLabel;

import javax.swing.JComboBox;

import javax.swing.JButton;

import javax.swing.JTextField;

import javax.swing.JScrollPane;

import javax.swing.JTree;

import java.awt.Dimension;

public class JanelaPrincipal extends JFrame {

private static final long serialVersionUID = 1L;

private JPanel jContentPane = null;

private JMenuBar barraMenu = null;

private JMenu menuArquivo = null;

private JMenu menuBuscar = null;

private JMenuItem menuAbrir = null;

private JMenuItem menuSalvar = null;

private JMenuItem menuFilhos = null;

private JMenuItem menuIrmaos = null;

private JMenuItem menuNetos = null;

private JMenuItem menuTios = null;

private JPanel painelFundo = null;

private JPanel painelEdicao = null;

private JLabel l1 = null;

private JComboBox comboNoAtual = null;

private JButton btNovoPai = null;

private JButton btNovoIrmao = null;

private JButton btNovoFilho = null;

private JPanel painelDados = null;

private JPanel painelDados1 = null;

private JPanel painelDados2 = null;

private JPanel pd11 = null;

private JLabel lbNome = null;

private JTextField txtNome = null;

private JLabel lbCidade = null;

private JTextField txtCidade = null;

private JLabel lbEstado = null;

private JTextField txtEstado = null;

private JLabel lbPais = null;

private JTextField txtPais = null;

private JPanel pd12 = null;

private JButton btAlterar = null;

private JPanel pd21 = null;

private JLabel lbNascimento = null;

private JTextField txtNascimento = null;

private JPanel pd22 = null;

private JLabel lbFalecimento = null;

private JTextField txtFalecimento = null;

private JScrollPane painelArvore = null;

private JTree jTree = null;

private JButton btRemover = null;

/**
 * This is the default constructor
 */
public JanelaPrincipal() {
	super();
	initialize();
}

/**
 * This method initializes this
 * 
 * @return void
 */
private void initialize() {
	this.setSize(587, 443);
	this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	this.setContentPane(getJContentPane());
	this.setJMenuBar(getBarraMenu());
	this.setTitle("Editor de Árvores Genealógicas");
}

/**
 * This method initializes jContentPane
 * 
 * @return javax.swing.JPanel
 */
private JPanel getJContentPane() {
	if (jContentPane == null) {
		jContentPane = new JPanel();
		jContentPane.setLayout(new BorderLayout());
		jContentPane.add(getPainelFundo(), BorderLayout.NORTH);
		jContentPane.add(getPainelArvore(), BorderLayout.CENTER);
	}
	return jContentPane;
}

/**
 * This method initializes barraMenu	
 * 	
 * @return javax.swing.JMenuBar	
 */
private JMenuBar getBarraMenu() {
	if (barraMenu == null) {
		barraMenu = new JMenuBar();
		barraMenu.add(getMenuArquivo());
		barraMenu.add(getMenuBuscar());
	}
	return barraMenu;
}

/**
 * This method initializes menuArquivo	
 * 	
 * @return javax.swing.JMenu	
 */
private JMenu getMenuArquivo() {
	if (menuArquivo == null) {
		menuArquivo = new JMenu();
		menuArquivo.setText("Arquivo");
		menuArquivo.add(getMenuAbrir());
		menuArquivo.add(getMenuSalvar());
	}
	return menuArquivo;
}

/**
 * This method initializes menuBuscar	
 * 	
 * @return javax.swing.JMenu	
 */
private JMenu getMenuBuscar() {
	if (menuBuscar == null) {
		menuBuscar = new JMenu();
		menuBuscar.setText("Buscar");
		menuBuscar.add(getMenuFilhos());
		menuBuscar.add(getMenuIrmaos());
		menuBuscar.add(getMenuNetos());
		menuBuscar.add(getMenuTios());
	}
	return menuBuscar;
}

/**
 * This method initializes menuAbrir	
 * 	
 * @return javax.swing.JMenuItem	
 */
private JMenuItem getMenuAbrir() {
	if (menuAbrir == null) {
		menuAbrir = new JMenuItem();
		menuAbrir.setText("Abrir");
	}
	return menuAbrir;
}

/**
 * This method initializes menuSalvar	
 * 	
 * @return javax.swing.JMenuItem	
 */
private JMenuItem getMenuSalvar() {
	if (menuSalvar == null) {
		menuSalvar = new JMenuItem();
		menuSalvar.setText("Salvar");
	}
	return menuSalvar;
}

/**
 * This method initializes menuFilhos	
 * 	
 * @return javax.swing.JMenuItem	
 */
private JMenuItem getMenuFilhos() {
	if (menuFilhos == null) {
		menuFilhos = new JMenuItem();
		menuFilhos.setText("Filhos de ...");
	}
	return menuFilhos;
}

/**
 * This method initializes menuIrmaos	
 * 	
 * @return javax.swing.JMenuItem	
 */
private JMenuItem getMenuIrmaos() {
	if (menuIrmaos == null) {
		menuIrmaos = new JMenuItem();
		menuIrmaos.setText("Irmãos de ...");
	}
	return menuIrmaos;
}

/**
 * This method initializes menuNetos	
 * 	
 * @return javax.swing.JMenuItem	
 */
private JMenuItem getMenuNetos() {
	if (menuNetos == null) {
		menuNetos = new JMenuItem();
		menuNetos.setText("Netos de ...");
	}
	return menuNetos;
}

/**
 * This method initializes menuTios	
 * 	
 * @return javax.swing.JMenuItem	
 */
private JMenuItem getMenuTios() {
	if (menuTios == null) {
		menuTios = new JMenuItem();
		menuTios.setText("Tios de ...");
	}
	return menuTios;
}

/**
 * This method initializes painelFundo	
 * 	
 * @return javax.swing.JPanel	
 */
private JPanel getPainelFundo() {
	if (painelFundo == null) {
		painelFundo = new JPanel();
		painelFundo.setLayout(new BorderLayout());
		painelFundo.add(getPainelEdicao(), BorderLayout.NORTH);
		painelFundo.add(getPainelDados(), BorderLayout.SOUTH);
	}
	return painelFundo;
}

/**
 * This method initializes painelEdicao	
 * 	
 * @return javax.swing.JPanel	
 */
private JPanel getPainelEdicao() {
	if (painelEdicao == null) {
		l1 = new JLabel();
		l1.setText("Seleção:");
		FlowLayout flowLayout = new FlowLayout();
		flowLayout.setAlignment(FlowLayout.LEFT);
		painelEdicao = new JPanel();
		painelEdicao.setPreferredSize(new Dimension(392, 62));
		painelEdicao.setLayout(flowLayout);
		painelEdicao.setBorder(BorderFactory.createTitledBorder(null, "Edição", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("Dialog", Font.BOLD, 12), new Color(51, 51, 51)));
		painelEdicao.add(l1, null);
		painelEdicao.add(getComboNoAtual(), null);
		painelEdicao.add(getBtNovoPai(), null);
		painelEdicao.add(getBtNovoIrmao(), null);
		painelEdicao.add(getBtNovoFilho(), null);
		painelEdicao.add(getBtRemover(), null);
	}
	return painelEdicao;
}

/**
 * This method initializes comboNoAtual	
 * 	
 * @return javax.swing.JComboBox	
 */
private JComboBox getComboNoAtual() {
	if (comboNoAtual == null) {
		comboNoAtual = new JComboBox();
		comboNoAtual.setMaximumRowCount(4);
		comboNoAtual.addItem("Asdrubal");
		comboNoAtual.addItem("Pafúncio");
		comboNoAtual.addItem("John Doe");
	}
	return comboNoAtual;
}

/**
 * This method initializes btNovoPai	
 * 	
 * @return javax.swing.JButton	
 */
private JButton getBtNovoPai() {
	if (btNovoPai == null) {
		btNovoPai = new JButton();
		btNovoPai.setText("Novo Pai");
	}
	return btNovoPai;
}

/**
 * This method initializes btNovoIrmao	
 * 	
 * @return javax.swing.JButton	
 */
private JButton getBtNovoIrmao() {
	if (btNovoIrmao == null) {
		btNovoIrmao = new JButton();
		btNovoIrmao.setText("Novo Irmão");
	}
	return btNovoIrmao;
}

/**
 * This method initializes btNovoFilho	
 * 	
 * @return javax.swing.JButton	
 */
private JButton getBtNovoFilho() {
	if (btNovoFilho == null) {
		btNovoFilho = new JButton();
		btNovoFilho.setText("Novo Filho");
	}
	return btNovoFilho;
}

/**
 * This method initializes painelDados	
 * 	
 * @return javax.swing.JPanel	
 */
private JPanel getPainelDados() {
	if (painelDados == null) {
		painelDados = new JPanel();
		painelDados.setLayout(new BorderLayout());
		painelDados.setBorder(BorderFactory.createTitledBorder(null, "Dados", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("Dialog", Font.BOLD, 12), new Color(51, 51, 51)));
		painelDados.add(getPainelDados1(), BorderLayout.CENTER);
		painelDados.add(getPainelDados2(), BorderLayout.SOUTH);
	}
	return painelDados;
}

/**
 * This method initializes painelDados1	
 * 	
 * @return javax.swing.JPanel	
 */
private JPanel getPainelDados1() {
	if (painelDados1 == null) {
		GridLayout gridLayout1 = new GridLayout();
		gridLayout1.setRows(2);
		gridLayout1.setColumns(2);
		painelDados1 = new JPanel();
		painelDados1.setLayout(gridLayout1);
		painelDados1.add(getPd11(), null);
		painelDados1.add(getPd12(), null);
		painelDados1.add(getPd21(), null);
		painelDados1.add(getPd22(), null);
	}
	return painelDados1;
}

/**
 * This method initializes painelDados2	
 * 	
 * @return javax.swing.JPanel	
 */
private JPanel getPainelDados2() {
	if (painelDados2 == null) {
		lbPais = new JLabel();
		lbPais.setText("País:");
		lbEstado = new JLabel();
		lbEstado.setText("Estado:");
		lbCidade = new JLabel();
		lbCidade.setText("Cidade:");
		FlowLayout flowLayout2 = new FlowLayout();
		flowLayout2.setAlignment(FlowLayout.LEFT);
		painelDados2 = new JPanel();
		painelDados2.setLayout(flowLayout2);
		painelDados2.add(lbCidade, null);
		painelDados2.add(getTxtCidade(), null);
		painelDados2.add(lbEstado, null);
		painelDados2.add(getTxtEstado(), null);
		painelDados2.add(lbPais, null);
		painelDados2.add(getTxtPais(), null);
	}
	return painelDados2;
}

/**
 * This method initializes pd11	
 * 	
 * @return javax.swing.JPanel	
 */
private JPanel getPd11() {
	if (pd11 == null) {
		lbNome = new JLabel();
		lbNome.setText("Nome:");
		FlowLayout flowLayout1 = new FlowLayout();
		flowLayout1.setAlignment(FlowLayout.LEFT);
		pd11 = new JPanel();
		pd11.setLayout(flowLayout1);
		pd11.add(lbNome, null);
		pd11.add(getTxtNome(), null);
	}
	return pd11;
}

/**
 * This method initializes txtNome	
 * 	
 * @return javax.swing.JTextField	
 */
private JTextField getTxtNome() {
	if (txtNome == null) {
		txtNome = new JTextField();
		txtNome.setPreferredSize(new Dimension(200, 20));
	}
	return txtNome;
}

/**
 * This method initializes txtCidade	
 * 	
 * @return javax.swing.JTextField	
 */
private JTextField getTxtCidade() {
	if (txtCidade == null) {
		txtCidade = new JTextField();
		txtCidade.setPreferredSize(new Dimension(100, 20));
	}
	return txtCidade;
}

/**
 * This method initializes txtEstado	
 * 	
 * @return javax.swing.JTextField	
 */
private JTextField getTxtEstado() {
	if (txtEstado == null) {
		txtEstado = new JTextField();
		txtEstado.setPreferredSize(new Dimension(100, 20));
	}
	return txtEstado;
}

/**
 * This method initializes txtPais	
 * 	
 * @return javax.swing.JTextField	
 */
private JTextField getTxtPais() {
	if (txtPais == null) {
		txtPais = new JTextField();
		txtPais.setPreferredSize(new Dimension(100, 20));
	}
	return txtPais;
}

/**
 * This method initializes pd12	
 * 	
 * @return javax.swing.JPanel	
 */
private JPanel getPd12() {
	if (pd12 == null) {
		pd12 = new JPanel();
		pd12.setLayout(new FlowLayout());
		pd12.add(getBtAlterar(), null);
	}
	return pd12;
}

/**
 * This method initializes btAlterar	
 * 	
 * @return javax.swing.JButton	
 */
private JButton getBtAlterar() {
	if (btAlterar == null) {
		btAlterar = new JButton();
		btAlterar.setText("Alterar");
	}
	return btAlterar;
}

/**
 * This method initializes pd21	
 * 	
 * @return javax.swing.JPanel	
 */
private JPanel getPd21() {
	if (pd21 == null) {
		lbNascimento = new JLabel();
		lbNascimento.setText("Nascimento:");
		FlowLayout flowLayout3 = new FlowLayout();
		flowLayout3.setAlignment(FlowLayout.LEFT);
		pd21 = new JPanel();
		pd21.setLayout(flowLayout3);
		pd21.add(lbNascimento, null);
		pd21.add(getTxtNascimento(), null);
	}
	return pd21;
}

/**
 * This method initializes txtNascimento	
 * 	
 * @return javax.swing.JTextField	
 */
private JTextField getTxtNascimento() {
	if (txtNascimento == null) {
		txtNascimento = new JTextField();
		txtNascimento.setPreferredSize(new Dimension(100, 20));
	}
	return txtNascimento;
}

/**
 * This method initializes pd22	
 * 	
 * @return javax.swing.JPanel	
 */
private JPanel getPd22() {
	if (pd22 == null) {
		FlowLayout flowLayout4 = new FlowLayout();
		flowLayout4.setAlignment(FlowLayout.LEFT);
		lbFalecimento = new JLabel();
		lbFalecimento.setText("Falecimento:");
		pd22 = new JPanel();
		pd22.setLayout(flowLayout4);
		pd22.add(lbFalecimento, null);
		pd22.add(getTxtFalecimento(), null);
	}
	return pd22;
}

/**
 * This method initializes txtFalecimento	
 * 	
 * @return javax.swing.JTextField	
 */
private JTextField getTxtFalecimento() {
	if (txtFalecimento == null) {
		txtFalecimento = new JTextField();
		txtFalecimento.setPreferredSize(new Dimension(100, 20));
	}
	return txtFalecimento;
}

/**
 * This method initializes painelArvore	
 * 	
 * @return javax.swing.JScrollPane	
 */
private JScrollPane getPainelArvore() {
	if (painelArvore == null) {
		painelArvore = new JScrollPane();
		painelArvore.setBorder(BorderFactory.createTitledBorder(null, "Árvore", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("Dialog", Font.BOLD, 12), new Color(51, 51, 51)));
		painelArvore.setViewportView(getJTree());
	}
	return painelArvore;
}

/**
 * This method initializes jTree	
 * 	
 * @return javax.swing.JTree	
 */
private JTree getJTree() {
	if (jTree == null) {
		jTree = new JTree();
	}
	return jTree;
}

/**
 * This method initializes btRemover	
 * 	
 * @return javax.swing.JButton	
 */
private JButton getBtRemover() {
	if (btRemover == null) {
		btRemover = new JButton();
		btRemover.setText("Remover");
	}
	return btRemover;
}

} // @jve:decl-index=0:visual-constraint=“25,25”

1 Resposta

cassio

Olá,

Qual a sua dúvida exatamente? Seja mais claro quanto ao problema que vc está tendo!

Criado 15 de novembro de 2006
Ultima resposta 15 de nov. de 2006
Respostas 1
Participantes 2