Difference between revisions of "Java"

From Sinfronteras
Jump to: navigation, search
m (Adelo Vieira trasladó la página GUI Programming a Java)
(Tag: New redirect)
 
(310 intermediate revisions by the same user not shown)
Line 1: Line 1:
'''GUI''' stands for Graphical User Interface.
+
#REDIRECT [[Object-Oriented Concepts and Constructs]]
 
 
'''Swing:'''
 
 
 
It's a '''GUI widget toolkit''' for '''Java'''. It is part of Oracle's Java Foundation Classes (JFC) – an API (Application programming interface) for providing a graphical user interface '''(GUI)''' for '''Java''' programs. '''Swing''' is  currently the main user interface package which is used for creating desktop applications.
 
 
 
'''AWT (Abstract Window toolkit):'''
 
 
 
It's the user-interface widget toolkit preceding '''Swing'''. The AWT is part of the Java Foundation Classes (JFC) — the standard API for providing a graphical user interface (GUI) for a Java program. Some elements of this are still used.
 
 
 
* '''On the Oracle website you can find a wealth of examples covering everything you will ever need to do using a Swing interface.'''
 
* '''You can find full tutorials and also API documentation for each component.'''
 
* '''The Oracle website contains so many examples, it really is worth taking the time to have a look through the website to get a feel for what can be done.'''
 
 
 
 
 
==Instalación de Java==
 
https://www.digitalocean.com/community/tutorials/how-to-install-java-with-apt-get-on-ubuntu-16-04
 
 
 
==Instalación de Eclipse==
 
Para estar seguro de que estamos instalando la última versión, es apropiado descargar el paquete desde la página oficial, y no instalar la versión que se encuentra en los repositorios de Ubuntu a través de apt-get (pues estar versiones generalmente están desactualizadas).
 
 
 
Página oficial de Eclipse: http://www.eclipse.org/downloads/
 
 
 
En la siguiente página se explica como instalar eclipse en Ubuntu 16.04:
 
http://ubuntuhandbook.org/index.php/2016/01/how-to-install-the-latest-eclipse-in-ubuntu-16-04-15-10/
 
 
 
Para instalarlo hay que simplemente ejecutar el instalador y seguir las instrucciones (como si se tratara de una instalación en Windows).
 
 
 
Luego, para agregar el ejecutable a la lista de comandos, he agregado la siguiente línea en el .bashrc:
 
PATH=$PATH:/home/adelo/.archivos_programas-ubuntu/eclipse/eclipse:
 
 
 
==Introduction to Swing components==
 
 
 
The '''JFrame''' can be considered to be base to which every other component is added.
 
 
 
Therefore if we wanted to create a simple interface with a text field and a button we would first need to create a '''JFrame''' to hold everything and then we would add the '''JTextField''' and the '''JButton''' to the '''JFrame'''.
 
 
 
Some of the components are:
 
* JFrame
 
* JButton
 
* JTextField
 
* JTextArea
 
* JCheckBox
 
* JComboBox
 
* JList
 
* JRadioButon
 
* JTable
 
* JTree
 
* JLabel
 
* JDialog
 
* List of Swing components and how to use them: http://docs.oracle.com/javase/tutorial/uiswing/components/componentlist.html
 
 
 
==Events==
 
How do we make things happen?
 
 
 
* In graphical user interfaces things happen and change because of events.
 
* During this example we will create a '''button click event''' which means a message will be sent internally to say that a specific button has been clicked.
 
* For our simple example, we want some text to be printed out to the console once a button has been clicked.
 
* In order for this to happen, we need create an '''event generator''' and register a '''listener''' for the button in question.
 
 
 
==Listeners==
 
How do we make things happen?
 
 
 
* Listeners are used to allow our program to "listen" for certain events in our program, e.g. when a button has been clicked.
 
* The job of the listener is to wait for an event to happen, and once it has happened, to cause an event to happen.
 
* For our example, we said that when a button is clicked an event will be "triggered". We will need to '''register a listener''' to wait and listen for this '''event to happen''' and then it will do what we tell it to do!
 
 
 
==Making a Jar File==
 
When developing an application we often need a method to package our software to give it to the users of our software.
 
 
 
A typical extension to files that we have always seen when working in a Windows environment is the .exe file extension. These files are a single binary executable file that when double clicked will open the program for the user.
 
 
 
In the Java world however things are a little different. There is no native .exe file in Java and we must use the .jar file extension instead. A jar file works exactly the same as a .exe file and when double clicked will run the program.
 
 
 
'''Jar files come in two different varieties:'''
 
* Simple archive folder
 
* Runnable archive folder
 
 
 
A jar file is an acronym for the title Java Archive, which is a filetype similar to that of the .zip extension. If we want, we can open up a jar file using a program such as WinZip or WinRar and check the contents inside of the jar.
 
 
 
The second variant of this is the ​runnable archive folder​. This type of file is exactly the same as the archive folder, just with one additional file. This extra file is used to define what happens when the user double clicks on the icon. In our case, we will point to the main method in our class file that we want to run. This will qick start the program to run when it is double clicked.
 

Latest revision as of 21:06, 23 January 2020