Link to home
Start Free TrialLog in
Avatar of jkteater
jkteaterFlag for United States of America

asked on

Simple question revisited - classes and methods

I had thought that the earlier question was solved, but now I am getting another error.  This is I am going to send the code from each class file, so it is more clear.

The class below is the first class, from that class I need to call a method in the second class.
Here is the error I am getting,

The method ediBaseDialog() is undefined for the type ediBaseDialog

package com.ediua.handlers;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import com.ediua.dialogs.ediBaseDialog;
import java.awt.*;

public class ediDialogHandler extends AbstractHandler {
   
     
   public ediDialogHandler() {
      // TODO Auto-generated constructor stub
	   
   }
       
   @Override
   public Object execute(final ExecutionEvent event) throws ExecutionException {
	   ediBaseDialog.ediBaseDialog();  <=  Calling the method in question
	   return null;
   }
   
}

Open in new window



package com.ediua.dialogs;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

import com.teamcenter.rac.aif.AbstractAIFDialog;

public class ediBaseDialog extends AbstractAIFDialog{
   private static final long serialVersionUID = 1L;
   private JPanel centerPanel = null; 
   
   public ediBaseDialog(Dialog parent){
      super(parent,"Lets Get Ready", true);
	  createDialog();
   } // end constructor
		    
   private void createDialog() {
	  //Component listPanel = EmailList();
   	  Component buttonPanel = OKCancelButtons();
   	  
	  centerPanel = new JPanel();
      centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.PAGE_AXIS));
      centerPanel.setPreferredSize(new Dimension(600, 200));
            
      centerPanel.add(Box.createRigidArea(new Dimension(5, 0)));
      //centerPanel.add(listPanel);
      centerPanel.add(Box.createHorizontalGlue());
      centerPanel.add(Box.createRigidArea(new Dimension(0, 2)));
      centerPanel.add(buttonPanel);
   
   }

//////////////////////////////////////////////////////////////////////////
//                                                                      //
//                        OKCancelButtons()                             //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

private JPanel OKCancelButtons() {
   JButton okButton = new JButton("OK");
   okButton.setEnabled(true);
   okButton.addActionListener(new ActionListener() {
   
      public void actionPerformed(ActionEvent e) {
         dispose();
      }
   });

   JButton cancelButton = new JButton("Cancel");
   cancelButton.setEnabled(true);
   cancelButton.addActionListener(new ActionListener() {
      
	   public void actionPerformed(ActionEvent e) {
          dispose();
       }
   });

   JPanel p = new JPanel();
   p.setBorder(BorderFactory.createLineBorder(Color.red));
   p.setLayout(new BoxLayout(p, BoxLayout.LINE_AXIS));
   p.add(Box.createHorizontalGlue());
   p.add(okButton);
   p.add(cancelButton);

return p;
}

}

Open in new window



Thanks for helping me out
Avatar of for_yan
for_yan
Flag of United States of America image


You cannot adfress constructor in this way:
 ediBaseDialog.ediBaseDialog();
The name of the method ediBaseDialog();  in your second class is identical; with the
name of the lass - such method is called constructor and you can access
it only with the new


ediBaseDialog asdb = new ediBaseDialog(..)


 ediBaseDialog.ediBaseDialog();  - this acnnot work

Constructor's role is to create inastance of the class and
simluultaneosu it can executs some lines inside constructor - but main thing
is to create instance of the class

Explain what you want tio accomplish

Maybe you bneed to declare createDialog as public static
and then you can call it from anothe class this way:

ediBaseDialog.createDialog()

this at least would work formally - do you want to create Dialog window in this
way - it is another story

You can aslo do this way:

ediBaseDialog asdb = new ediBaseDialog(..)
asdb.createDialog(...)


In this acse your creatDialog should not be static, but it should be public (not private)
Avatar of jkteater

ASKER

ediBaseDialog asdb = new ediBaseDialog(..)

The constructor ediBaseDialog() is undefined

it is wanting something like

ediBaseDialog asdb = new ediBaseDialog(Dialog)
But i have tried to match the constructor from the second file.


I was wrong about the Dialog -  I was trying to pass something that does not exist
I may not even need the constructor in the second file
You need to provide parameters of the required type

ediBaseDialog asdb = new ediBaseDialog(parent);


and parent shoudl be of type Dialog

then it would match
Yes maybe you don't.
You just create your new window say Dialog in the createDialog method
OK - let me try to explain what I am trying to do

I have a command on a menu.  when the user clicks the command - the first file is activated or executed.
The only reason for the first file is to execute the second file.  So the first file should execute the second file.  The second file is basically going to be my base dialog class.  I will be adding tables - list etc.... to it

All I am trying to do is when the user clicks the command a dialog box appears and they will work from there.

The files are in seperate directories and each file has its a differnt package.

Being the first file is only executing the second file - I am not sure I need a constructor in the second file.  If you can look at the 2 files and give me any help on how to do it - that would be great!!!!
the first file is basically a handler

You should just replace this line
ediBaseDialog.ediBaseDialog();  <=  Calling the method in question

with something like that:

Frame f = new Frame("tttle");
Dialog parent = new Dialog(f, false);
new ediBaseDialog(parent);

I cannot understand what is your Dialog paren

or indeed remnove that constructor from the clasee
and say

(new ediBaseDialog()).createDialog();


The problem that it extends



ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for sticking with me on this one - I got rid of Dialog parent in the constructor and it worked fine.

Great!