I don't really understand how to integrate jfd and intellij.
So far I have played around with it a little bit and developed a program that looks .
I then generated an actionEventHandler to handle when the add package button is pressed. For now I just kept it simple and had it output "THIS IS A TEST" into the outputField which is the textField in the picture above.
the actionEventHandler looks like this:
private void addPackageButtonActionPerformed(ActionEvent e) {
outputArea.setText("THIS IS A TEST");
}
I would then expect when I did "Test Form" on the jfd tab I would click the addPackageButton and it would put "THIS IS A TEST" into the outputField.
However, nothing happens. Is this what "Test Form" is for? Or is there another way that I can run my form and test it that I am not seeing? Or is this functionality only available in netbeans?
I figured out how to do this so I will post this for posterity.
Jfd doesn't add a main to your project by default so adding this:
public static void main(String[] args){
GUIClassName window = new GUIClassName();
window.setVisible(true);
}
will allow you to run the module and see the window.
Related
I am using Eclipse Luna and i am trying to run a simple text program but Eclipse gives the error:
Error: Could not find or load main class Main
I have no idea what's going on. I haven't found anything useful on Stack Overflow or Google. Here is my code:
public class Main {
public static void main(String[] args) {
System.out.println("This is a String");
}
}
Thank you.
Your code looking fine !
Do following steps to run your class
Select your project, go to Project section in menu bar then click clean.
In tool section click on enter code here Build Automatically.
Select your class right click on it and then select run.
In the menu Run, select Run Configurations....
In the dialog box that opens, on the left side, you are supposed to have an entry Java Application, and under it, there should be your class (and maybe other classes you worked on before). It may be named Main or Main__ here.
Select it. If it was erroneously named Main__, change that to Main in the Name: field.
Now look at the entry for Main Class. In the text field, it should say Main. If it says Main__ or anything else, change that to Main.
Apply and Run.
Sometimes you would like to run a single file to test some code quickly. Typing in public static void main(String[] args) { each time is tedious. How to do it quicker?
Thanks to predefined code templates in Netbeans it's simple:
just type psvm and press Tab.
psvm is an acronym for: public static void main
"psvm" is not the most intuitive abbreviation I can think of when I want to quickly insert a main method, so I created a new one more to my liking in the Code Templates library.
"main" seemed to be more natural for me, and since there's nothing else like it in the list of templates, I used it as an abbreviation and copied the same code from "psvm" in.
Now when I type "main" + TAB (without the quotes of course) I get my main method.
It is redundant, but more intuitive for me.
To create "main" go to Tools->Options, click the "Editor" Icon, then the "Code Templates" tab.
Make sure that the "Language" combo is set to "Java"
Click the "New" button that's to the right of the "Templates" window
Enter "main" (without quotes) in the "Abbreviation" textbox that pops up
Enter the template code in the "Expanded Text" window below
my entry looks like this:
Abbreviation
main
Expanded Text
public static void main(String[] args) {$cursor}
Expanded Text (Code Window)
public static void main(String[] args) {
${cursor}
}
Of course, you can always have Netbeans create your application's main class with the main method inserted by default.
You do that by Choosing "Java Main Class" from the "New File" dialog instead of "Java Class". That will do it.
Cheers!
If you want to just run some test why not use your testing framework?
like JUnit:
#Test
public void test() {
// do something
}
This way you can even store the test for later usage.
It is properbly in most cases not a good idear to think of tests as something to execute once and then throw away.
I have developed a basic desktop-app using Netbeans IDE, on the app I have a button called Ok. Now I have created another project, its a CRUD-app. Is there a way to make the ok-button in my 1st project to run the CRUD-app in another project- or how do I link tha ok-button to open/run the crud-app? In a different project..Project names are pro1 and CruD-test-
Below is a sample-code for my button:
OK.addActionListener(new ActionListener(){
//please add a link to the CRUD-app contained in project Crud-test
#Max: I wanna run pro1 on the IDE and run the CruD-test as jar...how do I link mu OK-button to the CruD-test?
Basically it is going to be code as :
OK.addActionListener(new ActionListener(){
MyCRUDApplication crudApp = new MyCRUDApplication(); //This is only an example, keep a gloabal reference as needed
//assuming MyCRUDApplication constructor would create and show its main window.
//Otherwise you will have to provide the relevant class that really shows the project.
}
For this, you should add MyCRUDApplication application as a referenced project in Netbeans. It is explained here
I have created a new DesktopApplication in Netbeans. When I start it, it shows the gui directly on the screen. How to hide it after startup?
Something like this:
DesktopApplication1.getApplication().getMainFrame().setVisible(false);
after the initComponents(); method doesn't work.
Is there a way to hide this window after starting up? (I only want to show it after clicking the tray-Icon of this application. Not after startup.)
Thanks.
This problem is reproduceable when you create a new DesktopApplication in Netbeans. I haven't changed the code (only added the line mentioned above.)
If you look at the source code for DesktopApplication1App, it says something like
//DesktopApplication1App.java
#Action public void startup(){
show(new DesktopApplication1View(this));
}
To fix this, just comment out the show() call, and replacing it with a dummy. For example:
//DesktopApplication1App.java
#Action public void startup(){
Object o = new DesktopApplication1View(this);
}
Later, if you want to set it to be visible, you can call this:
//DesktopApplication1View.java
DesktopApplication1App.getApplication().show(this);
// ----- OR -----
this.getFrame().setVisible(true);
whichever works for you.
I am trying to create my first GUI application using (Java + Eclipse + Swing). This is my code:
import java.awt.*;
import javax.swing.*;
public class HelloWorldSwing extends JFrame {
JTextArea m_resultArea = new JTextArea(6, 30);
//====================================================== constructor
public HelloWorldSwing() {
//... Set initial text, scrolling, and border.
m_resultArea.setText("Enter more text to see scrollbars");
JScrollPane scrollingArea = new JScrollPane(m_resultArea);
scrollingArea.setBorder(BorderFactory.createEmptyBorder(10,5,10,5));
// Get the content pane, set layout, add to center
Container content = this.getContentPane();
content.setLayout(new BorderLayout());
content.add(scrollingArea, BorderLayout.CENTER);
this.pack();
}
//============================================================= main
public static void main(String[] args) {
JFrame win = new HelloWorldSwing();
win.setTitle("TextAreaDemo");
win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
win.setVisible(true);
}
}
The code was taken from here.
When I run the application from Eclipse the expected window appears (So, it's good. I see what I want to see). However, when I try to close the window or try to write something in the text area the program freezes. The OS writes me that program is not responding (I try it on Ubuntu).
Can anybody help me to find the reason of the problem?
Thank you in advance for any help.
I'm sure this doesn't have to do with the code, as others have found the code runs just fine on their machines - which points to a machine specific issue. From within Eclipse, make sure it is setup to use the expected JDK/JRE. However, before worrying about how Eclipse is handling your situation, I'd run things by hand first - especially since you've got a very simple class.
I would check to ensure that you're using the expected compiler and runtime. On Linux:
which javac
which java
If they're both what you expect, do the following:
javac HelloWorldSwing.java
java HelloWorldSwing
If you get a similar problem, then you know it's not the Eclipse configuration and it's something else. If you're not using the latest JDK, upgrade to the latest. If you're already at the latest, it could be a display driver. Do other JAVA swing programs work on this computer? I'm sure you could find some on the net, download an app already packaged as a jar and try running it.
did you try using the eventdispatcherthread to view the JFrame?
something like:
public static void main(String[] args){
SwingUtilities.invokeLater(new Runnable(){
public void run(){
createAndViewJFrame();
}
});
}
public void createAndViewJFrame(){
JFrame win = new HelloWorldSwing();
win.setTitle("TextAreaDemo");
win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
win.setVisible(true);
}
then your frame would be shown by the swing dispatcher thread.
hope it helped, although im just guessing...
Update: as commenters pointed you i f**ed up the invokeLater() call. I just edited this post to correct that. Thanx go to yishai & willcodejavaforfood for pointing it out!
frank
You need to catch the exit event and
respond with a System.exit( 0 );
You should be able to find that in
most swing examples online.
wrong stuff... sorry... coffee... argh....