Working with two projects- - java

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

Related

Using Jdf and Intellij: Specifically running a Jfd form in intellij

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.

Read external Files with GlassFish / Vaadin?

I would like to make .txt-files accessible for my VaadinApp on a GlassfishServer.
Lets say I have a .txt-file, its content is 12345.
Now, when I click a button on my Vaadin StartPage, I would like to show the Data that has been written into this .txt-file.
I know how Java Input/Output is working but I have no clue how to make those files accessible for my VaadinApplication running on Glassfish 4.1.2.
Is there a folder I can put the .txt-file in, or how would I access the file?
Thanks
There is component named Label is available in Vaadin.
So that, the values which needs to be shown on the screen can be set as a caption/value for that object.
This can be done either through constructor or setter in that object.We will set the value through the setter as we need to display the value, once the button is clicked. That can be done like this.
Label sampleLabel = new Label();
sampleLabel.setContentMode(com.vaadin.shared.ui.ContentMode.HTML);
Now we will see how this can be added to the label, when a button is clicked.
Button sampleButton = new Button("Click");
sampleButton.addClickListener(event -> sampleLabel.setValue(<call the method that reads data from the text file>));
I hope this will be helpful.
Note: Basically you can place the file anywhere in the system.
But most preferred way.
If you are using maven to build the project, place the files in the resource folder.(src/main/resources)

How do I add a java program to a weebly site?

I'm experimenting with Weebly, and I'm currently trying to add an arbitrary swing program to the Weebly editor. I have tried two approaches thus far, as shown here:
1: (Note: - replaces < and >)
-embed height=400 width=400 src="siteName/uploads/someNumbers/testapplet.class"--/embed-
2: (Same substitution as above)
-applet codebase="siteName/uploads/someNumbers" code="testapplet.ckass" width=400 height=400--/applet-
Upon publishing and viewing the page, the first one says I need a plugin to display the content, and the second one says my security preferences won't let me run java on the site, whereas I can run java pretty much everywhere else just fine.
What should I do to make this work? This could include some of the following:
Modifying my program (i.e. the java code itself)
Modifying how I upload the program (i.e. .class vs .jar)
Modifying how I display the program (i.e. the actual -applet- or -embed-)
For reference, here is the java code- just a basic JButton and JLabel, with the JLabel's value increasing upon each click of the button:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class TestApplet extends JApplet
{
static int x = 0;
static JLabel l = new JLabel(x+"");
public void init()
{
setLayout(new FlowLayout());
JButton b = new JButton("Button");
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
x++;
l.setText(x+"");
}
});
add(b);
add(l);
}
}
Sign in to weebly and click on the edit button next to your site name
On the "Elements" tab on the top, go to "Multimedia" and drag a file element onto your page.
Follow directions to upload your .class file. Name should be lowercase.
Hit the publish button and go to your published page.
Remember your .class file? Right-click on it and copy the link address or link location.
Go back to editing your weebly page.
On the "Elements" tab, go down to "More" and drag in the "Custom HTML" element.
Click to edit the custom HTML element- this is where we are going to put our applet code.
If my link location to my .class file was http://www.johndoe.com/uploads/3/3/2/6/3326331/countme.class, my applet code would read:
<applet codebase="http://www.johndoe.com/uploads/3/3/2/6/3326331" code="countme.class" width=something height=something></applet>
The idea is that the codebase tells the browser where to look for a .class file and the code itself tells it whick .class it is.
10. Publish again, and your applet should appear.
I haven't tried it personally, but I had a chat with a support support staff and they affirmed this method.
All the best!

Eclipse Java Error: Cannot find or load main class

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.

JFrames/Objects access between two different projects

I have two separate projects, A and B, added the jar file of B in A's Libraries using netbeans. A has two JFrame (BasicFrame1 and BasicFrame2) and B has JFrame (Newframe). When i tries to make visible BsicFrame2 and unvisible BasicFrame1 it all works coz they are in the same project. But whenever i tries to make visible the project B's JFrame (Newframe) by clicking on the button in Project A's BasicFrame1 it does not show anything.
Newframe connenct=new Newframe();
this.BasicFrame1.setVisible(false);
Newframe.setVisible(true);
Please help me, why this not working and the same case when i try to access the Newframe's jPanel (butPanel).
Newframe connect=new Newframe();
connect.butPanel.setVisible(true);
This code also does not works but when i do this between the project A's Frames it works. What's the mistake i have done? Please help.

Categories