How to automate adding multiple methods in android studio 1.0? - java

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.

Related

Adding unimplemented methods of child classes in Eclipse

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.

Using marker interfaces in android studio / IntelliJ IDEA

I am trying to manage relatively large projects in Android Studio and IntelliJ IDEA. I want to use a marker interface to indicate a class that is unfinished in some way.
public interface ToDo {
}
The trouble is that when I click the "has implementations" icon, I get a list of all subclasses of classes that include the words implements ToDo, including anonymous ones (as I should). Is it possible to do a search so that I only get a list of classes where the words implements ToDo actually appear? If not, is there an alternative way to do it?
Alternative way for intellij & Android Studio
From the app menu, Edit > Find > Find in Path (quick tip the keyboard shortcut will be listed next to the menu option)
type in " implements ToDo" in text to find
For Scope, Select Custom "Project Files" (this will help you avoid some generated classes coming up in your search results)
For File name filter, check the checkbox for "File masks" and type in "*.java" in the textbox next to it.
Click "find".
"Find in path" on the project folder will do the work.

How to get eclipse to go to the ONLY implementation of an interface's method?

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.

How to quickly navigate between Java class method definitions in a large class without the 'Find' dialog in Eclipse?

I use what I think is a typical layout in Eclipse: my workspace contains the Project Explorer on the left and the Java editor window taking up most of the screen, with the small console window at the foot of this editor pane.
When I open a very long Java class, containing a large number of method definitions, in the editor pane, it can take a long time to move between methods. I use CTRL-F to open the Find dialog and then type in the name of the method if I can remember it.
Is there a better way to navigate between method definitions in a large class in Eclipse?
Ctrl+O will open a dialog with the methods (and variables) list. It supports "advanced" :-) searching so you can just type a few letters of the method's name
Use the Outline View.
I use a layout much like yours but I keep the Outline panel open in it beneath the project/package explorer. This makes it easy to see the project's outline as well as the current editor's outline at a glance.
In addition to the Ctrl+O option for a quick outline, one can type (on a Mac) Cmd-Alt-Q then O to focus the Outline view. Once focus is in the Outline view, you can use the arrow keys or letter keys to navigate through the list of methods.
Cmd-Alt-Q is useful for opening many of the views. In my Eclipse Helios right now, a momentary delay after playing the chord presents a quick list of many different views, many of which have their own hot key.
Finally, you can use the "Next/Previous member" chord to jump to the previous or next method definition in the file. Again in my Helios build, the Next member key is Ctrl-Alt-down . Yours may be different.
To find out what the keystrokes are in your Eclipse build, open the eclipse preferences. Use the searcher to search for 'keys'. Open the configuration for Keys . Then in the keys search bar look for "member". There should be an item for "Next member" with a bound shortcut key/chord. Browsing the list of hotkeys is a great way to improve Eclipse productivity in the long run ;)

How do I add components at run time to a Swing UI created with Netbeans visual editor?

I am currently writing an application where the user has, at some point, to click a button which have been generated at run time. I know how to do it when writing all my swing code from scratch, but I'd like to take advantage of Netbeans' visual editor.
The generated UI code goes into an initComponents() method I can't modify since it is regenerated automatically from the visual form.
I'd like to have a panel I place at design time using the visual editor in which I could add the buttons at run time so that they fit nicely in the layout, but I don't know how to access the panel in a convenient way. Besides, there may be another method than using a panel.
So basically :
How do I locate a Swing component at run time ?
Is there a better way of integrating components created at run time in a generated Swing UI ?
Thanks for your help.
NetBeans-generated GUI classes store all the components in private variables. You can add a method into the generated class that returns the panel, and it will remain even as you do additional design.
If you're going to use a generated UI, then it's probably best to use a JPanel within that UI to "carve out" space for your own components. Otherwise, you'll have to worry about how your components affect the layout of the components placed by the UI.
Just because you are using NetBeans generated GUI classes doesn't mean that you have to use the Group layout for the panels. I find that switching it to a BorderLayout helps especially in cases where I want to add some dynamic user interface code.
It is possible to change private to protected/public by either right clicking on a component in the GUI-Designer, choosing properties and hitting the Source-tab or right clicking on a component and choosing "Modify Source" (or something like that) and setting the appropriate access modifier.
Or just export them via a getXYZComponent() method.
Locating the component should provide as being too difficult, as you built it with the designer and thus know each component.
For example, if you had a JTabbedPane and wanted to add tabs to it when the user hits a button or something like that, you would simply issue myJTabbedPane.add(myCustomComponent); et voila, a new tab appears.
It is also possible to modify the auto-generated code and/or the code used for auto-generation by using the "Modify source" dialog mentioned above, which can be really useful.

Categories