Programming I Packets and JAR 11th lecture
© Branko Kavšek, Jernej Vičič Packets What are packets and how do we use them? http://java.sun.com/docs/books/tutorial/java/package/index.html The JAR tool http://java.sun.com/docs/books/tutorial/deployment/jar/index.html 11th lecture Programming I © Branko Kavšek, Jernej Vičič
© Branko Kavšek, Jernej Vičič Overview Basic libraries Packets JAR Swing JavaDoc 11th lecture Programming I © Branko Kavšek, Jernej Vičič
Basic libraries JavaTM SE 6 Platform Java Platform, Standard Edition 6 JDK. Version 6
Paketi paketi (packages) so knjižnice Java objektov. v program jih lahko uvozimo z besedo import. Java API vsebuje veliko različnih paketov, lahko pa pakete naredimo tudi sami. Paket je tesno povezan z imenikom datotečnega sistema Vsi javni razredi, ki so v nekem imeniku se lahko med sabo kličejo.
Packets All public classes that are in a directory can call each other. Package behaves as a directory, all the classes of a package are friends (you can call another method, modify / read properties). We must store all classes in the same directory at design time. Packages can be placed in a Java JAR archive.
Packts - example import java.lang.Math; // sedaj lahko uporabljamo metodi iz Math public class Bla { public static void main(String argv[]) { double x=5; System.out.println(Math.sin(x)); // kličemo Math.sin(3.14); }
Packets package PrviPaket; public class Razred{ public static void main(String args[]){ System.out.println("Dober dan!"); } } // Razred
Packets Content of the example must be saved in the file Razred.java, which is located in the directory PrviPaket. Compile file Razred.java as an ordinary Java program. The implementation is slightly different: java PrviPaket/Razred
Pakets - JAR Jar is Java Archive. It is a file format based on the zip and is used to combine multiple files into one. It is primarily designed to facilitate and speed up the handling of java projects. It handles (in addition to Class files) also images similar rubbish.
Packets - JAR Make a jar archive: jar cvf pp.jar PrviPaket/ Start a class in an archive (add to classpath): java -classpath pp.jar PrviPaket/Razred Executable jar files: Open a nerw jar file. Find file MANIFEST.MF Add the line: Main-Class: PrviPaket/Razred Make a new archive: jar cvfm pp1.jar c:\temp\MANIFEST.MF PrviPaket/ Start: java -jar pp1.jar
© Branko Kavšek, Jernej Vičič Swing – why, how, who? Sun and allies JFC AWT Java 2D Accessibility Drag and Drop Swing 11th lecture Programming I © Branko Kavšek, Jernej Vičič
© Branko Kavšek, Jernej Vičič Swing usage Analogous to AWT components Add the letter J Additional componnets 11th lecture Programming I © Branko Kavšek, Jernej Vičič
© Branko Kavšek, Jernej Vičič Swing - usage tree = new JTree(); list = new JList(items); button = new JButton("Pritisni"); button.addActionListener(new ButtonListener()); 11th lecture Programming I © Branko Kavšek, Jernej Vičič
Swing – Differences between Swing and AWT All components are written in Java AWT components are only envelope Uniform look on all platforms Look up Greater control over the components Pluggable Look and Feel Slow and greedy 11th lecture Programming I © Branko Kavšek, Jernej Vičič
© Branko Kavšek, Jernej Vičič Swing Windows look 11th lecture Programming I © Branko Kavšek, Jernej Vičič
Swing metal (Java) look 11th lecture Programming I © Branko Kavšek, Jernej Vičič
© Branko Kavšek, Jernej Vičič Swing Motif look 11th lecture Programming I © Branko Kavšek, Jernej Vičič
© Branko Kavšek, Jernej Vičič Swing Source code: SwingApplet.html 11th lecture Programming I © Branko Kavšek, Jernej Vičič
© Branko Kavšek, Jernej Vičič JavaDoc Example! 11th lecture Programming I © Branko Kavšek, Jernej Vičič