This site requires JavaScript, please enable it in your browser!
Greenfoot back
Nosson1459
Nosson1459 wrote ...

2017/2/23

package

1
2
3
danpost danpost

2017/2/23

#
Noson1459 wrote...
this isn't my own subclass
Where did you get it? Could you not just add a link to the page?
Nosson1459 Nosson1459

2017/2/23

#
It got downloaded with Java in a zip folder. Now can you answer the original question so I don't have to retype it (or quote it)?
danpost danpost

2017/2/23

#
Nosson1459 wrote...
It got downloaded with Java in a zip folder.
Okay, and the only thing you did was make it extend greenfoot.Actor.
Now can you answer the original question so I don't have to retype it (or quote it)?
Well, I do not have any definitive answers. I could hypothesize that as a subclass of Actor, the JComponent class is in the wrong package.
Nosson1459 Nosson1459

2017/2/24

#
danpost wrote...
Well, I do not have any definitive answers. I could hypothesize that as a subclass of Actor, the JComponent class is in the wrong package.
What do you mean in the wrong package? I didn't change any other code besides for the extends greenfoot.Actor.
danpost danpost

2017/2/24

#
Nosson1459 wrote...
danpost wrote...
Well, I do not have any definitive answers. I could hypothesize that as a subclass of Actor, the JComponent class is in the wrong package.
What do you mean in the wrong package? I didn't change any other code besides for the extends greenfoot.Actor.
Your JComponent class in in your project folder, which is not a part of any of the packages that you are importing. You may have manufactured a path that is similar to that of the one you can import; but from within a different package.
Nosson1459 Nosson1459

2017/2/24

#
But everything works/compiles even though in java.awt.Component it accesses methods from other classes in package java.awt that I didn't bring into this project. I brought only a few of the java classes into my program directory and in Component it calls a private method in Toolkit even though I didn't bring in Toolkit. I see that in this scenario my modified JButton has some of the greenfoot.Actor methods so it is importing everything correctly just there are two things: 1) Not all of the greenfoot.Actor methods are in JButton 2) They don't really work for javax.swing.JButton
danpost danpost

2017/2/24

#
(1) which ones are missing? (2) 'They'? referring to what?
Nosson1459 Nosson1459

2017/2/24

#
(1) It will take some patience to check which ones are missing so that question will have to wait (2) The methods from greenfoot.Actor
danpost danpost

2017/2/24

#
(2) what happens when you try them? Are you getting any error messages? if so, what are you getting? You should know by now that details are needed and examples are helpful.
Nosson1459 Nosson1459

2017/2/24

#
(1) Missing methods:
  • addedToWorld
  • getIntersectingObjects
  • getNeighbours
  • getObjectsAtOffset
  • getObjectsInRange
  • getOneIntersectingObject
  • getOneObjectAtOffset
  • intersects
  • isTouching
  • removeTouching
(2) Since I know that by now I already posted the error message in the first post. I wouldn't necessarily think that I get an error message with every method that I would try. When I tried doing button.act(); I got the error "java.lang.NoSuchMethodError: javax.swing.JButton.act()V". When I tried doing addObject(button, 20, 20); I got "Exception in thread "main" java.lang.VerifyError: Bad type on operand stack Type 'javax/swing/JButton' (current frame, stack) is not assignable to 'greenfoot/Actor'".
danpost danpost

2017/2/24

#
Nosson1459 wrote...
When I tried doing button.act();
How is 'button' declared? Show class code where you placed this line.
Nosson1459 Nosson1459

2017/2/27

#
danpost wrote...
How is 'button' declared? Show class code where you placed this line.
import greenfoot.World;
import javax.swing.JButton;

/**
 * Write a description of class Frame here.
 * 
 * @author Yehuda (1/2 of Nosson1459 - greenfoot.org user name)
 * @version 2/22/2017
 */
public class Frame extends World
{
    JButton button = new JButton();

    /**
     * Constructor for objects of class Frame.
     * 
     */
    public Frame()
    {
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(600, 400, 1);
        button.act();
    }
}
When I said missing I mean missing from the list that pops up when I press Ctrl+Space, because act() is in the list but it got the following error:
java.lang.NoSuchMethodError: javax.swing.JButton.act()V
	at Frame.<init>(Frame.java:22)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
	at greenfoot.export.GreenfootScenarioViewer.instantiateNewWorld(GreenfootScenarioViewer.java:356)
	at greenfoot.export.GreenfootScenarioViewer.init(GreenfootScenarioViewer.java:212)
	at greenfoot.export.GreenfootScenarioMain.main(GreenfootScenarioMain.java:100)
Sorry I didn't reply but I was getting more than 8 replies at a time and I missed this one, now I came back here to check and I saw the last post was by you.
danpost danpost

2017/2/27

#
What happens when you remove line 2 from the class? This line:
import javax.swing.JButton;
Nosson1459 Nosson1459

2017/2/27

#
danpost wrote...
What happens when you remove line 2 from the class? This line:
import javax.swing.JButton;
"cannot find symbol" Because I don't have a JButton class in my program folder, it's in a folder which is in my program folder/directory.
danpost danpost

2017/2/27

#
Nosson1459 wrote...
"cannot find symbol" Because I don't have a JButton class in my program folder, it's in a folder which is in my program folder/directory.
Then, you are creating a 'javax.swing.JButton' object which is not an Actor object -- it is not a '(greenfoot.Actor)Button' object.
There are more replies on the next page.
1
2
3