Como invocar um menu de outra classe através SelectionEvent

1 resposta
M

Olá,

Eu sou novato e estou a necessitar de uma ajuda.

tenho duas classes SWT Application e preciso de saltar de uma para a outra através SelectionEvent dos botoes e não estou conseguindo.

deixo o codigo das minhas classes, espero que possa ajudar.

CLASSE 1:

import org.eclipse.swt.widgets.Display;

import org.eclipse.swt.widgets.Shell;

import org.eclipse.swt.widgets.Table;

import org.eclipse.swt.SWT;

import org.eclipse.swt.widgets.TableColumn;

import org.eclipse.swt.widgets.Button;

import org.eclipse.swt.events.SelectionAdapter;

import org.eclipse.swt.events.SelectionEvent;

import org.eclipse.wb.swt.SWTResourceManager;

public class MenuSumarios {

protected Shell shell;
private Table table;

/**

  • Launch the application.
  • @param args
    */
    public static void main(String[] args) {
    try {
    MenuSumarios window = new MenuSumarios();
    window.open();
    } catch (Exception e) {
    e.printStackTrace();
    }
    }

/**

  • Open the window.
    */
    public void open() {
    Display display = Display.getDefault();
    createContents();
    shell.open();
    shell.layout();
    while (!shell.isDisposed()) {
    if (!display.readAndDispatch()) {
    display.sleep();
    }
    }
    }

/**

  • Create contents of the window.
    */
    protected void createContents() {
    shell = new Shell();
    shell.setImage(SWTResourceManager.getImage(“C:\Users\PSilva\Desktop\Eclipse\workspace\SGE\Logo25x25.jpg”));
    shell.setSize(580, 300);
    shell.setText(“SGE”);
table = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION);

table.setBounds(37, 37, 468, 126);

table.setHeaderVisible(true);

table.setLinesVisible(true);
TableColumn tblclmnCurso = new TableColumn(table, SWT.NONE);

tblclmnCurso.setWidth(81);

tblclmnCurso.setText(“Curso”);
TableColumn tblclmnDisciplina = new TableColumn(table, SWT.NONE);

tblclmnDisciplina.setWidth(69);

tblclmnDisciplina.setText(“Disciplina”);
TableColumn tblclmnDocente = new TableColumn(table, SWT.NONE);

tblclmnDocente.setWidth(63);

tblclmnDocente.setText(“Docente”);
TableColumn tblclmnTurma = new TableColumn(table, SWT.NONE);

tblclmnTurma.setWidth(54);

tblclmnTurma.setText(“Turma”);
TableColumn tblclmnDescrio = new TableColumn(table, SWT.NONE);

tblclmnDescrio.setWidth(142);

tblclmnDescrio.setText(“Descri\u00E7\u00E3o”);
TableColumn tblclmnData = new TableColumn(table, SWT.NONE);

tblclmnData.setWidth(53);

tblclmnData.setText(“Data”);
Button btnNovo = new Button(shell, SWT.NONE);

btnNovo.addSelectionListener(new SelectionAdapter() {

<a class="mention" href="/u/override">@Override</a>

public void widgetSelected(SelectionEvent e) {

}

});

btnNovo.setBounds(37, 195, 75, 25);

btnNovo.setText(“Novo”);
Button btnEditar = new Button(shell, SWT.NONE);

btnEditar.setBounds(118, 195, 75, 25);

btnEditar.setText(“Editar”);
Button btnVoltar = new Button(shell, SWT.NONE);

btnVoltar.addSelectionListener(new SelectionAdapter() {

<a class="mention" href="/u/override">@Override</a>

public void widgetSelected(SelectionEvent e) {

}

});

btnVoltar.setBounds(349, 195, 75, 25);

btnVoltar.setText(“Voltar”);

Button btnSair = new Button(shell, SWT.NONE);
btnSair.addSelectionListener(new SelectionAdapter() {

public void widgetSelected(SelectionEvent e) {

System.exit(0);

}

});

btnSair.setBounds(430, 195, 75, 25);

btnSair.setText(Sair);

}
}

CLASSE 2:

import java.awt.Component;

import java.awt.Dimension;

import java.awt.FlowLayout;

import java.awt.Image;

import java.awt.Toolkit;
import javax.swing.GroupLayout;

import javax.swing.ImageIcon;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.SwingConstants;

import javax.swing.GroupLayout.Alignment;

import javax.swing.LayoutStyle.ComponentPlacement;
import org.eclipse.swt.widgets.Display;

import org.eclipse.swt.widgets.Shell;

import org.eclipse.swt.widgets.Button;

import org.eclipse.swt.SWT;

import org.eclipse.swt.events.SelectionAdapter;

import org.eclipse.swt.events.SelectionEvent;

//import org.eclipse.wb.swing.FocusTraversalOnArray;

import org.eclipse.swt.widgets.Label;

import org.eclipse.wb.swt.SWTResourceManager;

public class Rere extends MenuSumarios{

protected Shell shell;

/**

  • Launch the application.
  • @param args
    */
    public static void main(String[] args) {
    try {
    Rere window = new Rere();
    window.open();
    } catch (Exception e) {
    e.printStackTrace();
    }
    }

/**

  • Open the window.
    */
    public void open() {
    Display display = Display.getDefault();
    createContents();
    shell.open();
    shell.layout();
    while (!shell.isDisposed()) {
    if (!display.readAndDispatch()) {
    display.sleep();
    }
    }
    }

/**

  • Create contents of the window.
    */
    protected void createContents() {
    shell = new Shell();
    shell.setImage(SWTResourceManager.getImage(“C:\Users\PSilva\Desktop\Eclipse\workspace\SGE\Logo25x25.jpg”));
    shell.setSize(450, 300);
    shell.setText(“SGE”);
Button btnSumarios = new Button(shell, SWT.NONE);

btnSumarios.addSelectionListener(new SelectionAdapter() {

<a class="mention" href="/u/override">@Override</a>

public void widgetSelected(SelectionEvent e) {
}

});

btnSumarios.setBounds(32, 34, 100, 60);

btnSumarios.setText(“Sum\u00E1rios”);
Button btnAlunos = new Button(shell, SWT.NONE);

btnAlunos.setBounds(284, 34, 100, 60);

btnAlunos.setText(“Alunos”);
Button btnDadosPessoais = new Button(shell, SWT.NONE);

btnDadosPessoais.setText(“Dados Pessoais”);

btnDadosPessoais.setBounds(32, 166, 100, 60);
Button btnSair = new Button(shell, SWT.NONE);

btnSair.addSelectionListener(new SelectionAdapter() {

<a class="mention" href="/u/override">@Override</a>

public void widgetSelected(SelectionEvent e) {

System.exit(0);

}

});

btnSair.setText(“Sair”);

btnSair.setBounds(284, 166, 100, 60);
Label lblLogo = new Label(shell, SWT.NONE);

lblLogo.setImage(SWTResourceManager.getImage(C:\Users\PSilva\Desktop\Eclipse\workspace\SGE\Logo100x100.jpg));

lblLogo.setBounds(164, 83, 100, 100);

}
}

Obrigado a todos

1 Resposta

M

Consegui resolver,

de qualquer forma obrigado

Criado 29 de janeiro de 2013
Ultima resposta 29 de jan. de 2013
Respostas 1
Participantes 1