a minha classe principal é essa:
/****************************************************************/
/* Poseidon */
/* */
/****************************************************************/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
import javax.swing.table.*;
/**
* Summary description for Poseidon
*2052102
*/
public class Poseidon extends JFrame
{
// Variables declaration
private JTabbedPane jTabbedPane1;
//-----
private JPanel contentPane, paineltabela, painelgrafo, painelvariavel, paineltarefa;
//-----
private JTable tabelavariavel,tabelatarefa, tabelateste;
//-----
private JScrollPane scrollvariavel, scrolltarefa;
//-----
private int totallinhas, alt, al, linhastarefa,cont, linhas, tamanholinhas,
controlalinhas, index, contastring;
//-----
private String variavel;
//-----
private JComboBox combobox;
//-----
JMenuItem sair, abrir, guardar, miadtarefa, miadvariavel;
//-----
JTable [] tabelasvar = new JTable[30];
//-----
JFrame w;
//-----
// End of variables declaration
public Poseidon()
{
super("Poseidon");
initializeComponent();
this.setVisible(true);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always regenerated
* by the Windows Form Designer. Otherwise, retrieving design might not work properly.
* Tip: If you must revise this method, please backup this GUI file for JFrameBuilder
* to retrieve your design properly in future, before revising this method.
*/
private void initializeComponent()
{
JMenuBar barra = new JMenuBar();
setJMenuBar(barra);
TratBarra trat = new TratBarra();
tabelavariavel = new JTable();
tabelatarefa = new JTable();
tabelavariavel.getTableHeader().setReorderingAllowed(false);
tabelavariavel.setModel(new DefaultTableModel());
tabelavariavel.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
tabelavariavel.setBackground(Color.cyan);
tabelatarefa.getTableHeader().setReorderingAllowed(false);
tabelatarefa.setModel(new DefaultTableModel());
tabelatarefa.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
tabelatarefa.setBackground(Color.white);
CaixaCombinacao combobox = new CaixaCombinacao();
DefaultCellEditor editor = new DefaultCellEditor(combobox);
tabelatarefa.setDefaultEditor(Object.class, editor);
painelvariavel = new JPanel();
painelvariavel.setLayout(new GridLayout(1, 0));
painelvariavel.setBorder(new TitledBorder("Variaveis"));
painelvariavel.setBounds(15, 35, 490, 650);
painelvariavel.setVisible(false);
this.add(painelvariavel);
scrollvariavel = new JScrollPane();
scrollvariavel.setViewportView(tabelavariavel);
painelvariavel.add(scrollvariavel);
paineltarefa = new JPanel();
paineltarefa.setLayout(new GridLayout(1,0));
paineltarefa.setBorder(new TitledBorder("Tarefas"));
paineltarefa.setBounds(506, 35, 490,650);
paineltarefa.setVisible(false);
this.add(paineltarefa);
scrolltarefa = new JScrollPane();
scrolltarefa.setViewportView(tabelatarefa);
paineltarefa.add(scrolltarefa);
tamanholinhas = 1;
linhas=1;
cont=0;
JMenu arquivo = new JMenu("Arquivo");
JMenu mtabela = new JMenu("Tabela");
arquivo.setMnemonic(KeyEvent.VK_A);
mtabela.setMnemonic(KeyEvent.VK_T);
miadvariavel = new JMenuItem("Adicionar Variavel");
miadtarefa = new JMenuItem("Adicionar Tarefa");
abrir = new JMenuItem("Abrir");
guardar = new JMenuItem("Guardar");
sair = new JMenuItem("Sair");
sair.addActionListener(trat);
miadvariavel.addActionListener(trat);
miadtarefa.addActionListener(trat);
mtabela.add(miadvariavel);
miadvariavel.setMnemonic(KeyEvent.VK_V);
mtabela.add(miadtarefa);
miadtarefa.setMnemonic(KeyEvent.VK_F);
arquivo.add(abrir);
abrir.setMnemonic(KeyEvent.VK_B);
arquivo.add(guardar);
guardar.setMnemonic(KeyEvent.VK_G);
arquivo.addSeparator();
arquivo.add(sair);
sair.setMnemonic(KeyEvent.VK_S);
barra.add(arquivo);
barra.add(mtabela);
jTabbedPane1 = new JTabbedPane();
contentPane = (JPanel)this.getContentPane();
//-----
paineltabela = new JPanel();
//-----
painelgrafo = new JPanel();
//-----
//
// jTabbedPane1
//
jTabbedPane1.addTab("Tabela", paineltabela);
jTabbedPane1.addTab("Grafo", painelgrafo);
jTabbedPane1.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e)
{
painelvariavel.setVisible(false);
}
});
//
// contentPane
//
contentPane.setLayout(null);
addComponent(contentPane, jTabbedPane1, 11,10,990,690);
//
// paineltabela
//
paineltabela.setLayout(null);
//
// painelgrafo
//
painelgrafo.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
//
// Poseidon
//
this.setTitle("UMa Poseidon");
this.setLocation(new Point(2, 1));
this.setSize(new Dimension(558, 441));
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
this.setExtendedState(MAXIMIZED_BOTH);
}
/** Add Component Without a Layout Manager (Absolute Positioning) */
private void addComponent(Container container,Component c,int x,int y,int width,int height)
{
c.setBounds(x,y,width,height);
container.add(c);
}
//
// TODO: Add any appropriate code in the following Event Handling Methods
//
private void jTabbedPane1_stateChanged(ChangeEvent e)
{
System.out.println("\njTabbedPane1_stateChanged(ChangeEvent e) called.");
// TODO: Add any handling code here
}
//
// TODO: Add any method code to meet your needs in the following area
//
private class TratBarra implements ActionListener{
public void actionPerformed(ActionEvent e){
if(e.getSource() == sair){
int op = JOptionPane.showConfirmDialog(null, "Deseja mesmo fechar o aplicativo?","Sair", JOptionPane.YES_NO_OPTION);
if(op == JOptionPane.YES_OPTION){
System.exit(0);
}
}
if(e.getSource() == miadvariavel){
final JFrame w = new JFrame();
new AdVariavel(w);
}
if(e.getSource() == miadtarefa){
final JFrame w = new JFrame();
new AdTarefa(w);
}
}
}
//============================= Testing ================================//
//= =//
//= The following main method is just for testing this class you built.=//
//= After testing,you may simply delete it. =//
//======================================================================//
public static void main(String[] args)
{
Spash sp = new Spash(3000);
sp.mostraTela();
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
try
{
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
}
catch (Exception ex)
{
System.out.println("Failed loading L&F: ");
System.out.println(ex);
}
new Poseidon();
}
//= End of Testing =
private class AdVariavel extends JDialog
{
// Variables declaration
private JLabel jLabel1;
private JTextField jTextField1;
private JButton varOK;
private JButton varCancel;
private JPanel contentPane;
//-----
private JTextField jTextField2;
private JList listadominio;
private JScrollPane jScrollPane1;
private JButton varAdiciona;
private JButton varRemove;
private JPanel jPanel1;
private DefaultListModel modelo1;
//-----
// End of variables declaration
public AdVariavel(Frame w)
{
super(w);
initializeComponent();
//
// TODO: Add any constructor code after initializeComponent call
//
this.setVisible(true);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always regenerated
* by the Windows Form Designer. Otherwise, retrieving design might not work properly.
* Tip: If you must revise this method, please backup this GUI file for JFrameBuilder
* to retrieve your design properly in future, before revising this method.
*/
private void initializeComponent()
{
modelo1 = new DefaultListModel();
jLabel1 = new JLabel();
jTextField1 = new JTextField();
varOK = new JButton();
varCancel = new JButton();
contentPane = (JPanel)this.getContentPane();
//-----
jTextField2 = new JTextField();
listadominio = new JList(modelo1);
jScrollPane1 = new JScrollPane();
varAdiciona = new JButton();
varRemove = new JButton();
jPanel1 = new JPanel();
//-----
//
// jLabel1
//
jLabel1.setText("Nome da variável:");
//
// jTextField1
//
jTextField1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
jTextField1_actionPerformed(e);
}
});
//
// varOK
//
varOK.setText("OK");
varOK.setMnemonic(KeyEvent.VK_O);
varOK.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
varOK_actionPerformed(e);
}
});
//
// varCancel
//
varCancel.setText("Cancelar");
varCancel.setMnemonic(KeyEvent.VK_C);
varCancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
varCancel_actionPerformed(e);
}
});
//
// contentPane
//
contentPane.setLayout(null);
addComponent(contentPane, jLabel1, 12,12,105,18);
addComponent(contentPane, jTextField1, 118,10,137,22);
addComponent(contentPane, varOK, 170,227,83,28);
addComponent(contentPane, varCancel, 257,227,85,28);
addComponent(contentPane, jPanel1, 12,42,332,180);
//
// jTextField2
//
jTextField2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
jTextField2_actionPerformed(e);
}
});
//
// listadominio
//
listadominio.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e)
{
listadominio_valueChanged(e);
}
});
//
// jScrollPane1
//
jScrollPane1.setViewportView(listadominio);
//
// varAdiciona
//
varAdiciona.setText("Adicionar");
varAdiciona.setMnemonic(KeyEvent.VK_A);
varAdiciona.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
varAdiciona_actionPerformed(e);
}
});
//
// varRemove
//
varRemove.setText("Remover");
varRemove.setMnemonic(KeyEvent.VK_R);
varRemove.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
varRemove_actionPerformed(e);
}
});
//
// jPanel1
//
jPanel1.setLayout(null);
jPanel1.setBorder(new TitledBorder("Dominio:"));
addComponent(jPanel1, jTextField2, 17,22,130,22);
addComponent(jPanel1, jScrollPane1, 165,21,154,144);
addComponent(jPanel1, varAdiciona, 56,50,89,28);
addComponent(jPanel1, varRemove, 57,84,88,28);
//
// AdTarefas
//
this.setTitle("Adicionar Variavel");
this.setLocation(new Point(1, 0));
this.setSize(new Dimension(367, 296));
this.setLocationRelativeTo(null);
this.setResizable(false);
}
/** Add Component Without a Layout Manager (Absolute Positioning) */
private void addComponent(Container container,Component c,int x,int y,int width,int height)
{
c.setBounds(x,y,width,height);
container.add(c);
}
//
// TODO: Add any appropriate code in the following Event Handling Methods
//
private void jTextField1_actionPerformed(ActionEvent e)
{
System.out.println("\njTextField1_actionPerformed(ActionEvent e) called.");
// TODO: Add any handling code here
}
private void varOK_actionPerformed(ActionEvent e)
{
System.out.println("\nvarOK_actionPerformed(ActionEvent e) called.");
if (jTextField1 == null){
return;
}
if (jTextField1.getText().length()<1){
JOptionPane.showMessageDialog(null,"Não introduziu nenhuma variavel","AVISO", 1 );
jTextField1.requestFocus();
return;
}
else {
if (modelo1.getSize() == 0){
JOptionPane.showMessageDialog(null,"Não introduziu nenhum dominio","AVISO", 1 );
return;
}
else{
painelvariavel.add(scrollvariavel);
index = 0;
variavel = jTextField1.getText();
contastring = variavel.length();
System.out.println(contastring);
DefaultTableModel dtm = (DefaultTableModel)tabelavariavel.getModel();
tabelavariavel.getTableHeader().setBackground(Color.yellow);
dtm.addColumn(variavel, new Object[]{});
al = modelo1.getSize();
totallinhas = al;
for(int i = 0;i < modelo1.getSize();i++){
listadominio.setSelectedIndex(index) ;
Object dominio = listadominio.getSelectedValue();
dtm.addRow(new Object[]{dominio});
index ++;
}
tabelasvar[cont] = tabelavariavel;
cont++;
System.out.println(cont);
for(int i=0;i<cont;i++){
tabelateste = tabelasvar[i];
linhas = tabelateste.getRowCount();
if (linhas >= tamanholinhas){
tamanholinhas = linhas;
}
}
for (int i=0;i<cont;i++){
tabelateste = tabelasvar[i];
System.out.println(linhas);
linhas = tabelateste.getRowCount();
tabelateste.setRowHeight((tamanholinhas/linhas)*20);
tabelasvar[i] = tabelateste;
System.out.println(tabelateste);
}
}
tabelavariavel = new JTable();
scrollvariavel = new JScrollPane();
painelvariavel.add(tabelavariavel);
tabelavariavel.setBackground(Color.cyan);
tabelavariavel.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
scrollvariavel.setViewportView(tabelavariavel);
painelvariavel.setVisible(true);
tabelavariavel.getTableHeader().setReorderingAllowed(false);
this.setVisible(false);
miadtarefa.setEnabled(true);
miadvariavel.setEnabled(true);
DefaultTableModel dtm = (DefaultTableModel)tabelatarefa.getModel();
tabelatarefa.getTableHeader().setBackground(Color.yellow);
controlalinhas = tamanholinhas - linhastarefa;
for(int i = 0;i < controlalinhas;i++){
dtm.addRow(new Object[]{});
linhastarefa++;
}
tabelatarefa.setRowHeight((tamanholinhas/linhas)*20);
}
// TODO: Add any handling code here
}
private void varCancel_actionPerformed(ActionEvent e)
{
System.out.println("\nvarCancel_actionPerformed(ActionEvent e) called.");
this.setVisible(false);
}
private void jTextField2_actionPerformed(ActionEvent e)
{
System.out.println("\njTextField2_actionPerformed(ActionEvent e) called.");
// TODO: Add any handling code here
}
private void listadominio_valueChanged(ListSelectionEvent e)
{
System.out.println("\nlistadominio_valueChanged(ListSelectionEvent e) called.");
if(!e.getValueIsAdjusting())
{
Object o = listadominio.getSelectedValue();
System.out.println(">>" + ((o==null)? "null" : o.toString()) + " is selected.");
// TODO: Add any handling code here for the particular object being selected
}
}
private void varAdiciona_actionPerformed(ActionEvent e)
{
System.out.println("\nvarAdiciona_actionPerformed(ActionEvent e) called.");
if(jTextField2.getText().length()>=1){
modelo1.addElement(jTextField2.getText());
jTextField2.setText("");
jTextField2.requestFocus();
}
}
private void varRemove_actionPerformed(ActionEvent e)
{
System.out.println("\nvarRemove_actionPerformed(ActionEvent e) called.");
int index = listadominio.getSelectedIndex();
modelo1.remove(index);
}
//
// TODO: Add any method code to meet your needs in the following area
//
}
private class AdTarefa extends JDialog
{
// Variables declaration
private JLabel jLabel1;
private JTextField jTextField1;
private JButton tarOK;
private JButton tarCancel;
private JPanel contentPane;
//-----
private JPanel jPanel1;
//-----
// End of variables declaration
public AdTarefa(Frame w)
{
super(w);
initializeComponent();
//
// TODO: Add any constructor code after initializeComponent call
//
this.setVisible(true);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always regenerated
* by the Windows Form Designer. Otherwise, retrieving design might not work properly.
* Tip: If you must revise this method, please backup this GUI file for JFrameBuilder
* to retrieve your design properly in future, before revising this method.
*/
private void initializeComponent()
{
jLabel1 = new JLabel();
jTextField1 = new JTextField();
tarOK = new JButton();
tarCancel = new JButton();
contentPane = (JPanel)this.getContentPane();
//
// jLabel1
//
jLabel1.setText("Nome da tarefa:");
//
// jTextField1
//
jTextField1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
jTextField1_actionPerformed(e);
}
});
//
// tarOK
//
tarOK.setText("OK");
tarOK.setMnemonic(KeyEvent.VK_O);
tarOK.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
tarOK_actionPerformed(e);
}
});
//
// tarCancel
//
tarCancel.setText("Cancelar");
tarCancel.setMnemonic(KeyEvent.VK_C);
tarCancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
tarCancel_actionPerformed(e);
}
});
//
// contentPane
//
contentPane.setLayout(null);
addComponent(contentPane, jLabel1, 12,12,105,18);
addComponent(contentPane, jTextField1, 118,10,120,22);
addComponent(contentPane, tarOK, 10,50,83,28);
addComponent(contentPane, tarCancel, 153,50,85,28);
//
// AdTarefas
//
this.setTitle("Adicionar Tarefa");
this.setLocation(new Point(1, 0));
this.setSize(new Dimension(250, 120));
this.setLocationRelativeTo(null);
this.setResizable(false);
}
/** Add Component Without a Layout Manager (Absolute Positioning) */
private void addComponent(Container container,Component c,int x,int y,int width,int height)
{
c.setBounds(x,y,width,height);
container.add(c);
}
//
// TODO: Add any appropriate code in the following Event Handling Methods
//
private void jTextField1_actionPerformed(ActionEvent e)
{
System.out.println("\njTextField1_actionPerformed(ActionEvent e) called.");
// TODO: Add any handling code here
}
private void tarOK_actionPerformed(ActionEvent e)
{
System.out.println("\ntarOK_actionPerformed(ActionEvent e) called.");
if (jTextField1 == null){
return;
}
if (jTextField1.getText().length()<1){
JOptionPane.showMessageDialog(null,"Não introduziu nenhuma tarefa","AVISO", 1 );
jTextField1.requestFocus();
return;
}
else{
String variavel = jTextField1.getText();
DefaultTableModel dtm = (DefaultTableModel)tabelatarefa.getModel();
dtm.addColumn(variavel,new Object[]{});
controlalinhas = tamanholinhas - linhastarefa;
for(int i = 0;i < controlalinhas;i++){
dtm.addRow(new Object[]{});
linhastarefa++;
}
for(int i=0; i < tabelatarefa.getColumnCount(); i++){
tabelatarefa.getColumnModel().getColumn(i).setPreferredWidth(100);
tabelatarefa.getColumnModel().getColumn(i).setResizable(false);
tabelatarefa.getTableHeader().setBackground(Color.yellow);
}
tabelatarefa.setRowHeight((tamanholinhas/linhas)*20);
}
paineltarefa.setVisible(true);
tabelatarefa.getTableHeader().setReorderingAllowed(true);
this.setVisible(false);
miadtarefa.setEnabled(true);
miadvariavel.setEnabled(true);
// TODO: Add any handling code here
}
private void tarCancel_actionPerformed(ActionEvent e)
{
System.out.println("\ntarCancel_actionPerformed(ActionEvent e) called.");
this.setVisible(false);
}
}
}
depois preciso dessa classe k da um splash de entrada:
/*@ Classe de montagem da tela Splash ligada apenas á Classe Agenda(Principal)
*/
//package rosto;
import javax.swing.*;
import java.awt.*;
public class Spash extends JWindow{
private int duracao;
public Spash(int d){
duracao=d;
}
public void mostraSpalsh(){
JPanel painel=(JPanel)getContentPane();
int width =260;
int height=238;
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
int x = (screen.width-width)/2;
int y = (screen.height-height)/2;
setBounds(x,y,width,height);
JLabel lbSpash = new JLabel(new ImageIcon("poseidon.jpg"));
painel.add(lbSpash,BorderLayout.CENTER);
painel.setBackground(Color.white);
Color linha = new Color(0,0,0,0);
painel.setBorder(BorderFactory.createLineBorder(linha,8));
setVisible(true);
try{
Thread.sleep(duracao);
setVisible(false);
}
catch(Exception e){
JOptionPane.showMessageDialog(null,"Erro"+e.getMessage());
}
}
public void mostraTela(){
mostraSpalsh();
}
}
e tem a class k faz a combobox k é essa:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class CaixaCombinacao extends JComboBox{
ImageIcon[] images;
String[] linguagens = {"x", "check"};
public CaixaCombinacao(){
images = new ImageIcon[linguagens.length];
Integer[] intArray = new Integer[linguagens.length];
for (int i = 0; i < linguagens.length; i++) {
intArray[i] = new Integer(i);
images[i] = createImageIcon(linguagens[i] + ".gif");
this.addItem(images[i]);
}
this.setMaximumRowCount(2);
ComboBoxRenderer renderer= new ComboBoxRenderer();
this.setRenderer(renderer);
}
protected static ImageIcon createImageIcon(String path) {
java.net.URL imgURL = CaixaCombinacao.class.getResource(path);
System.out.println(imgURL);
return new ImageIcon(imgURL);
}
class ComboBoxRenderer extends JLabel
implements ListCellRenderer {
public ComboBoxRenderer() {
setOpaque(false);
setHorizontalAlignment(CENTER);
setVerticalAlignment(CENTER);
}
public Component getListCellRendererComponent(
JList list,
Object value,
int index,
boolean isSelected,
boolean cellHasFocus) {
//Get the selected index. (The index param isn't
//always valid, so just use the value.)
System.out.println(images);
int selectedIndex = index;
if (isSelected) {
setBackground(list.getSelectionBackground());
setForeground(list.getSelectionForeground());
} else {
setBackground(list.getBackground());
setForeground(list.getForeground());
}
ImageIcon icon = images[selectedIndex];
String pet = linguagens[selectedIndex];
setIcon(icon);
return this;
}
}
}
amigo peço desculpa se tou sendo massador mas tou mesmo aflito,
agradeço muito a sua ajuda e desculpa postar isso assim,é k o codigo é muito grande, se voce kiser eu posso mandar o codigo bem como todas as imagens pra seu mail…