Upload Java Files Using a Jar in Netbeans
NetBeans Visual Library Tutorial for Java Applications
- Setting Upwards the Application
- Calculation the Libraries
- Creating the Container
- Creating the Widgets
- Enabling the Deportment
Also, you lot volition utilize 3 icons in the tutorial. Y'all can right-click them hither and save them locally, then re-create them to the application's location, after you create the application after in this tutorial. Here are the 3 icons:
Setting Upwards the Application
In this section, nosotros utilize a wizard to create a Coffee awarding.
-
Choose File > New Projection (Ctrl+Shift+N). Under Categories, select Java. Nether Projects, select Java Application. Click Next.
1. In the Proper name and Location panel, type VisLibDemo
in the Project Name field:
Click Finish.
The IDE creates the VisLibDemo
project. Add together the three images above to the main packet. You lot should now see this:
Adding the Libraries
In this section, we add the 2 libraries you need to piece of work with the Visual Library.
-
Right-click the Libraries node and choose "Add JAR/Binder".
-
Browse to the installation directory of NetBeans IDE.
-
In
platform9/lib
, chooseorg-openide-util.jar
.
-
In
platform9/modules
, chooseorg-netbeans-api-visual.jar
.
You lot now have the only two JARs y'all volition need. You should now encounter this:
Creating the Container
In this section, we create the container that will hold the Scene
from the Visual Library.
-
Define
Main.java
as follows:
public class Main extends JPanel { *//Create the JFrame:* public static void chief(String[] args) { JFrame frame = new JFrame("Graph test"); frame.setMinimumSize(new Dimension(500, 400)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(new Main()); frame.pack(); frame.setVisible(true); } public Main() { initComponents(); } individual void initComponents() { *//Set the layout:* setLayout(new BorderLayout()); *//Create a JScrollPane:* JScrollPane scrollPane = new JScrollPane(); *//Add the JScrollPane to the JPanel:* add together(scrollPane, BorderLayout.Heart); } }
-
Run the application and yous should see a simple JFrame:
Now that you have a JScrollPane
, yous're ready to create a scene!
In this section, we create a separate grade containing our scene. We then hook information technology into our JPanel
.
-
Create a new grade called
GraphSceneImpl.java
.
-
Permit information technology extend GraphScene<Cord, String>.
-
Use the lightbulb at the side of the IDE to add together import statements and abstract methods. You should now run across this:
bundle vislibdemo; import org.netbeans.api.visual.graph.GraphScene; import org.netbeans.api.visual.widget.Widget; public course GraphSceneImpl extends GraphScene<String, String> { @Override protected Widget attachNodeWidget(String arg0) { throw new UnsupportedOperationException("Not supported yet."); } @Override protected Widget attachEdgeWidget(String arg0) { throw new UnsupportedOperationException("Not supported yet."); } @Override protected void attachEdgeSourceAnchor(String arg0, String arg1, String arg2) { throw new UnsupportedOperationException("Not supported yet."); } @Override protected void attachEdgeTargetAnchor(String arg0, String arg1, String arg2) { throw new UnsupportedOperationException("Not supported yet."); } }
-
We'll be using iii
LayerWidgets
, which are likeJGlassPanes
in Swing. Declare them at the top of the form:
private LayerWidget mainLayer; private LayerWidget connectionLayer; individual LayerWidget interactionLayer;
-
Create a constructor, initialize your
LayerWidgets
and add them to theScene
:
public GraphSceneImpl() { mainLayer = new LayerWidget(this); connectionLayer = new LayerWidget(this); interactionLayer = new LayerWidget(this); addChild(mainLayer); addChild(connectionLayer); addChild(interactionLayer); }
-
Next, define what will happen when a new Widget is created:
@Override protected Widget attachNodeWidget(String arg) { IconNodeWidget widget = new IconNodeWidget(this); if (arg.startsWith("one")) { widget.setImage(ImageUtilities.loadImage("vislibdemo/red.gif")); } else if (arg.startsWith("2")) { widget.setImage(ImageUtilities.loadImage("vislibdemo/green.gif")); } else { widget.setImage(ImageUtilities.loadImage("vislibdemo/blueish.gif")); } widget.setLabel(arg); mainLayer.addChild(widget); return widget; }
The above is triggered whenever addNode
is called on the scene.
-
At the end of the constructor, trigger the method to a higher place 4 times:
Widget w1 = addNode("i. Hammer"); w1.setPreferredLocation(new Point(10, 100)); Widget w2 = addNode("2. Saw"); w2.setPreferredLocation(new Point(100, 250)); Widget w3 = addNode("Boom"); w3.setPreferredLocation(new Indicate(250, 250)); Widget w4 = addNode("Commodities"); w4.setPreferredLocation(new Point(250, 350));
Above, you accept created 4 widgets, you lot take passed in a cord, and you have set the widget's position. Now, the attachNodeWidget
method is triggered, which you defined in the previous step. The arg
parameter in the attachNodeWidget
is the cord you lot passed to addNode
. Therefore, the cord will set the label of the widget. Then the widget is added to the mainLayer
.
-
Dorsum in the
Primary.java
class, add the lines in bold to theinitComponents
method:
private void initComponents() { //Prepare the layout: setLayout(new BorderLayout()); //Create a JScrollPane: JScrollPane scrollPane = new JScrollPane(); //Add the JScrollPane to the JPanel: add(scrollPane, BorderLayout.Eye); *//Create the GraphSceneImpl: GraphScene scene = new GraphSceneImpl(); //Add it to the JScrollPane: scrollPane.setViewportView(scene.createView()); //Add the SatellitView to the scene: add(scene.createSatelliteView(), BorderLayout.WEST);* }
-
Run the application and you should see this:
Now that you have a scene with some widgets, we can begin integrating some actions!
Enabling the Actions
In this section, we enable actions on the widgets we created previously.
-
Alter the
attachNodeWidget
by adding the lines in bold beneath:
@Override protected Widget attachNodeWidget(String arg) { IconNodeWidget widget = new IconNodeWidget(this); if (arg.startsWith("1")) { widget.setImage(ImageUtilities.loadImage("vislibdemo/blood-red.gif")); } else if (arg.startsWith("2")) { widget.setImage(ImageUtilities.loadImage("vislibdemo/green.gif")); } else { widget.setImage(ImageUtilities.loadImage("vislibdemo/blue.gif")); } *widget.getActions().addAction( ActionFactory.createAlignWithMoveAction( mainLayer, interactionLayer, ActionFactory.createDefaultAlignWithMoveDecorator()));* widget.setLabel(arg); mainLayer.addChild(widget); return widget; }
-
Run the application. Drag a widget around and notice that alignment markers announced that help the user position a widget in relation to other widgets.
-
Change the
GraphSceneImpl
class by adding the line below to the stop of the constructor:
getActions().addAction(ActionFactory.createZoomAction());
-
Run the application. Scroll the centre mousebutton, or do whatever your operating system requires for "zooming", and detect that the whole scene increases/decreases in size.
Now that you have a basic idea of the features that the Visual Library API provides, run across the section called "NetBeans APIs for Visualizing Data" on the NetBeans Platform Learning Trail.
Source: https://netbeans.apache.org/tutorials/nbm-visual_library3.html
0 Response to "Upload Java Files Using a Jar in Netbeans"
Post a Comment