Whats the use of initComponents(); in java constructor? - constructor

When I create JFrame everytime I see initComponents(); in my constructor. What is it? If I remove it what is going to happen?

initcomponents() is a method that NetBeans (I guess you are using it) swing Designer creates to initialise components (set default values etc.). It doesn't really have anything to do with the JFrame class.
You can call the method whenever you like (constructor, other method). For Java, it is just like any other method. The NetBeans IDE, however, calls it inside the constructor to control the parameters you have passed via your GUI editor of Netbeans. It is by default private.
You can think of it as the connection between the GUI Editor and Java. So if you remove it, probably you will not be able to use the functionality that NetBeans provides to work with components (which can still be ok).

To add to Artem's answer above:
Invariably, the initcomponents() initializes all of the Java swing components objects that your front-end GUI uses using the NetBeans GUI Builder.
These swing components are automatically generated in your Java class whenever you make changes to the design of your GUI using the GUI builder.
As a general rule of thumb, you should never change any aspect of the code within this method as this method is inextricably linked to the front-end NetBeans GUI builder. The image below outlines the NetBeans GUI design builder. A user can quickly jump between the design front-end by clicking on the DESIGN button and also the source by clicking on the SOURCE button respectively
By clicking on the source button (outlined below), you will see the auto generated initcomponents() containing all of the swing components
the following link provides very good quick start guide to the essentials of NetBeans GUI builder: Designing a Swing GUI in NetBeans

Related

How do I create a Processing library that adds a new function to the language?

I want to create a Processing library that adds a single function to Processing. A single command. How do I do this?
So I want to be able to write on Processing this:
void setup() {
drawMyCustomShape()
}
In a way that drawMyCustomShape will be on my custom library implementation.
Thanks!
Note: this question is not about creating a new library in processing. Is about creating a library that exports one new command (so you can using without caring of the container class instance).
First of all, are you sure you really need to create an entire library? You could just add that class to your sketch without needing to deploy it as a library. If you're worried about clutter, just put it in its own tab.
If you really need to create a library, then there are three tutorials that you need to read:
Library Overview
Library Basics
Library Guidelines
But basically, you need to create a Java project (in an IDE like eclipse, or with a basic text editor and the command line) that uses Processing as a library. That's where you'd put your MyLibrary class. You'd then export it as a .jar file, and then import that .jar file into Processing. You would then be able to use your class exactly like you can use any other Processing library.
Your proposed setup has some other issues (how are you going to access the sketch variable from the static function?), but I'd suggest treating them as separate questions after you get the basics in place.
It sounds like you are actually looking to create your own extension of the Processing library, as in actually change the core jar file.
You can extend the actual Processing library by forking off of its main branch on Github. By writing your function drawMyCustomShape into the actual core in the forked version, you can then build the Processing Development Environment from your copy of the code. Using that particular copy of the PDE, you could do what you're describing.
Once you compile this build, you could actually distribute this copy of the PDE to your college students. They would be able to use your function as if nothing were changed. (I'm guessing that this is for an intro-level class at the college level, so that's why you would have to hide implementation from your students?)
Here's some links to get you started:
Processing github
Instructions for building the PDE from source
So, finally I found the most adequate answer for my case.
The solution for this is to implement a new Processing Mode that extends the builtin Java Mode. To include static members to the main processing program you will need to add a new static import to the ones that processing adds to your code.
You can do this by forking the Mode Template for 3.0 that #joelmoniz created from #martinleopold:
https://github.com/joelmoniz/TemplateMode/tree/3.0-compatibility
There is a good tutorial here:
http://pvcresin.hatenablog.com/entry/2016/03/17/210135
Why is the most adequate solution? : I think this is the best way to achieve new static methods in processing code and ensure an easy distribution! You just have to set the mode folder in your sketchbook/modes folder. If I were to fork processing it would be a big deal to prepare distributions for all operative systems and also to keep update with main project.
My particular solution:
To add my static imports into Processing I implemented a custom mode where I overrode the PdePreprocessor class which wraps the processing code with all the Java procesing code. So, the idea was to add more imports to the imports that the PdePreprocessor generates on the generated Java source.
In my custom PdePreprocessor I overrode the getCoreImports method to add my custom methods. I did this here because I consider the new imports are part of the core of my custom mode. You could also achieve this by overriding writeImports method.
In order to use my PdePreprocessor implementation I had to overrode the following classes:
Commander
JavaBuild
JavaEditor
JavaMode
JavaEditor
I had to implement a new JavaBuild which preprocesses the Sketch with my custom PdePreprocessor. And also use my custom JavaBuild in all the places where the Processing Java Mode instances the build class. Please share with us if there is a better way to do what I did.
Here is the github for my solution: http://github.com/arypbatista/processing-inpr/

