After installing development environment (IDE) The Eclipse and create a new project, we added a program to the Eclipse project.
The next step is to begin to structure the application initiating the construction of the graphical library items.
The first tool we will develop will be responsible for storage and display of graphic objects. A panel on which elements are drawn: “Blackboard”.
This object is stored in a file that will reside on the graphics library. A library elements are grouped into what are called “packages” (Package):
When you create a file you can specify, and the name of the same, name “package” where to live. If the package does not exist, wizard will create files. Physically is a directory that will be adding new files. In our case we will call “graph”, WHILE file that we will call “Blackboard” (slate).
In reviewing the project structure will see changes. Appears again “package” along with the file we created.
Extend class file “Canvas”, namely, take the properties of this JAVA class that allows drawing on a surface. For now we will include a unique function to draw a line, and to check that everything is working properly at the structural level. Then develop the functionality we need to provide this kind of high-level graphics capabilities..
Modify the main program to incorporate graphics library element we just created.
We need a handle to incorporate the element “Blackboard”. In the same line of code declare the identifier (slate) and begin assigning a new object (Blackboard)
Blacboard pizarra = new Blackboard();
Add the item to the applet, but first we define as placed on the screen. Los “Layouts” are required for the distribution of the components on the application window.
this.setLayout(new GridLayout()); this.add(slate);
These operations are performed in the constructor of the main class, which is the function that has the same name as the file JAVA.
When you run the main program (Example1) we can do as “Applet” in a browser page or as a standalone. In the first case run this function or class constructor, while the second function is executed “main” as we saw at add a program to the Eclipse project.
By this we ensure that it runs the constructor if we start the application from the function “main”. First we create an identifier of the object and begin with the operator “new”:
Example1 app=new Example1();
Then create a window for the application, a “frame” adequate size. If we run the program in a browser it will serve as a window.
Frame frame=new Frame(); frame.setSize(640,480);
If you press the close button “frame”, we stop the application, We will do this by adding a process or “listener” the same, to be executed by pressing the close icon:
frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent arg0) { System.exit(0); } });
Finally add the application to “frame” and we will visible.
frame.add(app); frame.setVisible(true);
Run the application as an applet
We use an emulator to see how the application would run in a browser. We saw that with the menu or the alphanumeric graphic could define a run configuration:
Run->Run As ->Java Applet
We can change this setting by selecting Run:
Run->Run Configurations…
This menu will offer a tabbed window where you can set various parameters in the implementation of the program, as the size of the window, the file to be executed to start the same, virtual machine parameters JAVA etc..
We can change the name if we define settings for testing several different. The name should remind us what is special about this configuration.
The parameter that is specifically want to modify the size of the browser window simulator. This size will be defined later as HTML code to insert the applet on a web page.
Although apparently the program does nothing new, we have come in the way of structuring the code starting to specialize the elements of the. For the time te of the files JAVA, the first starts the application while the second is going to be responsible to paint the objects. The next step is to start defining our graphic objects.
Must be connected to post a comment.