I am new to Netbeans and trying to piece together my application by using code from different sources. I have a query. In one of my projects there are two different files with green arrows against them - I think the green arrow indicates the presence of a main routine. I want to prioritise which file has the main routine and wanted to know the easiest way to do this. Would this simply be a case of removing the line public static void main(String args[]) in one of my projects - If not how do I do it. I'm using Netbeans 7.4
Every file with a main method will have the "green arrow". Normally, a project should only have one main method, the launching point of the program.
You can't change the green arrow in the context your speaking of, but you can change which class is the launching class (Main Class).
right click your project.
from the context menu select properties
from the dialog choose run on the left.
where it says Main Class select the class you want as the launching point class.
Related
I'm working on a GUI in Window Builder and I want to import some of the objects I have declared on my main. The GUI is in the same package as my main and 5 classes, 1 parent and 4 child classes. Is this possible to do? As of right now, I'm trying to call my characters for the game I created into the GUI to be displayed when a certain button is pushed.
So far, I tried importing each class into my GUI. That didn't work went into my main and added my GUI by declaring it as a new object followed up by adding EventQueue.invokeLater and making that visible, but that didn't really work. Any thoughts on how to do something like this?
On Window builder Palette, click choose component and search for your class for example
package.class. This is the image Refer to this.
As the University project, I have to make a simple program in Java and I am currently using the latest version of Netbeans IDE 8.0.2.
I know that main class is where our program will begin and when I am creating classes, I make a mistake but I do not know where..
My program mainly consists of 3 classes and User interface.
ATM - ATMCard - Account
my questions,
ATM should the main class and the GUI. How can I create such class in Netbeans? I mean, as the options, there are Java Main class or other forms.
Should GUI be separated from main class ? I mean, in total, should there be 4 classes (GUI - ATM - ATMCard - Account)
I can guess that these are very simple questions but it is important since I will build all the program on the structure, which is shaped by your answers..
Thank you in advance..
In netbeans i normaly create new Java project.
(File -> New project -> Java -> Java Application)
And select the project's name. There is an option where you can selec option create main class.
Next i normaly create two packages. For instance in your case it could be:
atm.gui (for gui) package and atm.bl package (for buisness logic).
Then select gui package and left click on it, select new JFrame form (AtmForm or something).
And in jour main class just call:
AtmForm form = new AtmForm();
form.setVisible(true);
So the structure should look like this:
Suppose I was making a game and within the render method which cycles hundreds of times per second I have two lines of code e.g.
Sprite sprite = new Sprite (...);
screen.renderSprite(...);
Which creates an object and renders it onto the screen so it shows. But suppose it didn't show; it would be natural to assume that if there is no error then it just wasn't called.
So in Eclipse how I can check if these two lines of code have been called in line x? If you tell me to use breakpoints tell me step by step because I feel that would only obfuscate the render method. (?) I want to check if the object has been created and utilized.
If you need more information don't hesitate to ask.
11. Sprite sprite = new Sprite (...);
12. screen.renderSprite(...);
Right click on line 12 (in my example but will be different in your code.)
Click on Toggle breakpoint
Click Run > Debug As an then either selct Java Application or an existing launch configuration
Once the code starts and enters screen.renderSprite, the program will halt and you'll be able to check it.
First of all you will have to identify some lines in your code at which you know that your sprite wasn't rendered (maybe a state flag?).
From that you have two options:
If you maintain the source code of method #renderSprite(...) you should consider using a logger (like apache logging which should be already included as a plugin of your Eclipse IDE). Thus your application wouldn't obfuscate your rendering processes.
The other option would be debugging: Set up a breakpoint (double-click left of said lines) and run your application in debug mode. You can also set conditions for the breakpoint to stop only in certain cases. Therefor you'll have to right-click a breakpoint and choose "Breakpoint Properties..." and check the "conditional"-box. In the textfield below you can define your condition in Java (you'll have access to all variables just like in your Editor). For more information see the debug help page of Eclipse or Lars Vogel's tutorial on debugging. By debugging your rendering would be paused, but it should be easier for you to find the concrete source of your problem.
A line with a breakpoint set, whose bytecode has been executed, will have a little checkmark on the breakpoint image.
I'm trying to make a hello world form in Intellij. I've created the form, but the question now is what code to make in main() to make the form run and show up?
PS: all the tutorials around seem to only focus on "how to do forms on intellij" not in "how to actually make it run, then".
Thanks
Go to the class with the same name as the form.
Press the keyboard shortcut for "Generate". It's Ctrl+N on Mac OS X, Alt+Ins on Windows. Alternatively, from the menu, select menu Code → Generate.
Select "Form main()".
Now the main method is written and inserted for you. It will look something like this:
public static void main(String[] args) {
JFrame frame = new JFrame("MyForm");
frame.setContentPane(new MyForm().mainPanel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
I just did my first Intellij Swing App.
Steve McLeod has the right instructions, however, when I tried to generate the main method using Alt+Insert => Generate main, I received an error message about one of my panels not being bound. So I clicked on the gui designer page (.form), selected my top panel, and gave it a name.
Everything else was named for me, but for some reason, the panel name was blank. Once I did that, I was able to switch over to the form .java class, press "Alt+Insert" and generate a constructor (not required, but needed).
From there, I followed Steve's advice to generate a main method. One thing that threw me off was the expectation that my Intellij generated .java class would extend or implement something swing related - it didn't. Swing only shows up in the Intellij generated main method (besides the private variables).
Check this tut while it is realy step-by-step:
JetBrains JavaFX HelloWorld
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 ;)