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

2020/5/29

Act method causing error in switch statement (getKey())

1
2
3
4
5
danpost danpost

2020/5/31

#
4444Jam4444 wrote...
Code omitted because my comment was marked as spam for posting my world code!!!
It might just be because you have a link to an outside site referenced in your world code.
4444Jam4444 4444Jam4444

2020/5/31

#
danpost wrote...
The getWorldCanvas method only worked in the Legacy versions of greenfoot. I am not privy to any workarounds.
That's quite unfortunate... How else am I supposed to scroll? What I need is for the world to display a number of string elements line-by-line, with the ability for the user to scroll through the string elements (Additionally, is there any way for these string elements to be bounded to certain dimensions other than the world's dimensions, and to stop displaying a specific element if it's outside these boundaries?)
danpost wrote...
4444Jam4444 wrote...
Code omitted because my comment was marked as spam for posting my world code!!!
It might just be because you have a link to an outside site referenced in your world code.
That's a likely possibility. I didn't know this was a thing though, and they're only links to java-tutorial related websites and forums, Greenfoot discussions included. There isn't anything I can really do about this, is there?
danpost danpost

2020/5/31

#
4444Jam4444 wrote...
That's quite unfortunate... How else am I supposed to scroll? What I need is for the world to display a number of string elements line-by-line, with the ability for the user to scroll through the string elements (Additionally, is there any way for these string elements to be bounded to certain dimensions other than the world's dimensions, and to stop displaying a specific element if it's outside these boundaries?)
There are others ways to scroll -- and your text image can provide the limits of scrolling. Scrolling can be controlled by mouse clicking on "scroll" objects, mouse dragging on text image or on "scroll" bars or by specific keypresses (like on arrow keys, for example). My Scrolling Tutorial scenario includes mouse dragging and keyboard scrolling and my TextFile Viewing World Class scenario is an example of using "scroll" objects (buttons and bars).
4444Jam4444 4444Jam4444

2020/5/31

#
danpost wrote...
My Scrolling Tutorial scenario includes mouse dragging and keyboard scrolling and my TextFile Viewing World Class scenario is an example of using "scroll" objects (buttons and bars).
I'm going through the scrolling scenario, but I have one question; does the scroll bar scroll for a maximum length? Because the scroll bar/methods that I need must be able to scroll flexibly (depending on file size that the text is read from). Also, it is likely that the text will be long enough to go off-screen, how do I make the text automatically newline after a certain number of characters? I think the world dimensions of 420, 600 can fit ~43 chars horizontally, not sure though.
danpost danpost

2020/5/31

#
4444Jam4444 wrote...
I'm going through the scrolling scenario, but I have one question; does the scroll bar scroll for a maximum length? Because the scroll bar/methods that I need must be able to scroll flexibly (depending on file size that the text is read from).
No. It is dependent on the length of the text at hand.
Also, it is likely that the text will be long enough to go off-screen, how do I make the text automatically newline after a certain number of characters? I think the world dimensions of 420, 600 can fit ~43 chars horizontally, not sure though.
I suggest you use mouse dragging which will easily allow for scrolling both vertically AND horizontally.
4444Jam4444 4444Jam4444

2020/5/31

#
danpost wrote...
I suggest you use mouse dragging which will easily allow for scrolling both vertically AND horizontally.
Interesting. Only issue with that is that the text will (in most worlds where scrolling is used) be clickable, making a possible problem for the user. On the other hand, that isn't in my documentation so I don't need to compensate for this, and this is for a school project so the user doesn't entirely matter. Thanks. I'll look into that. Have you made any scenarios on mouse dragging that I could look at?
danpost danpost

2020/6/1

#
4444Jam4444 wrote...
Have you made any scenarios on mouse dragging that I could look at?
There is my Scroller Class Demos scenario. At the bottom of the initial page of the Scrolling Tutorial, you will find a link to Mouse drag controlled scrolling code used by a world.
4444Jam4444 4444Jam4444

2020/6/1

#
Thanks, I'll get back to you on how that goes. In the mean time, I have a rather odd question: Can classes (more specifically, world classes) have a return type? e.g.
public class myWorld extends World
{
    public String myWorld(){ //String return type
        //stuff
    }
}
I highly doubt the answer is yes, but hey, worth a shot. What I mean by that is; Main world (calculator) User changes mode (World: mode select) User selects calculation history mode (World: show calc history) Information (calculation history) is retrieved from file and displayed on-screen User selects one specific calculation by clicking on it The answer to that calculation is transferred from show calc history world to actor calculate in main world So far I've used a separate constructor in the main world to transfer this information upon world change (which will happen immediately after text is clicked) but is there a better way to do this?
4444Jam4444 4444Jam4444

2020/6/1

#
Sorry, I know I'm asking a few too many questions on this one discussion, but I've just noticed an issue. Every minute or so, my main world re-initialises itself which causes a lot of lag when editing the code. I've checked through every class that involves the main world, but none of them ever use Calculator = new Calculator(); so I don't know what could be causing the start-up terminal message to pop up ~6 times upon completely closing and reopening greenfoot. Might be a temporary issue involving some iffy syntax in a recent edit, but I'm unsure.
danpost danpost

2020/6/1

#
4444Jam4444 wrote...
Can classes (more specifically, world classes) have a return type? e.g. << Code Omitted >>
Line 3, because it contains a return type, is not a constructor declaration, but is instead a method declaration.
So far I've used a separate constructor in the main world to transfer this information upon world change (which will happen immediately after text is clicked) but is there a better way to do this?
Depending on exactly what you are dealing with, you may be able to use static content for this, as long as nothing involves any state or behavior of the current World object. That is, as long as it can be done without referencing the active World objecct (cannot use "this", explicitly or implicitly).
4444Jam4444 wrote...
terminal message
Shot entire terminal output (copy all/paste).
4444Jam4444 4444Jam4444

