Eclipse - access by method name requires a receiver

S

S

<a
href="http://home.online.no/~phersta/siggen/pictures/java-error.JPG">This
picture shows my problem</a>

Have tried to google and find information about this, and I`m sorry if
this is a noob-question.
I am using eclipse (ver 3.1.1.) with java 1.5.0.06.

I am trying to make a GUI using VE in eclipse. And so far I have
managed to make make some JTabbedPane, JPanes and JButtons. It seemed
to work - with no errors. But when I opened the file again today - all
I got was this message - and I have no idea on how to solve it.


2. question: I have a calculation.class who does all calculations. And
I want to use methods from this inside my jAppletRobotArm.java to
calculate things. But I can not seem to find the right place to add
(calculations calculation = new calculations()) - parameter. Is there
something special to deal with since this is an applet? How to make it
easiest?

Thanks in advantage for the swift replies.
 
H

Hendrik Maryns

S schreef:

Seems like this is caused by a plugin. I don´t know where you get the
upper part of the editor window from.

BUT more important: start all your Java classes with a capital letter
(Eclipse warns about this!)

And you might want to use the Java perspective instead of resource.
2. question: I have a calculation.class who does all calculations. And
I want to use methods from this inside my jAppletRobotArm.java to
calculate things. But I can not seem to find the right place to add
(calculations calculation = new calculations()) - parameter. Is there
something special to deal with since this is an applet? How to make it
easiest?

Have you imported it? Once again, start class names with a capital letter.

H.

--
Hendrik Maryns

==================
www.lieverleven.be
http://aouw.org
 
S

S

Thanks for a very swift reply. Have changed all class-names and now it
works. However I still have one problem.
I have these lines (removed lines not necessary for this example)

public class JAppletRobotArm extends JApplet {
private Calculations calculations = new Calculations();
}

When I run debug mode - this will run, and start the constructor of
Calcuations, and do everything I have asked for in the constructor.

However I can not for instance write: this.calculations.doSomething()
later on, when for instance a button is pressed.

I have also tried to write

public class JAppletRobotArm extends JApplet {
private Calculations calculations = null;
}

and ad the creation of the class here:

public JAppletRobotArm() {
super();
}

or here:

public void init() {
this.setSize(500, 400);
this.setContentPane(getJContentPane());
this.calculations = new Calculations();
}

withouth any luck. I can not seem to use this.calculations.someMethod()
anywhere in the code.

Is there a major points I have missed here? I should be able to call
methods from other classes when pushing a button in one class.

Thanks again for a swift reply.
 
H

Hendrik Maryns

S schreef:
Thanks for a very swift reply. Have changed all class-names and now it
works.

Good, though I don´t see how the two could be related (Java does work
with non-conventional class names, there are even a lot of them defined
in the API, it is just not recommended, definitely not if you hope for
help on this forum).

However I still have one problem.
I have these lines (removed lines not necessary for this example)

public class JAppletRobotArm extends JApplet {
private Calculations calculations = new Calculations();
}

When I run debug mode - this will run, and start the constructor of
Calcuations, and do everything I have asked for in the constructor.

However I can not for instance write: this.calculations.doSomething()
later on, when for instance a button is pressed.

I have also tried to write

public class JAppletRobotArm extends JApplet {
private Calculations calculations = null;
}

and ad the creation of the class here:

public JAppletRobotArm() {
super();
}

I don´t know what you mean by this. I don´t suppose calculations is
initialised in JApplet.
or here:

public void init() {
this.setSize(500, 400);
this.setContentPane(getJContentPane());
this.calculations = new Calculations();
}

Should work _if you invoke this method_. But it seems like a very
useless method to me. You might consider to make it private.
withouth any luck. I can not seem to use this.calculations.someMethod()
anywhere in the code.
Strange.

Is there a major points I have missed here? I should be able to call
methods from other classes when pushing a button in one class.

Why don´t you post some real code that exhibits the problem. See
http://mindprod.com/jgloss/sscce.html

Cheers, H.

--
Hendrik Maryns

==================
www.lieverleven.be
http://aouw.org
 
S

S

The calculations should be initialized in the JAppletRobotArm.java -
because this is the main applet. Do I need a main() method in an
Applet?

So what I want to do is to initialize Calculations calculation, and use
methods from this class for instance in: private JButton getJButton() {

Thanks once again for the swift reply.


This is the code (removed comments) as it is in JAppletRobotArm.java
===================================================
import javax.swing.JPanel;
import javax.swing.JApplet;
import javax.swing.JTabbedPane;
import javax.swing.JButton;
public class JAppletRobotArm extends JApplet {
private static final long serialVersionUID = 2621050794148530944L;
private JPanel jContentPane = null;
private JTabbedPane jTabbedPane = null;
private JPanel jPanelOptions = null;
private JPanel jPanelGraphs = null;
private JPanel jPanelStatistics = null;
private JButton jButton = null;
private JButton jButtonNextGen = null;
private JPanel jPanelRobotArm1 = null;
private JPanel jPanelRobotArm2 = null;

public JAppletRobotArm() {
super();
Calculations calculation = new Calculations();
}

private JTabbedPane getJTabbedPane() {
if (jTabbedPane == null) {
jTabbedPane = new JTabbedPane();
jTabbedPane.setBounds(new java.awt.Rectangle(1,5,492,342));
jTabbedPane.addTab("Graphs", null, getJPanelGraphs(), null);
jTabbedPane.addTab("Options", null, getJPanelOptions(), null);
jTabbedPane.addTab("Statistics", null, getJPanelStatistics(), null);
}
return jTabbedPane;
}

private JPanel getJPanelOptions() {
if (jPanelOptions == null) {
jPanelOptions = new JPanel();
jPanelOptions.setLayout(null);
}
return jPanelOptions;
}

private JPanel getJPanelGraphs() {
if (jPanelGraphs == null) {
jPanelGraphs = new JPanel();
jPanelGraphs.setLayout(null);
jPanelGraphs.add(getJButton(), null);
jPanelGraphs.add(getJButtonNextGen(), null);
jPanelGraphs.add(getJPanelRobotArm1(), null);
jPanelGraphs.add(getJPanelRobotArm2(), null);
}
return jPanelGraphs;
}

private JPanel getJPanelStatistics() {
if (jPanelStatistics == null) {
jPanelStatistics = new JPanel();
}
return jPanelStatistics;
}

private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setBounds(new java.awt.Rectangle(142,6,104,25));
jButton.setText("Start/pause");
jButton.addPropertyChangeListener(new
java.beans.PropertyChangeListener() {
public void propertyChange(java.beans.PropertyChangeEvent e) {
if ((e.getPropertyName().equals("enabled"))) {
System.out.println("propertyChange(enabled)"); // TODO
Auto-generated property Event stub "enabled"
}
}
});
}
return jButton;
}

private JButton getJButtonNextGen() {
if (jButtonNextGen == null) {
jButtonNextGen = new JButton();
jButtonNextGen.setBounds(new java.awt.Rectangle(8,5,130,27));
jButtonNextGen.setText("Next Generation");
}
return jButtonNextGen;
}

private JPanel getJPanelRobotArm1() {
if (jPanelRobotArm1 == null) {
jPanelRobotArm1 = new JPanel();
jPanelRobotArm1.setPreferredSize(new java.awt.Dimension(200,200));
jPanelRobotArm1.setSize(new java.awt.Dimension(200,200));
jPanelRobotArm1.setLocation(new java.awt.Point(7,33));
}
return jPanelRobotArm1;
}
private JPanel getJPanelRobotArm2() {
if (jPanelRobotArm2 == null) {
jPanelRobotArm2 = new JPanel();
jPanelRobotArm2.setBounds(new java.awt.Rectangle(208,33,200,200));
jPanelRobotArm2.setPreferredSize(new java.awt.Dimension(200,200));
}
return jPanelRobotArm2;
}

public void init() {
this.setSize(500, 400);
this.setContentPane(getJContentPane());
//this.calculation = new Calculations();
}

private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(getJTabbedPane(), null);
}
return jContentPane;
}

} // @jve:decl-index=0:visual-constraint="0,7"
 
H

Hendrik Maryns

S schreef:
The calculations should be initialized in the JAppletRobotArm.java -
because this is the main applet. Do I need a main() method in an
Applet?

I don´t know, never wrote an applet. See
http://mindprod.com/jgloss/applet.html
So what I want to do is to initialize Calculations calculation, and use
methods from this class for instance in: private JButton getJButton() {

Thanks once again for the swift reply.


This is the code (removed comments) as it is in JAppletRobotArm.java
===================================================

public JAppletRobotArm() {
super();
Calculations calculation = new Calculations();
}

And what does Java do now? Forget about calculation, of course! It is
a local variable. Define it outside the constructor, just like all
those swing thingies above.

HTH, H.

--
Hendrik Maryns

==================
www.lieverleven.be
http://aouw.org
 
S

S

Hehe, well - got to admit I don`t realy understand what was wrong, but
now it works. Moved the define outside the constructor as you said, and
tried it... And now it works. Guess it was just a result of to mutch
work and no fun.

