I am using LibGDX for a 2D game. I have a class BasicActor that extends Actor which is a class inside the LibGDX library. By pressing alt + 1 while coding inside the BasicActor Eclipse shows suggestions such as implementing methods of a parent class. For some reason it doesn't this time. It's been a while since I coded with eclipse and I want to know if there is a mistake on my side or if this simply won't work that way.
The shortcut for adding unimplemented methods in a class in Eclipse is "Alt + Shift + S + V".
Hum... [ALT][1]? I didn't know that shortcut, but in all Eclipse editions I've used there are two ways to override super-methods:
Press [CTRL][SPACE] with the cursor into a class' body. A pop-up list of overridable methods and other stuff will appear.
Execute Source > Override/implement methods.
Related
I'm new to Java and OOP. I have a strange disorder that makes me extremely curious how things work. So I copied this code that use normalize() and I'm trying to get the source code of it but all I found is
public abstract String normalize(String path);
In:
FileSystem.java file
Of course, know what it does. But I'm curious how and why i cant find the code behind it.
Thank you
Michal
If you are using an IDE (like Eclipse), you can use it to find the concrete implementations of that method.
In Eclipse:
Ctrl + Shift + T and type java.io.FileSystem; click "OK"
Hover over the normalize method name. A menu will appear like below.
Click "Open Implementation"
If there is more than one implementation available, you will see a list. Click on the one you want to open.
If there is only one, then that single implementation will be opened automatically.
What I'm thinking of doing is creating a class for my little subview, so I can use it over and over again. Specifically, in my project, I need a colored rectangular and a label, and between those subviews those are the ones gonna change. Thus, I want a class that represent that two components as one component.
I'm trying to use swing. Before, I used acm package which gave me convenient way of doing it, but I can't solve that problem with swing. So, the problem starts here, I couldn't figure out how to create a custom GUI class for a subview.
I want to put them in a for loop later, so I want to handle the case in once rather than writing for 20 times manually.
Any help would be appreciated,
Create your custom class so that it extends a JPanel. From there, you can add your common subcomponents, which sets each one up by passing parameters through the constructor, and then implement any common behaviours with methods on that class.
You could try Window Builder plugin for eclipse for drag and drop editor. You could try to figure what's going wrong by organizing you objects.
I know how to find the source by using ctrl + left click on a method, for example, but what if I want to find where this method is used? I'm using Windows 7.
Let's suppose I have the following method:
class A {
public int sum(int a, int b) {
return a+b;
}
}
and I am using this method in
class B {
...
a.sum(c, d);
...
}
and I want to find where I used sum while I was in class A.
PS: I'm new to Android studio (started using it about a month ago).
In Android Studio, highlight the method and either right click > Find usages or use the Alt+F7 shortcut.
Edit: Ctrl+left click on a method is useful for finding where that method was initially declared
For Ubuntu users:
For me Alt+F7 has not worked,
so I've solved the conflict by going to the
Ubuntu System settings-> keyboard -> shortcuts
and changing Alt+F7 in there with another combination.
And now it's working ))
Just click on the method or variable and any usages will be highlighted and on the scroll bar on the right side of your code you will see gray bars appear, those are the usages of the current highlighted (or clicked on) variable or method within your code.
Here are different key shortcuts for displaying method or variable usage. The keymaps with F14 in them were added by me; the others are default. For Windows (and Linux?), replace the ⌘ key with Ctrl (I think). Find Usages shows them in a dedicated window in Android Studio (the solution in other answers), while Show Usages puts them in a popup (second image below).
To find all uses of a variable or method in Android Studio you can use
ctrl+shift+F7(window/Ubuntu)
after that for navigation purpose you can use F3
use [Ctrl+b] or [Ctrl+Alt+b] to navigate to the origin of the method or variable declearation and implementation
Ubuntu is Ctrl+Alt+7 or Ctrl+b to show the usage of the class. Ctrl+Alt+F7 is not work.
I am following a tutorial on how to create a flappy bird clone from http://www.kilobolt.com/day-3-understanding-the-libgdx-framework.html
This is where I am at
I know what's going because GScreen is a concrete class, it has to provide implementations of all the methods in the Screen interface.
To do this, I looked up "Add unimplemented methods" feature in the Android Studio
and used the control o shortcut to get to this dialog.
However from this dialog, is there a way of selecting multiple methods that you want stubs for? If I double click one, I just get the stub for that method. Is there a way to get multiple stubs at a time, for efficiency sakes?
You can select multiple methods using the control (Command on a Mac) key or the shift key, then single click. The shift key selects a continuous list of methods, the control key allows non-contiguous selections.
You can right click on the class name in java file. A drop down arrow will come containing an various options like "GENERATE". Click it and select which unimplemented you want to apply it will be automatic generated.
If I'm in an interface and pointing to a method name, what can I do to quickly go to the ONLY implementation of that method?
Using Eclipse 3.6.
F3 is the typical "go to implementation". For interfaces that go to the interface definition.
Instead use Ctrl + T to see all implementations of the interface definition. You can then easily go to the one you want with the arrow keys and Enter. I believe that the first one is automatically selected so that Ctrl-T + Enter will do what you need.
I just checked this on my Eclipse 3.6 install: Hold control (command on Mac), hover over the method name and select "Open Implementation".
You may assign a keyboard shortcut to this action by using Window > Preferences > General > Keys and searching for "Open Implementation".
In the keymap (General > Keys) search for "open implementation" and map it to whatever you want. I chose Ctrl + Shift + I. Make sure you select "Editing Java Source" in the When box. I tested it, and having the cursor over the method name and pressing Ctrl + Shift + I took me directly to the implementation instead of showing the hierarchy that you get with Ctrl + T.
Also you can see an answer to a nearly identical question for other options:
In eclipse, ctrl-click goes to the declaration of the method I clicked. For interfaces with one implementation, how can I just directly to that implementation?
If someone still need this information nowadays (Eclipse version 2022), to jump into interface method definition starting from an #Override method, now in Eclipse you can see on the left, next to the method signature, a little white triangle. By clicking on that you will jump to the implemented interface method. here an image of the little triangle
Oterwise, if you are on a interface method definition and you need to jump to one of the implementations, you must use CTRL+T shortcut to see the list of available implementations and than click on one of them.