Solved

Simple question revisited - classes and methods

Posted on 2011-09-07
16
199 Views
Last Modified: 2012-05-12
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
0
Comment
Question by:jkteater
  • 10
  • 6
16 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 36499434

You cannot adfress constructor in this way:
 ediBaseDialog.ediBaseDialog();
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36499440
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(..)
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36499448


 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

0
 
LVL 47

Expert Comment

by:for_yan
ID: 36499459
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
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36499466

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)
0
 

Author Comment

by:jkteater
ID: 36499510
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.


0
 

Author Comment

by:jkteater
ID: 36499519
I was wrong about the Dialog -  I was trying to pass something that does not exist
0
 

Author Comment

by:jkteater
ID: 36499528
I may not even need the constructor in the second file
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 47

Expert Comment

by:for_yan
ID: 36499532
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
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36499536
Yes maybe you don't.
You just create your new window say Dialog in the createDialog method
0
 

Author Comment

by:jkteater
ID: 36499549
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!!!!
0
 

Author Comment

by:jkteater
ID: 36499558
the first file is basically a handler
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36499591

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



0
 
LVL 47

Accepted Solution

by:
for_yan earned 125 total points
ID: 36499595


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();

0
 

Author Closing Comment

by:jkteater
ID: 36499636
Thanks for sticking with me on this one - I got rid of Dialog parent in the constructor and it worked fine.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36499645

Great!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now