2020/6/2

#
danpost wrote...
4444Jam4444 wrote...
Can classes (more specifically, world classes) have a return type? e.g. << Code Omitted >>
Line 3, because it contains a return type, is not a constructor declaration, but is instead a method declaration.
Yeah, I thought something along those lines. Didn't think that would work. Again, was worth a shot.
danpost wrote...
Depending on exactly what you are dealing with, you may be able to use static content for this, as long as nothing involves any state or behavior of the current World object. That is, as long as it can be done without referencing the active World objecct (cannot use "this", explicitly or implicitly).
That seems more reasonable. How do I make a class static? One of my classes is (technically) static but not really, the class itself isn't static but all its methods and attributes are static. It works as far as I know.
danpost wrote...
Shot entire terminal output (copy all/paste).
It's just a bunch of the same message that prints to the terminal when the main world is initialised, greeting the user and requesting for bug reports.
public Calculator(){
    ...
    printInitialMessage();
    ...
}

public void printInitialMessage(){
    System.out.println("NOTICE FOR THE USER:");
    System.out.println("It is vital that any bugs in this software are reported");
    System.out.println("to the development team for possible maintenance.");
    System.out.println("Some issues can go unnoticed in the development of a");
    System.out.println("software, despite extensive bug testing.");
    System.out.println("The development team wish to maintain a quality product,");
    System.out.println("and user feedback is highly effective and highly valued");
    System.out.println("in the maintenance of this product.");
}
Was repeated ~6 times in the terminal (no other terminal messages) upon starting Greenfoot last night. Don't think I'm having this issue anymore, but I can't be sure.
4444Jam4444 4444Jam4444

2020/6/2

#
Ah, I've found the problem that was causing the lag. I'm no longer having the issue of the initial message popping up multiple times, but I have found that I should have put the 'createFiles()' method before other method calls in the world constructor rather than after, and made certain classes static. I am getting a different issue, the terminal is showing: java.io.FileNotFoundException: Constants.txt (The system cannot find the file specified) at java.base/java.io.FileInputStream.open0(Native Method) at java.base/java.io.FileInputStream.open(FileInputStream.java:219) at java.base/java.io.FileInputStream.<init>(FileInputStream.java:157) at java.base/java.io.FileInputStream.<init>(FileInputStream.java:112) at java.base/java.io.FileReader.<init>(FileReader.java:60) at Constant.<init>(Constant.java:35) at Calculate.<init>(Calculate.java:29) at RightArrow.<init>(RightArrow.java:13) <-- This terminal message is repeated for each arrow (up, down, left, right) and I'm not sure why. The arrows don't relate to files at all. When clicked, it highlights the line in arrow "Calculate cal = new Calculate();" which makes me think that the arrows are only in the terminal because they create a new calculate object. at Calculator.makeArrowButtons(Calculator.java:164) at Calculator.<init>(Calculator.java:63) Ok, so while typing this, I noticed that one of the terminal error messages highlights a completely unrelated comment?! How? The comment relates to code that hasn't been implemented yet! I'm confused... at Calculate.<init>(Calculate.java:29)
/**private boolean indexIsValid = true;*/
//This boolean isn't even used in any of my code, was intended for a feature that I haven't added yet
Referring back to the whole 'arrows' thing, how would I call a method within a class (specifically an actor subclass) without creating a new object of that class? I can't make the methods static (tried just now) because they're modifier method (like get/setPrivateVariableAttribute) that increments (down/right arrows) / decrements (up/left arrows) currentIndex, which is a non-static variable.
danpost danpost

2020/6/2

#
4444Jam4444 wrote...
How do I make a class static? One of my classes is (technically) static but not really, the class itself isn't static but all its methods and attributes are static. It works as far as I know.
I was not saying to write another class. I was pointing out that maybe by using static methods and attributes (in a class you already have), you could accomplish what you were trying to do.
It's just a bunch of the same message that prints to the terminal when the main world is initialised, greeting the user and requesting for bug reports. << Code Omitted >> Was repeated ~6 times in the terminal (no other terminal messages) upon starting Greenfoot last night. Don't think I'm having this issue anymore, but I can't be sure.
Okay.
danpost danpost

2020/6/2

#
4444Jam4444 wrote...
Referring back to the whole 'arrows' thing, how would I call a method within a class (specifically an actor subclass) without creating a new object of that class? I can't make the methods static (tried just now) because they're modifier method (like get/setPrivateVariableAttribute) that increments (down/right arrows) / decrements (up/left arrows) currentIndex, which is a non-static variable.
I believe you are needing this line:
Calculate calculate = ((Calculator)getWorld()).myCalculator;
Then you can call the method on 'calculate'.
4444Jam4444 4444Jam4444

2020/6/3

#
danpost wrote...
I believe you are needing this line:
Calculate calculate = ((Calculator)getWorld()).myCalculator;
Then you can call the method on 'calculate'.
Yeah, I realised that my button class held the answer all along, but this page wasn't loading (505 error) so I couldn't post an edit.
danpost wrote...
4444Jam4444 wrote...
How do I make a class static? One of my classes is (technically) static but not really, the class itself isn't static but all its methods and attributes are static. It works as far as I know.
I was not saying to write another class. I was pointing out that maybe by using static methods and attributes (in a class you already have), you could accomplish what you were trying to do.
I was referring to a different class that I made static. I made 2 other classes static since then. I probably should've specified that I was referring to a different class, my bad. I still don't understand why a multi-line comment was involved in a terminal error message? I mean, it's no big deal, but still... Whoops, I wrote this last night and forgot to post...
There are more replies on the next page.
1
2
3
4
5