Olá a situação e essa . Eu criei uma classe principal com botoes, e um botão tem que ativa essa caixa de dialogo , só que não consigo chama-la no codigo principal, o action perfomece esta um if nele esta o que era para ser chamado a classe caixa de dialogo mas não sei o que faz ele dar erro e não funcionar, anteriormente pelo Eclispe ele sugeriu criar um dialog para a classe principal fiz dai deu certo mporem não consigo mais fazer ele funcionar
alguem tem alguma ideia de chamar minha classe dialogo dentro da principal ?
lina
Novembro 19, 2009, 6:22pm
#2
Oi,
Post aqui a mensagem de erro…
Dica: Coloque um Sysout dentro do action para ver se realmente o mesmo está sendo executado.
Tchauzin!
CrOnNoS
Novembro 19, 2009, 11:12pm
#3
Aproveite e já poste o código entre as tags Code também
a classe principal e essa
[code]import java.awt.BorderLayout;
import javax.swing.JFileChooser;
import javax.swing.JPanel;
import javax.swing.JApplet;
import java.awt.Dimension;
import javax.swing.JScrollPane;
import java.awt.Rectangle;
import javax.swing.JTextArea;
import javax.swing.JButton;
import java.awt.Point;
import java.awt.Color;
import java.awt.Font;
import java.awt.TextArea;
import java.io .*;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JScrollBar;
public class AppletAva extends JApplet {
private JPanel jContentPane = null;
private JScrollPane ScrollPane1 = null;
protected JTextArea TextAva = null;
private JButton BotaoComp = null;
private JButton BotaoExec = null;
private JButton BotaoParar = null;
protected JButton BotaoNovo = null;
private JButton BotaoSalvar = null;
private JButton ButaoAbrir = null;
private JScrollPane PaneErro = null;
private JTextArea Erros = null;
/**
* This is the xxx default constructor
*/
public AppletAva() {
super();
}
/**
* This method initializes this
*
* @return void
*/
public void init() {
this.setSize(496, 337);
this.setBackground(new Color(94, 189, 214));
this.setContentPane(getJContentPane());
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.setBackground(new Color(122, 176, 220));
jContentPane.add(getScrollPane1(), null);
jContentPane.add(getBotaoComp(), null);
jContentPane.add(getBotaoExec(), null);
jContentPane.add(getBotaoParar(), null);
jContentPane.add(getBotaoNovo(), null);
jContentPane.add(getButaoSalvar(), null);
jContentPane.add(getButaoAbrir(), null);
jContentPane.add(getPaneErro(), null);
}
return jContentPane;
}
/**
* This method initializes ScrollPane1
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getScrollPane1() {
if (ScrollPane1 == null) {
ScrollPane1 = new JScrollPane();
ScrollPane1.setBounds(new Rectangle(20, 46, 360, 161));
ScrollPane1.setViewportView(getTextAva());
}
return ScrollPane1;
}
/**
* This method initializes TextAva
*
* @return javax.swing.JTextArea
*/
private JTextArea getTextAva() {
if (TextAva == null) {
TextAva = new JTextArea();
TextAva.setFont(new Font("Arial", Font.PLAIN, 12));
//TextAva.setLineWrap(false);
//TextAva.setWrapStyleWord(false);
}
return TextAva;
}
private JButton getBotaoExec() {
if (BotaoExec == null) {
BotaoExec = new JButton();
BotaoExec.setBounds(new Rectangle(123, 296, 85, 26));
BotaoExec.setText("Executar");
}
return BotaoExec;
}
private JButton getBotaoNovo() {
if (BotaoNovo == null) {
BotaoNovo = new JButton();
BotaoNovo.setText("Novo");
BotaoNovo.setLocation(new Point(414, 60));
BotaoNovo.setSize(new Dimension(69, 26));
BotaoNovo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
e.getActionCommand();
if(TextAva != null){
DialogoSN dial = new DialogoSN();
dial.setVisible(true);
// JDialog DialogSN = getDialogSN();
//DialogSN.setVisible(true);
}
}
});
}
return BotaoNovo;
}
protected JDialog getDialogSN() {
// TODO Auto-generated method stub
return null;
}
/**
* Metodo que inicializa o botão Salvar
*
* @return javax.swing.JButton
*/
private JButton getButaoSalvar() {
if (BotaoSalvar == null) {
BotaoSalvar = new JButton();
BotaoSalvar.setText("Salvar");
BotaoSalvar.setLocation(new Point(414, 100));
BotaoSalvar.setSize(new Dimension(70, 26));
BotaoSalvar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
Salvar salv=new Salvar();
}
}
);
}
return BotaoSalvar;
}
/**
* Metodo que inicializa o botão Abrir
*
* @return javax.swing.JButton
*/
private JButton getButaoAbrir() {
if (ButaoAbrir == null) {
ButaoAbrir = new JButton();
ButaoAbrir.setText("Abrir");
ButaoAbrir.setLocation(new Point(414, 140));
ButaoAbrir.setSize(new Dimension(69, 26));
ButaoAbrir.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
Abrir ab=new Abrir();
}
});
}
return ButaoAbrir;
}[/code]
a classe onde esta caixa de dialogo é essa
[code]import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Point;
import java.awt.Rectangle;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class DialogoSN extends AppletAva{
protected JDialog DialogSN = null; // @jve:decl-index=0:visual-constraint="75,-3"
protected JPanel jContPn = null;
protected JLabel jLabel = null;
protected JButton Sim = null;
protected JButton Nao = null;
public DialogoSN(){
}
protected JDialog getDialogSN() {
if (DialogSN == null) {
DialogSN = new JDialog();
DialogSN.setSize(new Dimension(286, 141));
DialogSN.setLocation(new Point(130, 70));
DialogSN.setContentPane(getJContPn());
DialogSN.setVisible(true);
}
return DialogSN;
}
//metodo que permite um painel para a caixa dialogo
protected JPanel getJContPn() {
if (jContPn == null) {
jLabel = new JLabel();
jLabel.setText(" Você deseja salvar este arquivo ?");
jLabel.setBackground(Color.white);
jLabel.setFont(new Font("Dialog", Font.BOLD, 12));
jLabel.setForeground(new Color(13, 12, 12));
jLabel.setBounds(new Rectangle(-1, 21, 278, 16));
jContPn = new JPanel();
jContPn.setLayout(null);
jContPn.setBackground(new Color(122, 176, 220));
jContPn.add(jLabel, null);
jContPn.add(getSim(), null);
jContPn.add(getNao(), null);
}
return jContPn;
}
// metodo do qual torna possivel o botão sim abrir o dialogo salvar
protected JButton getSim() {
if (Sim == null) {
Sim = new JButton();
Sim.setBounds(new Rectangle(42, 75, 61, 21));
Sim.setText("Sim");
Sim.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
DialogSim sim=new DialogSim();
}
});
}
return Sim;
}
// metodo que permite apagar o conteudo do text Area
protected JButton getNao() {
if (Nao == null) {
Nao = new JButton();
Nao.setBounds(new Rectangle(166, 77, 59, 19));
Nao.setText("Não");
Nao.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
TextAva.setText(" ");
TextAva.repaint();
DialogSN.dispose();
}
});
}
return Nao;
}
}
[/code]
Bem no console do Eclipse ele não acusa erro, só simplismente o console do Eclipse diz actio performece, e nada mais , e que ele não executa o q tem que executar que é a caixa de dialogo q esta na Classe DialogoSN