How can I access Gtk# widgets in code in MonoDevelop?

First, I am new to Monodevelop and Gtk# (but have experience with Visual Studio, C# and Winforms).
In Monodevelop I designed a form by dragging widgets onto it. I entered a value for the Name and (the same or a different value) for the MemberName. However I can't access the widgets in code.
In Visual Studio there is a form.Designer.cs which contains the code that creates the controls. What is the equivalent in MonoDevelop? I would like to examine the code so I can learn from it, and to find out how I can access a widget in code.
I am using MonoDevelop 5.5, Mono 3.10.0 on Linux Mint 17.1 64-bit.
(This question has been asked before, but that answer doesn't help me).
The GTK# generated code will be in a .cs file inside a gtk-gui directory inside your project. The .cs file will have a similar name to your widget class name but will have the full namespace of the class as part of its name.
MyWidget.cs
gtk-gui/MyGtkApp.MyWidget.cs
Also you will need to compile your project before the code is generated. The new member names should be available from within the widget's class.

Including projects in other projects in PHPStorm

Say I am working on a couple of PHP projects named Framework and Application, where the latter is using the former. When I dive in the Application's classes, I see some of them extending Framework's classes, for example:
class Application_Controller extends Framework_Controller
When I hover mouse over Framework_Controller and click Ctrl, I want the name to become clickable link upon clicking on which the source code of the Framework_Controller class from the Framework project will be opened.
Currently I have achieved almost the same thing by adding the Framework codebase path to the "Include path" list (having the Application project opened, go to File/Settings/PHP). The Framework codebase tree appears under "External Libraries" in the Project window. So when I click on Framework_Controller as described above the Framework_Controller class file gets opened indeed. However, PHPStorm does not take into consideration that the file actually belongs to another project named Framework — it just opens the file. This has the following disadvantages:
On the top navigation bar, the full path to the file is shown (i.e.
starting from "/") rather than starting from the Framework project
root directory.
If I want to edit the file (and possibly more related files in the Framework codebase), I would have to manually switch to the Framework project window and find the same file in there.
So I am wondering if there is any way I could tell PHPStorm that the Application project uses/includes the Framework project, so that when I click on Framework_Controller as described above, the Framework_Controller class file gets opened in the Framework project window rather than just a file external to the Application project.

I can't go to design mode in NetBeans (jframe)

I am building a GUI using swing Jframe. I am using netbeans, because it has this nice interface that allows you to create your GUI just by clicking. I once saved just the Java file of the Interface. Now I want to use this file again and it works fine, when I just add this file to a package inside a project. But I cant go to the design view anymore, the option is not available.
Does anyone know how to enable the design view?
Looking at it there is no .form file. Any idea how to compile this file?
You can recreate the .form file from the class. Please see here: http://wiki.netbeans.org/FaqFormGeneratingFormFile
If you move / copy your class you also have to copy the form file since it's not recreated.

How to configure FlashDevelop for unit test builds?

I'm using AsUnit for unit-testing my current AS3 project. My Main() is basically:
if ( UnitTest )
runUnitTests();
else
runMainProgram();
where I change UnitTest before building depending on whether I want to run the program or run the unit tests. Is there a way that makes it easier to switch between the two modes?
Optimally, I'd use F5 for building with UnitTest=false and another hotkey for building with UnitTest=false. What is the closest I can get with FlashDevelop?
You can do the following in FlashDevelop
if(CONFIG::debug) {
trace("Debug");
} else if(CONFIG::release) {
trace("Release");
}
These correspond to the drop down in the toolbar next to the play button.
See this link: http://www.flashdevelop.org/wikidocs/index.php?title=AS3_Conditional_Compilation
In terms of the shortcut, just create a macro that switches the release mode then hits play. From there you can add any shortcut you would like to your macro. So one shortcut will launch the course into debug/release mode as required.
Also note, you can have other CONFIG::bla's - so you might want to have CONFIG:unit1, CONFIG:unit2, etc, etc. See above link.
Easy solution:
duplicate the FlashDevelop project file (.as3proj) and name it "MyProject_tests.as3proj",
open this project, create a new ProjectTests class and set it as the main class,
change the output SWF in project settings.
Add another project file. To run the test using it as the primary. "Document class" the context menu on the file.
Like Chris mentioned, you can use FlashDevelop's Compiler Constants to do what you need, though it is a bit cumbersome turning these constants on and off.
However, there is a FlashDevelop plugin called Config::Toggle that makes that significantly quicker by providing an additional panel where you can enable/disable boolean constants with 1 click. The linked website describes the value of the plugin far better than I ever could. Hope that helps.