Hope I did not spend to mutch of your time, and thanks for the help.
 
R

Roedy Green

2. question: I have a calculation.class who does all calculations. And
I want to use methods from this inside my jAppletRobotArm.java to
calculate things.

Your Calculate class could be a top level default scope class in the
same package as your Applet. Making it a nested class just adds
complications you don't want to deal with unless you have to.

It is highly irritating and confusing when someone fail to start class
names with Upper case, packages and methods with lower case. It is as
disorienting as someone who named the male characters in his novel
Beverly, Leslie, and Carroll and the female characters Pat, Chris and
Jamie.
 
R

Roedy Green

Should work _if you invoke this method_. But it seems like a very
useless method to me. You might consider to make it private.
did he not say he was writing an JApplet? You need a public init.

Applets don't decide their size. HTML does.
this should not be necessary unless you are doing something very
peculiar.
 
R

Roedy Green

private JTabbedPane getJTabbedPane() {
if (jTabbedPane == null) {
jTabbedPane = new JTabbedPane();
jTabbedPane.setBounds(new java.awt.Rectangle(1,5,492,342));
jTabbedPane.addTab("Graphs", null, getJPanelGraphs(), null);
jTabbedPane.addTab("Options", null, getJPanelOptions(), null);
jTabbedPane.addTab("Statistics", null, getJPanelStatistics(), null);
}
return jTabbedPane;

It is much less wicked to have a long method so long as it contains no
conditional logic. Just pile the initialisation code into your init
method or if you want to split it up into bites, use methods that just
init and return nothing and do no if. init is called only once. You
can trust it to be the place to create all your widgets.
 
S

S

Yes, I know. But I use the inbuilt Visual Editor in Eclipse, so it
automatically generates these and other methods. I know it is better to
write the GUI "by hand", but I really don`t like it - and just want an
easy way to make a GUI that works. Any other recommendations than using
the VE would happily be accepted.
 
C

Chris Smith

Roedy Green said:
It is highly irritating and confusing when someone fail to start class
names with Upper case, packages and methods with lower case. It is as
disorienting as someone who named the male characters in his novel
Beverly, Leslie, and Carroll and the female characters Pat, Chris and

I agree that it's irritating... but I'm confused about something. Pat,
Chris, and Jamie are all fairly common female names.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
O

Oliver Wong

Chris Smith said:
I agree that it's irritating... but I'm confused about something. Pat,
Chris, and Jamie are all fairly common female names.

I had assumed that was intentional (because the odds seem low that that
was coincidental/accidental), though it does break the symmetry because the
male characters have "obviously female" names, as opposed to "typically
female, but possibly male" names.

- Oliver
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top