Presentation is loading. Please wait.

Presentation is loading. Please wait.

Intro to Java 2 By Geb Thomas Based on the Java TutorialJava Tutorial.

Similar presentations


Presentation on theme: "Intro to Java 2 By Geb Thomas Based on the Java TutorialJava Tutorial."— Presentation transcript:

1 Intro to Java 2 By Geb Thomas Based on the Java TutorialJava Tutorial

2 What is Java? Platform independent code Runs on many machines Runs within browsers as applets Will soon run on cell phones, microwaves, car displays and washing machines, for example.

3 How do you make Java go? Create a java file (HelloWorldApp.java) Compile the java file with javac to make bytecodes (javac HelloWorldApp.java) Creates HelloWorldApp.class Run the bytecodes on a java virtual machine. (java HelloWorldApp)

4 Where Do You Get This Stuff? http://java.sun.com

5 A Simple Example /* * The HelloWorldApp class implements an application that * simply displays "Hello World!" to the standard output. */ class HelloWorldApp { public static void main(String[] args) { System.out.println("Hello World!"); //Display the string. }

6 Objects Objects are high level concepts that can have Variables (data associated with the concept) Methods (actions associated with the concept)

7 Passing Messages

8 Classes Definition: A class is a blueprint, or prototype, that defines the variables and the methods common to all objects of a certain kind.

9 Inheritance Subclass Superclass Hierarchy Inheritance Override Abstract classes

10 Putting the Ideas Into Action ClickMe.java Spot.java

11 First Swing Example import javax.swing.*; public class HelloWorldSwing { public static void main(String[] args) { JFrame frame = new JFrame("HelloWorldSwing"); final JLabel label = new JLabel("Hello World"); frame.getContentPane().add(label); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); }

12 Actions and Events Examples of Events and Their Associated Event Listeners Act that Results in the EventListener Type User clicks a button, presses Return while typing in a text field, or chooses a menu item ActionListener User closes a frame (main window) WindowListener User presses a mouse button while the cursor is over a component MouseListener User moves the mouse over a component MouseMotionListen er Component becomes visible ComponentListener Component gets the keyboard focus FocusListener Table or list selection changes ListSelectionListene r


Download ppt "Intro to Java 2 By Geb Thomas Based on the Java TutorialJava Tutorial."

Similar presentations


Ads by Google