Java2D - University of Exeterempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides03.pdf · Basics...
Transcript of Java2D - University of Exeterempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides03.pdf · Basics...
ECM2410: Graphics and Animation
Java 2D
Java 2D 1/17
Java 2D Basics
Device
Output is to a FrameFrame is the ‘window’ of window managers andMicrosoft.Output can also be drawn to a Component, JComponent,etc or an image.
paint()
Each object to be drawn has a paint() method, which iscalled to draw the object.
Simple
In simple programs all work is done by a single paint().
Basics Java 2D 2/17
Java 2D Basics
Device
Output is to a FrameFrame is the ‘window’ of window managers andMicrosoft.Output can also be drawn to a Component, JComponent,etc or an image.
paint()
Each object to be drawn has a paint() method, which iscalled to draw the object.
Simple
In simple programs all work is done by a single paint().
Basics Java 2D 2/17
Java 2D Basics
Device
Output is to a FrameFrame is the ‘window’ of window managers andMicrosoft.Output can also be drawn to a Component, JComponent,etc or an image.
paint()
Each object to be drawn has a paint() method, which iscalled to draw the object.
Simple
In simple programs all work is done by a single paint().
Basics Java 2D 2/17
Java 2D Basics
Device
Output is to a FrameFrame is the ‘window’ of window managers andMicrosoft.Output can also be drawn to a Component, JComponent,etc or an image.
paint()
Each object to be drawn has a paint() method, which iscalled to draw the object.
Simple
In simple programs all work is done by a single paint().
Basics Java 2D 2/17
Java 2D Basics
Device
Output is to a FrameFrame is the ‘window’ of window managers andMicrosoft.Output can also be drawn to a Component, JComponent,etc or an image.
paint()
Each object to be drawn has a paint() method, which iscalled to draw the object.
Simple
In simple programs all work is done by a single paint().
Basics Java 2D 2/17
Java 2D Basics
Device
Output is to a FrameFrame is the ‘window’ of window managers andMicrosoft.Output can also be drawn to a Component, JComponent,etc or an image.
paint()
Each object to be drawn has a paint() method, which iscalled to draw the object.
Simple
In simple programs all work is done by a single paint().
Basics Java 2D 2/17
Java 2D Basics
Device
Output is to a FrameFrame is the ‘window’ of window managers andMicrosoft.Output can also be drawn to a Component, JComponent,etc or an image.
paint()
Each object to be drawn has a paint() method, which iscalled to draw the object.
Simple
In simple programs all work is done by a single paint().
Basics Java 2D 2/17
Java 2D Basics
Device
Output is to a FrameFrame is the ‘window’ of window managers andMicrosoft.Output can also be drawn to a Component, JComponent,etc or an image.
paint()
Each object to be drawn has a paint() method, which iscalled to draw the object.
Simple
In simple programs all work is done by a single paint().
Basics Java 2D 2/17
Java 2D Basics
Device
Output is to a FrameFrame is the ‘window’ of window managers andMicrosoft.Output can also be drawn to a Component, JComponent,etc or an image.
paint()
Each object to be drawn has a paint() method, which iscalled to draw the object.
Simple
In simple programs all work is done by a single paint().
Basics Java 2D 2/17
Object Hierarchy
java.lang.Object.Object
java.lang.awt.Component Abstract super-class – implementedby buttons, scrollbars, canvases etc
java.lang.awt.Container Holds Components
java.lang.awt.Window No borders, menubars.Also JComponent
java.lang.awt.Frame Title and borderjava.lang.awt.Frame.paint()
Invoked to redraw Component
Components/Containers receive events from window manager
Sub-class paint() methods invoked to redraw Component
Basics Java 2D 3/17
Object Hierarchy
java.lang.Object.Object
java.lang.awt.Component Abstract super-class – implementedby buttons, scrollbars, canvases etc
java.lang.awt.Container Holds Components
java.lang.awt.Window No borders, menubars.Also JComponent
java.lang.awt.Frame Title and borderjava.lang.awt.Frame.paint()
Invoked to redraw Component
Components/Containers receive events from window manager
Sub-class paint() methods invoked to redraw Component
Basics Java 2D 3/17
Object Hierarchy
java.lang.Object.Object
java.lang.awt.Component Abstract super-class – implementedby buttons, scrollbars, canvases etc
java.lang.awt.Container Holds Components
java.lang.awt.Window No borders, menubars.Also JComponent
java.lang.awt.Frame Title and borderjava.lang.awt.Frame.paint()
Invoked to redraw Component
Components/Containers receive events from window manager
Sub-class paint() methods invoked to redraw Component
Basics Java 2D 3/17
Object Hierarchy
java.lang.Object.Object
java.lang.awt.Component Abstract super-class – implementedby buttons, scrollbars, canvases etc
java.lang.awt.Container Holds Components
java.lang.awt.Window No borders, menubars.Also JComponent
java.lang.awt.Frame Title and borderjava.lang.awt.Frame.paint()
Invoked to redraw Component
Components/Containers receive events from window manager
Sub-class paint() methods invoked to redraw Component
Basics Java 2D 3/17
Object Hierarchy
java.lang.Object.Object
java.lang.awt.Component Abstract super-class – implementedby buttons, scrollbars, canvases etc
java.lang.awt.Container Holds Components
java.lang.awt.Window No borders, menubars.Also JComponent
java.lang.awt.Frame Title and borderjava.lang.awt.Frame.paint()
Invoked to redraw Component
Components/Containers receive events from window manager
Sub-class paint() methods invoked to redraw Component
Basics Java 2D 3/17
Object Hierarchy
java.lang.Object.Object
java.lang.awt.Component Abstract super-class – implementedby buttons, scrollbars, canvases etc
java.lang.awt.Container Holds Components
java.lang.awt.Window No borders, menubars.Also JComponent
java.lang.awt.Frame Title and borderjava.lang.awt.Frame.paint()
Invoked to redraw Component
Components/Containers receive events from window manager
Sub-class paint() methods invoked to redraw Component
Basics Java 2D 3/17
Object Hierarchy
java.lang.Object.Object
java.lang.awt.Component Abstract super-class – implementedby buttons, scrollbars, canvases etc
java.lang.awt.Container Holds Components
java.lang.awt.Window No borders, menubars.Also JComponent
java.lang.awt.Frame Title and borderjava.lang.awt.Frame.paint()
Invoked to redraw Component
Components/Containers receive events from window manager
Sub-class paint() methods invoked to redraw Component
Basics Java 2D 3/17
Object Hierarchy
java.lang.Object.Object
java.lang.awt.Component Abstract super-class – implementedby buttons, scrollbars, canvases etc
java.lang.awt.Container Holds Components
java.lang.awt.Window No borders, menubars.Also JComponent
java.lang.awt.Frame Title and borderjava.lang.awt.Frame.paint()
Invoked to redraw Component
Components/Containers receive events from window manager
Sub-class paint() methods invoked to redraw Component
Basics Java 2D 3/17
Object Hierarchy
java.lang.Object.Object
java.lang.awt.Component Abstract super-class – implementedby buttons, scrollbars, canvases etc
java.lang.awt.Container Holds Components
java.lang.awt.Window No borders, menubars.Also JComponent
java.lang.awt.Frame Title and borderjava.lang.awt.Frame.paint()
Invoked to redraw Component
Components/Containers receive events from window manager
Sub-class paint() methods invoked to redraw Component
Basics Java 2D 3/17
Object Hierarchy
java.lang.Object.Object
java.lang.awt.Component Abstract super-class – implementedby buttons, scrollbars, canvases etc
java.lang.awt.Container Holds Components
java.lang.awt.Window No borders, menubars.Also JComponent
java.lang.awt.Frame Title and borderjava.lang.awt.Frame.paint()
Invoked to redraw Component
Components/Containers receive events from window manager
Sub-class paint() methods invoked to redraw Component
Basics Java 2D 3/17
String Art Exeter.java
import java.awt.*;import java.awt.geom.*;
public class StringArtExeter extends ApplicationFrame {public StringArtExeter () {
super("StringArtExeter"); // Name in titlebarsetSize(600, 600); // Frame size, in pixelscenter(); // Centre of desktopsetVisible(true);
}
public void paint(Graphics g) {// Work done here
}
public static void main(String[] args) {new StringArtExeter();
}}
Basics Java 2D 4/17
String Art Exeter.java
import java.awt.*;import java.awt.geom.*;
public class StringArtExeter extends ApplicationFrame {public StringArtExeter () {
super("StringArtExeter"); // Name in titlebarsetSize(600, 600); // Frame size, in pixelscenter(); // Centre of desktopsetVisible(true);
}
public void paint(Graphics g) {// Work done here
}
public static void main(String[] args) {new StringArtExeter();
}}
Basics Java 2D 4/17
String Art Exeter.java
import java.awt.*;import java.awt.geom.*;
public class StringArtExeter extends ApplicationFrame {public StringArtExeter () {
super("StringArtExeter"); // Name in titlebarsetSize(600, 600); // Frame size, in pixelscenter(); // Centre of desktopsetVisible(true);
}
public void paint(Graphics g) {// Work done here
}
public static void main(String[] args) {new StringArtExeter();
}}
Basics Java 2D 4/17
String Art Exeter.java
import java.awt.*;import java.awt.geom.*;
public class StringArtExeter extends ApplicationFrame {public StringArtExeter () {
super("StringArtExeter"); // Name in titlebarsetSize(600, 600); // Frame size, in pixelscenter(); // Centre of desktopsetVisible(true);
}
public void paint(Graphics g) {// Work done here
}
public static void main(String[] args) {new StringArtExeter();
}}
Basics Java 2D 4/17
String Art Exeter.java
import java.awt.*;import java.awt.geom.*;
public class StringArtExeter extends ApplicationFrame {public StringArtExeter () {
super("StringArtExeter"); // Name in titlebarsetSize(600, 600); // Frame size, in pixelscenter(); // Centre of desktopsetVisible(true);
}
public void paint(Graphics g) {// Work done here
}
public static void main(String[] args) {new StringArtExeter();
}}
Basics Java 2D 4/17
String Art Exeter.java
import java.awt.*;import java.awt.geom.*;
public class StringArtExeter extends ApplicationFrame {public StringArtExeter () {
super("StringArtExeter"); // Name in titlebarsetSize(600, 600); // Frame size, in pixelscenter(); // Centre of desktopsetVisible(true);
}
public void paint(Graphics g) {// Work done here
}
public static void main(String[] args) {new StringArtExeter();
}}
Basics Java 2D 4/17
Application Frame.java
Extends FrameSets up an application with user interface
Methodspublic ApplicationFrame(String title)Constructor, putting “title” in frame title-bar
public void center()Centre frame on desktop
System.exit() when frame closed.
Code under “Example Files” on ELE pageApplicationFramePrint – with printing interface
Basics Java 2D 5/17
Application Frame.java
Extends FrameSets up an application with user interface
Methodspublic ApplicationFrame(String title)Constructor, putting “title” in frame title-bar
public void center()Centre frame on desktop
System.exit() when frame closed.
Code under “Example Files” on ELE pageApplicationFramePrint – with printing interface
Basics Java 2D 5/17
Application Frame.java
Extends FrameSets up an application with user interface
Methodspublic ApplicationFrame(String title)Constructor, putting “title” in frame title-bar
public void center()Centre frame on desktop
System.exit() when frame closed.
Code under “Example Files” on ELE pageApplicationFramePrint – with printing interface
Basics Java 2D 5/17
Application Frame.java
Extends FrameSets up an application with user interface
Methodspublic ApplicationFrame(String title)Constructor, putting “title” in frame title-bar
public void center()Centre frame on desktop
System.exit() when frame closed.
Code under “Example Files” on ELE pageApplicationFramePrint – with printing interface
Basics Java 2D 5/17
Application Frame.java
Extends FrameSets up an application with user interface
Methodspublic ApplicationFrame(String title)Constructor, putting “title” in frame title-bar
public void center()Centre frame on desktop
System.exit() when frame closed.
Code under “Example Files” on ELE pageApplicationFramePrint – with printing interface
Basics Java 2D 5/17
Application Frame.java
Extends FrameSets up an application with user interface
Methodspublic ApplicationFrame(String title)Constructor, putting “title” in frame title-bar
public void center()Centre frame on desktop
System.exit() when frame closed.
Code under “Example Files” on ELE pageApplicationFramePrint – with printing interface
Basics Java 2D 5/17
Application Frame.java
Extends FrameSets up an application with user interface
Methodspublic ApplicationFrame(String title)Constructor, putting “title” in frame title-bar
public void center()Centre frame on desktop
System.exit() when frame closed.
Code under “Example Files” on ELE pageApplicationFramePrint – with printing interface
Basics Java 2D 5/17
Application Frame.java
Extends FrameSets up an application with user interface
Methodspublic ApplicationFrame(String title)Constructor, putting “title” in frame title-bar
public void center()Centre frame on desktop
System.exit() when frame closed.
Code under “Example Files” on ELE pageApplicationFramePrint – with printing interface
Basics Java 2D 5/17
Application Frame.java
Extends FrameSets up an application with user interface
Methodspublic ApplicationFrame(String title)Constructor, putting “title” in frame title-bar
public void center()Centre frame on desktop
System.exit() when frame closed.
Code under “Example Files” on ELE pageApplicationFramePrint – with printing interface
Basics Java 2D 5/17
Application Frame.java
Extends FrameSets up an application with user interface
Methodspublic ApplicationFrame(String title)Constructor, putting “title” in frame title-bar
public void center()Centre frame on desktop
System.exit() when frame closed.
Code under “Example Files” on ELE pageApplicationFramePrint – with printing interface
Basics Java 2D 5/17
Application Frame.java
Extends FrameSets up an application with user interface
Methodspublic ApplicationFrame(String title)Constructor, putting “title” in frame title-bar
public void center()Centre frame on desktop
System.exit() when frame closed.
Code under “Example Files” on ELE pageApplicationFramePrint – with printing interface
Basics Java 2D 5/17
String Art Exeter.java
private int mNumberOfLines = 25;private Color[] mColors = { Color.red, Color.green, Color.blue };
public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g; // Promote to Graphics2D context
System.out.println("Paint");Dimension d = getSize(); // Defined by Frame
for (int i = 0; i < mNumberOfLines; i++) {double ratio = (double)i / (double)mNumberOfLines;Line2D line = new Line2D.Double(
0, ratio * d.height,ratio * d.width, d.height);
g2.setPaint(mColors[i % mColors.length]);g2.draw(line);
}}
Basics Java 2D 6/17
String Art Exeter.java
private int mNumberOfLines = 25;private Color[] mColors = { Color.red, Color.green, Color.blue };
public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g; // Promote to Graphics2D context
System.out.println("Paint");Dimension d = getSize(); // Defined by Frame
for (int i = 0; i < mNumberOfLines; i++) {double ratio = (double)i / (double)mNumberOfLines;Line2D line = new Line2D.Double(
0, ratio * d.height,ratio * d.width, d.height);
g2.setPaint(mColors[i % mColors.length]);g2.draw(line);
}}
Basics Java 2D 6/17
String Art Exeter.java
private int mNumberOfLines = 25;private Color[] mColors = { Color.red, Color.green, Color.blue };
public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g; // Promote to Graphics2D context
System.out.println("Paint");Dimension d = getSize(); // Defined by Frame
for (int i = 0; i < mNumberOfLines; i++) {double ratio = (double)i / (double)mNumberOfLines;Line2D line = new Line2D.Double(
0, ratio * d.height,ratio * d.width, d.height);
g2.setPaint(mColors[i % mColors.length]);g2.draw(line);
}}
Basics Java 2D 6/17
String Art Exeter.java
private int mNumberOfLines = 25;private Color[] mColors = { Color.red, Color.green, Color.blue };
public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g; // Promote to Graphics2D context
System.out.println("Paint");Dimension d = getSize(); // Defined by Frame
for (int i = 0; i < mNumberOfLines; i++) {double ratio = (double)i / (double)mNumberOfLines;Line2D line = new Line2D.Double(
0, ratio * d.height,ratio * d.width, d.height);
g2.setPaint(mColors[i % mColors.length]);g2.draw(line);
}}
Basics Java 2D 6/17
String Art Exeter.java
private int mNumberOfLines = 25;private Color[] mColors = { Color.red, Color.green, Color.blue };
public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g; // Promote to Graphics2D context
System.out.println("Paint");Dimension d = getSize(); // Defined by Frame
for (int i = 0; i < mNumberOfLines; i++) {double ratio = (double)i / (double)mNumberOfLines;Line2D line = new Line2D.Double(
0, ratio * d.height,ratio * d.width, d.height);
g2.setPaint(mColors[i % mColors.length]);g2.draw(line);
}}
Basics Java 2D 6/17
String Art Exeter.java
private int mNumberOfLines = 25;private Color[] mColors = { Color.red, Color.green, Color.blue };
public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g; // Promote to Graphics2D context
System.out.println("Paint");Dimension d = getSize(); // Defined by Frame
for (int i = 0; i < mNumberOfLines; i++) {double ratio = (double)i / (double)mNumberOfLines;Line2D line = new Line2D.Double(
0, ratio * d.height,ratio * d.width, d.height);
g2.setPaint(mColors[i % mColors.length]);g2.draw(line);
}}
Basics Java 2D 6/17
String Art Exeter.java
private int mNumberOfLines = 25;private Color[] mColors = { Color.red, Color.green, Color.blue };
public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g; // Promote to Graphics2D context
System.out.println("Paint");Dimension d = getSize(); // Defined by Frame
for (int i = 0; i < mNumberOfLines; i++) {double ratio = (double)i / (double)mNumberOfLines;Line2D line = new Line2D.Double(
0, ratio * d.height,ratio * d.width, d.height);
g2.setPaint(mColors[i % mColors.length]);g2.draw(line);
}}
Basics Java 2D 6/17
The paint() Method
paint() is invoked whenever the Frame needs redrawingResize, redraw, expose eventsOccasionally invoked unnecessarily.
paint(Graphics g)
g is old graphics context; cast toGraphics2D
Device coordinate origin is at thetop left hand corner.X-axis horizontally.Y-axis vertically downwards.Frame is also occupied bywindow manager borders etcDefault transformation fromworld to device coordinates isthe identity
Basics Java 2D 7/17
The paint() Method
paint() is invoked whenever the Frame needs redrawingResize, redraw, expose eventsOccasionally invoked unnecessarily.
paint(Graphics g)
g is old graphics context; cast toGraphics2D
Device coordinate origin is at thetop left hand corner.X-axis horizontally.Y-axis vertically downwards.Frame is also occupied bywindow manager borders etcDefault transformation fromworld to device coordinates isthe identity
Basics Java 2D 7/17
The paint() Method
paint() is invoked whenever the Frame needs redrawingResize, redraw, expose eventsOccasionally invoked unnecessarily.
paint(Graphics g)
g is old graphics context; cast toGraphics2D
Device coordinate origin is at thetop left hand corner.X-axis horizontally.Y-axis vertically downwards.Frame is also occupied bywindow manager borders etcDefault transformation fromworld to device coordinates isthe identity
Basics Java 2D 7/17
The paint() Method
paint() is invoked whenever the Frame needs redrawingResize, redraw, expose eventsOccasionally invoked unnecessarily.
paint(Graphics g)
g is old graphics context; cast toGraphics2D
Device coordinate origin is at thetop left hand corner.X-axis horizontally.Y-axis vertically downwards.Frame is also occupied bywindow manager borders etcDefault transformation fromworld to device coordinates isthe identity
Basics Java 2D 7/17
The paint() Method
paint() is invoked whenever the Frame needs redrawingResize, redraw, expose eventsOccasionally invoked unnecessarily.
paint(Graphics g)
g is old graphics context; cast toGraphics2D
Device coordinate origin is at thetop left hand corner.X-axis horizontally.Y-axis vertically downwards.Frame is also occupied bywindow manager borders etcDefault transformation fromworld to device coordinates isthe identity
Basics Java 2D 7/17
The paint() Method
paint() is invoked whenever the Frame needs redrawingResize, redraw, expose eventsOccasionally invoked unnecessarily.
paint(Graphics g)
g is old graphics context; cast toGraphics2D
Device coordinate origin is at thetop left hand corner.X-axis horizontally.Y-axis vertically downwards.Frame is also occupied bywindow manager borders etcDefault transformation fromworld to device coordinates isthe identity
Basics Java 2D 7/17
The paint() Method
paint() is invoked whenever the Frame needs redrawingResize, redraw, expose eventsOccasionally invoked unnecessarily.
paint(Graphics g)
g is old graphics context; cast toGraphics2D
Device coordinate origin is at thetop left hand corner.X-axis horizontally.Y-axis vertically downwards.Frame is also occupied bywindow manager borders etcDefault transformation fromworld to device coordinates isthe identity
Basics Java 2D 7/17
The paint() Method
paint() is invoked whenever the Frame needs redrawingResize, redraw, expose eventsOccasionally invoked unnecessarily.
paint(Graphics g)
g is old graphics context; cast toGraphics2D
Device coordinate origin is at thetop left hand corner.X-axis horizontally.Y-axis vertically downwards.Frame is also occupied bywindow manager borders etcDefault transformation fromworld to device coordinates isthe identity
Basics Java 2D 7/17
The paint() Method
paint() is invoked whenever the Frame needs redrawingResize, redraw, expose eventsOccasionally invoked unnecessarily.
paint(Graphics g)
g is old graphics context; cast toGraphics2D
Device coordinate origin is at thetop left hand corner.X-axis horizontally.Y-axis vertically downwards.Frame is also occupied bywindow manager borders etcDefault transformation fromworld to device coordinates isthe identity
Basics Java 2D 7/17
The paint() Method
paint() is invoked whenever the Frame needs redrawingResize, redraw, expose eventsOccasionally invoked unnecessarily.
paint(Graphics g)
g is old graphics context; cast toGraphics2D
Device coordinate origin is at thetop left hand corner.X-axis horizontally.Y-axis vertically downwards.Frame is also occupied bywindow manager borders etcDefault transformation fromworld to device coordinates isthe identity
Basics Java 2D 7/17
Coordinates
Local Coordinates
Specify locations of primitives in objectArbitrary units (chosen by the modeller).
World Coordinates or User Coordinates.Specify locations of objects in sceneSpecify location of clipping windowUnits dependent on graphics API.Java2D: pixels.
Device Coordinates or Screen CoordinatesMeasured in pixels.
Single viewportOccupies the entire device space.
Basics Java 2D 8/17
Coordinates
Local Coordinates
Specify locations of primitives in objectArbitrary units (chosen by the modeller).
World Coordinates or User Coordinates.Specify locations of objects in sceneSpecify location of clipping windowUnits dependent on graphics API.Java2D: pixels.
Device Coordinates or Screen CoordinatesMeasured in pixels.
Single viewportOccupies the entire device space.
Basics Java 2D 8/17
Coordinates
Local Coordinates
Specify locations of primitives in objectArbitrary units (chosen by the modeller).
World Coordinates or User Coordinates.Specify locations of objects in sceneSpecify location of clipping windowUnits dependent on graphics API.Java2D: pixels.
Device Coordinates or Screen CoordinatesMeasured in pixels.
Single viewportOccupies the entire device space.
Basics Java 2D 8/17
Coordinates
Local Coordinates
Specify locations of primitives in objectArbitrary units (chosen by the modeller).
World Coordinates or User Coordinates.Specify locations of objects in sceneSpecify location of clipping windowUnits dependent on graphics API.Java2D: pixels.
Device Coordinates or Screen CoordinatesMeasured in pixels.
Single viewportOccupies the entire device space.
Basics Java 2D 8/17
Coordinates
Local Coordinates
Specify locations of primitives in objectArbitrary units (chosen by the modeller).
World Coordinates or User Coordinates.Specify locations of objects in sceneSpecify location of clipping windowUnits dependent on graphics API.Java2D: pixels.
Device Coordinates or Screen CoordinatesMeasured in pixels.
Single viewportOccupies the entire device space.
Basics Java 2D 8/17
Coordinates
Local Coordinates
Specify locations of primitives in objectArbitrary units (chosen by the modeller).
World Coordinates or User Coordinates.Specify locations of objects in sceneSpecify location of clipping windowUnits dependent on graphics API.Java2D: pixels.
Device Coordinates or Screen CoordinatesMeasured in pixels.
Single viewportOccupies the entire device space.
Basics Java 2D 8/17
Coordinates
Local Coordinates
Specify locations of primitives in objectArbitrary units (chosen by the modeller).
World Coordinates or User Coordinates.Specify locations of objects in sceneSpecify location of clipping windowUnits dependent on graphics API.Java2D: pixels.
Device Coordinates or Screen CoordinatesMeasured in pixels.
Single viewportOccupies the entire device space.
Basics Java 2D 8/17
Coordinates
Local Coordinates
Specify locations of primitives in objectArbitrary units (chosen by the modeller).
World Coordinates or User Coordinates.Specify locations of objects in sceneSpecify location of clipping windowUnits dependent on graphics API.Java2D: pixels.
Device Coordinates or Screen CoordinatesMeasured in pixels.
Single viewportOccupies the entire device space.
Basics Java 2D 8/17
Coordinates
Local Coordinates
Specify locations of primitives in objectArbitrary units (chosen by the modeller).
World Coordinates or User Coordinates.Specify locations of objects in sceneSpecify location of clipping windowUnits dependent on graphics API.Java2D: pixels.
Device Coordinates or Screen CoordinatesMeasured in pixels.
Single viewportOccupies the entire device space.
Basics Java 2D 8/17
Coordinates
Local Coordinates
Specify locations of primitives in objectArbitrary units (chosen by the modeller).
World Coordinates or User Coordinates.Specify locations of objects in sceneSpecify location of clipping windowUnits dependent on graphics API.Java2D: pixels.
Device Coordinates or Screen CoordinatesMeasured in pixels.
Single viewportOccupies the entire device space.
Basics Java 2D 8/17
Coordinates
Local Coordinates
Specify locations of primitives in objectArbitrary units (chosen by the modeller).
World Coordinates or User Coordinates.Specify locations of objects in sceneSpecify location of clipping windowUnits dependent on graphics API.Java2D: pixels.
Device Coordinates or Screen CoordinatesMeasured in pixels.
Single viewportOccupies the entire device space.
Basics Java 2D 8/17
Coordinates
Local Coordinates
Specify locations of primitives in objectArbitrary units (chosen by the modeller).
World Coordinates or User Coordinates.Specify locations of objects in sceneSpecify location of clipping windowUnits dependent on graphics API.Java2D: pixels.
Device Coordinates or Screen CoordinatesMeasured in pixels.
Single viewportOccupies the entire device space.
Basics Java 2D 8/17
Coordinates
Local Coordinates
Specify locations of primitives in objectArbitrary units (chosen by the modeller).
World Coordinates or User Coordinates.Specify locations of objects in sceneSpecify location of clipping windowUnits dependent on graphics API.Java2D: pixels.
Device Coordinates or Screen CoordinatesMeasured in pixels.
Single viewportOccupies the entire device space.
Basics Java 2D 8/17
String Art Exeter Add.java
import java.awt.*;import java.awt.geom.*;import javax.swing.*;
public class StringArtExeterAdd extends JComponent {public void paint(Graphics g) { . . . }
public static void main(String[] args) {ApplicationFrame f =
new ApplicationFrame("StringArtExeterAdd");
f.add(new StringArtExeterAdd()); // Add to the JComponentf.setSize(600, 600);f.center();f.setVisible(true);
}}
Basics Java 2D 9/17
String Art Exeter Add.java
import java.awt.*;import java.awt.geom.*;import javax.swing.*;
public class StringArtExeterAdd extends JComponent {public void paint(Graphics g) { . . . }
public static void main(String[] args) {ApplicationFrame f =
new ApplicationFrame("StringArtExeterAdd");
f.add(new StringArtExeterAdd()); // Add to the JComponentf.setSize(600, 600);f.center();f.setVisible(true);
}}
Basics Java 2D 9/17
String Art Exeter Add.java
import java.awt.*;import java.awt.geom.*;import javax.swing.*;
public class StringArtExeterAdd extends JComponent {public void paint(Graphics g) { . . . }
public static void main(String[] args) {ApplicationFrame f =
new ApplicationFrame("StringArtExeterAdd");
f.add(new StringArtExeterAdd()); // Add to the JComponentf.setSize(600, 600);f.center();f.setVisible(true);
}}
Basics Java 2D 9/17
String Art Exeter Add.java
import java.awt.*;import java.awt.geom.*;import javax.swing.*;
public class StringArtExeterAdd extends JComponent {public void paint(Graphics g) { . . . }
public static void main(String[] args) {ApplicationFrame f =
new ApplicationFrame("StringArtExeterAdd");
f.add(new StringArtExeterAdd()); // Add to the JComponentf.setSize(600, 600);f.center();f.setVisible(true);
}}
Basics Java 2D 9/17
String Art Exeter Add.java
import java.awt.*;import java.awt.geom.*;import javax.swing.*;
public class StringArtExeterAdd extends JComponent {public void paint(Graphics g) { . . . }
public static void main(String[] args) {ApplicationFrame f =
new ApplicationFrame("StringArtExeterAdd");
f.add(new StringArtExeterAdd()); // Add to the JComponentf.setSize(600, 600);f.center();f.setVisible(true);
}}
Basics Java 2D 9/17
String Art Exeter Add.java
import java.awt.*;import java.awt.geom.*;import javax.swing.*;
public class StringArtExeterAdd extends JComponent {public void paint(Graphics g) { . . . }
public static void main(String[] args) {ApplicationFrame f =
new ApplicationFrame("StringArtExeterAdd");
f.add(new StringArtExeterAdd()); // Add to the JComponentf.setSize(600, 600);f.center();f.setVisible(true);
}}
Basics Java 2D 9/17
Modelling and Transformations
Modelling
Build objects in their own, natural coordinates.Standard size and orientation.Make objects as flexible as possible.
Transformations
Place objects in scene with transformations.Set the size, orientation with transformations.
Java
One graphics object per class.Constructor Instantiate shapes from primitives.paint() Draw the instantiated objects.
Modelling and transformation Java 2D 10/17
Modelling and Transformations
Modelling
Build objects in their own, natural coordinates.Standard size and orientation.Make objects as flexible as possible.
Transformations
Place objects in scene with transformations.Set the size, orientation with transformations.
Java
One graphics object per class.Constructor Instantiate shapes from primitives.paint() Draw the instantiated objects.
Modelling and transformation Java 2D 10/17
Modelling and Transformations
Modelling
Build objects in their own, natural coordinates.Standard size and orientation.Make objects as flexible as possible.
Transformations
Place objects in scene with transformations.Set the size, orientation with transformations.
Java
One graphics object per class.Constructor Instantiate shapes from primitives.paint() Draw the instantiated objects.
Modelling and transformation Java 2D 10/17
Modelling and Transformations
Modelling
Build objects in their own, natural coordinates.Standard size and orientation.Make objects as flexible as possible.
Transformations
Place objects in scene with transformations.Set the size, orientation with transformations.
Java
One graphics object per class.Constructor Instantiate shapes from primitives.paint() Draw the instantiated objects.
Modelling and transformation Java 2D 10/17
Modelling and Transformations
Modelling
Build objects in their own, natural coordinates.Standard size and orientation.Make objects as flexible as possible.
Transformations
Place objects in scene with transformations.Set the size, orientation with transformations.
Java
One graphics object per class.Constructor Instantiate shapes from primitives.paint() Draw the instantiated objects.
Modelling and transformation Java 2D 10/17
Modelling and Transformations
Modelling
Build objects in their own, natural coordinates.Standard size and orientation.Make objects as flexible as possible.
Transformations
Place objects in scene with transformations.Set the size, orientation with transformations.
Java
One graphics object per class.Constructor Instantiate shapes from primitives.paint() Draw the instantiated objects.
Modelling and transformation Java 2D 10/17
Modelling and Transformations
Modelling
Build objects in their own, natural coordinates.Standard size and orientation.Make objects as flexible as possible.
Transformations
Place objects in scene with transformations.Set the size, orientation with transformations.
Java
One graphics object per class.Constructor Instantiate shapes from primitives.paint() Draw the instantiated objects.
Modelling and transformation Java 2D 10/17
Modelling and Transformations
Modelling
Build objects in their own, natural coordinates.Standard size and orientation.Make objects as flexible as possible.
Transformations
Place objects in scene with transformations.Set the size, orientation with transformations.
Java
One graphics object per class.Constructor Instantiate shapes from primitives.paint() Draw the instantiated objects.
Modelling and transformation Java 2D 10/17
Modelling and Transformations
Modelling
Build objects in their own, natural coordinates.Standard size and orientation.Make objects as flexible as possible.
Transformations
Place objects in scene with transformations.Set the size, orientation with transformations.
Java
One graphics object per class.Constructor Instantiate shapes from primitives.paint() Draw the instantiated objects.
Modelling and transformation Java 2D 10/17
Modelling and Transformations
Modelling
Build objects in their own, natural coordinates.Standard size and orientation.Make objects as flexible as possible.
Transformations
Place objects in scene with transformations.Set the size, orientation with transformations.
Java
One graphics object per class.Constructor Instantiate shapes from primitives.paint() Draw the instantiated objects.
Modelling and transformation Java 2D 10/17
Modelling and Transformations
Modelling
Build objects in their own, natural coordinates.Standard size and orientation.Make objects as flexible as possible.
Transformations
Place objects in scene with transformations.Set the size, orientation with transformations.
Java
One graphics object per class.Constructor Instantiate shapes from primitives.paint() Draw the instantiated objects.
Modelling and transformation Java 2D 10/17
Modelling and Transformations
Modelling
Build objects in their own, natural coordinates.Standard size and orientation.Make objects as flexible as possible.
Transformations
Place objects in scene with transformations.Set the size, orientation with transformations.
Java
One graphics object per class.Constructor Instantiate shapes from primitives.paint() Draw the instantiated objects.
Modelling and transformation Java 2D 10/17
House.java – Primitives
body RectangleBottom left corner at (0,0)Width 150, Height 150
door RectangleBottom left corner at (50, 0)Width 50, Height 75.
roof Two lines( 0, 150) → (75, 250)(150, 150) → (75, 250)
(0,150)
(150,150)
(50,75) (100, 75)
(75,250)
(0,0)
(0,150)
Modelling and transformation Java 2D 11/17
House.java – Primitives
body RectangleBottom left corner at (0,0)Width 150, Height 150
door RectangleBottom left corner at (50, 0)Width 50, Height 75.
roof Two lines( 0, 150) → (75, 250)(150, 150) → (75, 250)
(0,150)
(150,150)
(50,75) (100, 75)
(75,250)
(0,0)
(0,150)
Modelling and transformation Java 2D 11/17
House.java – Primitives
body RectangleBottom left corner at (0,0)Width 150, Height 150
door RectangleBottom left corner at (50, 0)Width 50, Height 75.
roof Two lines( 0, 150) → (75, 250)(150, 150) → (75, 250)
(0,150)
(150,150)
(50,75) (100, 75)
(75,250)
(0,0)
(0,150)
Modelling and transformation Java 2D 11/17
House.java – Primitives
body RectangleBottom left corner at (0,0)Width 150, Height 150
door RectangleBottom left corner at (50, 0)Width 50, Height 75.
roof Two lines( 0, 150) → (75, 250)(150, 150) → (75, 250)
(0,150)
(150,150)
(50,75) (100, 75)
(75,250)
(0,0)
(0,150)
Modelling and transformation Java 2D 11/17
House.java – Primitives
body RectangleBottom left corner at (0,0)Width 150, Height 150
door RectangleBottom left corner at (50, 0)Width 50, Height 75.
roof Two lines( 0, 150) → (75, 250)(150, 150) → (75, 250)
(0,150)
(150,150)
(50,75) (100, 75)
(75,250)
(0,0)
(0,150)
Modelling and transformation Java 2D 11/17
House.java – Primitives
body RectangleBottom left corner at (0,0)Width 150, Height 150
door RectangleBottom left corner at (50, 0)Width 50, Height 75.
roof Two lines( 0, 150) → (75, 250)(150, 150) → (75, 250)
(0,150)
(150,150)
(50,75) (100, 75)
(75,250)
(0,0)
(0,150)
Modelling and transformation Java 2D 11/17
House.java – Primitives
body RectangleBottom left corner at (0,0)Width 150, Height 150
door RectangleBottom left corner at (50, 0)Width 50, Height 75.
roof Two lines( 0, 150) → (75, 250)(150, 150) → (75, 250)
(0,150)
(150,150)
(50,75) (100, 75)
(75,250)
(0,0)
(0,150)
Modelling and transformation Java 2D 11/17
House.java – Primitives
body RectangleBottom left corner at (0,0)Width 150, Height 150
door RectangleBottom left corner at (50, 0)Width 50, Height 75.
roof Two lines( 0, 150) → (75, 250)(150, 150) → (75, 250)
(0,150)
(150,150)
(50,75) (100, 75)
(75,250)
(0,0)
(0,150)
Modelling and transformation Java 2D 11/17
House.java – Primitives
body RectangleBottom left corner at (0,0)Width 150, Height 150
door RectangleBottom left corner at (50, 0)Width 50, Height 75.
roof Two lines( 0, 150) → (75, 250)(150, 150) → (75, 250)
(0,150)
(150,150)
(50,75) (100, 75)
(75,250)
(0,0)
(0,150)
Modelling and transformation Java 2D 11/17
House.java – Primitives
body RectangleBottom left corner at (0,0)Width 150, Height 150
door RectangleBottom left corner at (50, 0)Width 50, Height 75.
roof Two lines( 0, 150) → (75, 250)(150, 150) → (75, 250)
(0,150)
(150,150)
(50,75) (100, 75)
(75,250)
(0,0)
(0,150)
Modelling and transformation Java 2D 11/17
House.java – Primitives
body RectangleBottom left corner at (0,0)Width 150, Height 150
door RectangleBottom left corner at (50, 0)Width 50, Height 75.
roof Two lines( 0, 150) → (75, 250)(150, 150) → (75, 250)
(0,150)
(150,150)
(50,75) (100, 75)
(75,250)
(0,0)
(0,150)
Modelling and transformation Java 2D 11/17
House.java – Constructor
import java.awt.*;import java.awt.geom.*;
public class House {private Rectangle2D body;private Rectangle2D door;private GeneralPath roof = new GeneralPath();
public House() {// Setup the shapesbody = new Rectangle2D.Double(0.0, 0.0, 150.0, 150.0);door = new Rectangle2D.Double(50.0, 0.0, 50.0, 75.0);roof.append(new Line2D.Double(0.0, 150., 75., 250.), false);roof.append(new Line2D.Double(150., 150., 75., 250.), false);
}
public paint(Graphics g) {. . .
}}
Modelling and transformation Java 2D 12/17
House.java – Constructor
import java.awt.*;import java.awt.geom.*;
public class House {private Rectangle2D body;private Rectangle2D door;private GeneralPath roof = new GeneralPath();
public House() {// Setup the shapesbody = new Rectangle2D.Double(0.0, 0.0, 150.0, 150.0);door = new Rectangle2D.Double(50.0, 0.0, 50.0, 75.0);roof.append(new Line2D.Double(0.0, 150., 75., 250.), false);roof.append(new Line2D.Double(150., 150., 75., 250.), false);
}
public paint(Graphics g) {. . .
}}
Modelling and transformation Java 2D 12/17
House.java – Constructor
import java.awt.*;import java.awt.geom.*;
public class House {private Rectangle2D body;private Rectangle2D door;private GeneralPath roof = new GeneralPath();
public House() {// Setup the shapesbody = new Rectangle2D.Double(0.0, 0.0, 150.0, 150.0);door = new Rectangle2D.Double(50.0, 0.0, 50.0, 75.0);roof.append(new Line2D.Double(0.0, 150., 75., 250.), false);roof.append(new Line2D.Double(150., 150., 75., 250.), false);
}
public paint(Graphics g) {. . .
}}
Modelling and transformation Java 2D 12/17
House.java – Constructor
import java.awt.*;import java.awt.geom.*;
public class House {private Rectangle2D body;private Rectangle2D door;private GeneralPath roof = new GeneralPath();
public House() {// Setup the shapesbody = new Rectangle2D.Double(0.0, 0.0, 150.0, 150.0);door = new Rectangle2D.Double(50.0, 0.0, 50.0, 75.0);roof.append(new Line2D.Double(0.0, 150., 75., 250.), false);roof.append(new Line2D.Double(150., 150., 75., 250.), false);
}
public paint(Graphics g) {. . .
}}
Modelling and transformation Java 2D 12/17
House.java – Constructor
import java.awt.*;import java.awt.geom.*;
public class House {private Rectangle2D body;private Rectangle2D door;private GeneralPath roof = new GeneralPath();
public House() {// Setup the shapesbody = new Rectangle2D.Double(0.0, 0.0, 150.0, 150.0);door = new Rectangle2D.Double(50.0, 0.0, 50.0, 75.0);roof.append(new Line2D.Double(0.0, 150., 75., 250.), false);roof.append(new Line2D.Double(150., 150., 75., 250.), false);
}
public paint(Graphics g) {. . .
}}
Modelling and transformation Java 2D 12/17
House.java – Constructor
import java.awt.*;import java.awt.geom.*;
public class House {private Rectangle2D body;private Rectangle2D door;private GeneralPath roof = new GeneralPath();
public House() {// Setup the shapesbody = new Rectangle2D.Double(0.0, 0.0, 150.0, 150.0);door = new Rectangle2D.Double(50.0, 0.0, 50.0, 75.0);roof.append(new Line2D.Double(0.0, 150., 75., 250.), false);roof.append(new Line2D.Double(150., 150., 75., 250.), false);
}
public paint(Graphics g) {. . .
}}
Modelling and transformation Java 2D 12/17
House.java – Constructor
import java.awt.*;import java.awt.geom.*;
public class House {private Rectangle2D body;private Rectangle2D door;private GeneralPath roof = new GeneralPath();
public House() {// Setup the shapesbody = new Rectangle2D.Double(0.0, 0.0, 150.0, 150.0);door = new Rectangle2D.Double(50.0, 0.0, 50.0, 75.0);roof.append(new Line2D.Double(0.0, 150., 75., 250.), false);roof.append(new Line2D.Double(150., 150., 75., 250.), false);
}
public paint(Graphics g) {. . .
}}
Modelling and transformation Java 2D 12/17
House.java – Constructor
import java.awt.*;import java.awt.geom.*;
public class House {private Rectangle2D body;private Rectangle2D door;private GeneralPath roof = new GeneralPath();
public House() {// Setup the shapesbody = new Rectangle2D.Double(0.0, 0.0, 150.0, 150.0);door = new Rectangle2D.Double(50.0, 0.0, 50.0, 75.0);roof.append(new Line2D.Double(0.0, 150., 75., 250.), false);roof.append(new Line2D.Double(150., 150., 75., 250.), false);
}
public paint(Graphics g) {. . .
}}
Modelling and transformation Java 2D 12/17
House.java – Constructor
import java.awt.*;import java.awt.geom.*;
public class House {private Rectangle2D body;private Rectangle2D door;private GeneralPath roof = new GeneralPath();
public House() {// Setup the shapesbody = new Rectangle2D.Double(0.0, 0.0, 150.0, 150.0);door = new Rectangle2D.Double(50.0, 0.0, 50.0, 75.0);roof.append(new Line2D.Double(0.0, 150., 75., 250.), false);roof.append(new Line2D.Double(150., 150., 75., 250.), false);
}
public paint(Graphics g) {. . .
}}
Modelling and transformation Java 2D 12/17
House.java – Constructor
import java.awt.*;import java.awt.geom.*;
public class House {private Rectangle2D body;private Rectangle2D door;private GeneralPath roof = new GeneralPath();
public House() {// Setup the shapesbody = new Rectangle2D.Double(0.0, 0.0, 150.0, 150.0);door = new Rectangle2D.Double(50.0, 0.0, 50.0, 75.0);roof.append(new Line2D.Double(0.0, 150., 75., 250.), false);roof.append(new Line2D.Double(150., 150., 75., 250.), false);
}
public paint(Graphics g) {. . .
}}
Modelling and transformation Java 2D 12/17
House.java – paint()
public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g; // Promote to 2D context
g2.setStroke(new BasicStroke(5));g2.setPaint(Color.red); // Interiorg2.fill(body);g2.setPaint(Color.black); // Borderg2.draw(body);
g2.setPaint(Color.cyan);g2.draw(roof);
g2.setPaint(Color.green);g2.fill(door);
}
Modelling and transformation Java 2D 13/17
House.java – paint()
public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g; // Promote to 2D context
g2.setStroke(new BasicStroke(5));g2.setPaint(Color.red); // Interiorg2.fill(body);g2.setPaint(Color.black); // Borderg2.draw(body);
g2.setPaint(Color.cyan);g2.draw(roof);
g2.setPaint(Color.green);g2.fill(door);
}
Modelling and transformation Java 2D 13/17
House.java – paint()
public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g; // Promote to 2D context
g2.setStroke(new BasicStroke(5));g2.setPaint(Color.red); // Interiorg2.fill(body);g2.setPaint(Color.black); // Borderg2.draw(body);
g2.setPaint(Color.cyan);g2.draw(roof);
g2.setPaint(Color.green);g2.fill(door);
}
Modelling and transformation Java 2D 13/17
House.java – paint()
public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g; // Promote to 2D context
g2.setStroke(new BasicStroke(5));g2.setPaint(Color.red); // Interiorg2.fill(body);g2.setPaint(Color.black); // Borderg2.draw(body);
g2.setPaint(Color.cyan);g2.draw(roof);
g2.setPaint(Color.green);g2.fill(door);
}
Modelling and transformation Java 2D 13/17
House.java – paint()
public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g; // Promote to 2D context
g2.setStroke(new BasicStroke(5));g2.setPaint(Color.red); // Interiorg2.fill(body);g2.setPaint(Color.black); // Borderg2.draw(body);
g2.setPaint(Color.cyan);g2.draw(roof);
g2.setPaint(Color.green);g2.fill(door);
}
Modelling and transformation Java 2D 13/17
House.java – paint()
public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g; // Promote to 2D context
g2.setStroke(new BasicStroke(5));g2.setPaint(Color.red); // Interiorg2.fill(body);g2.setPaint(Color.black); // Borderg2.draw(body);
g2.setPaint(Color.cyan);g2.draw(roof);
g2.setPaint(Color.green);g2.fill(door);
}
Modelling and transformation Java 2D 13/17
House.java – paint()
public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g; // Promote to 2D context
g2.setStroke(new BasicStroke(5));g2.setPaint(Color.red); // Interiorg2.fill(body);g2.setPaint(Color.black); // Borderg2.draw(body);
g2.setPaint(Color.cyan);g2.draw(roof);
g2.setPaint(Color.green);g2.fill(door);
}
Modelling and transformation Java 2D 13/17
Draw House.java – Constructor / Main
import java.awt.*;import java.awt.geom.*;
public class DrawHouse extends ApplicationFrame {private House house = new House();
public DrawHouse() {super("DrawHouse");setSize(600, 600);center();setVisible(true);
}
public void paint(Graphics g) {. . .
}
public static void main(String[] args) {new DrawHouse();
}}
Modelling and transformation Java 2D 14/17
Draw House.java – Constructor / Main
import java.awt.*;import java.awt.geom.*;
public class DrawHouse extends ApplicationFrame {private House house = new House();
public DrawHouse() {super("DrawHouse");setSize(600, 600);center();setVisible(true);
}
public void paint(Graphics g) {. . .
}
public static void main(String[] args) {new DrawHouse();
}}
Modelling and transformation Java 2D 14/17
Draw House.java – Constructor / Main
import java.awt.*;import java.awt.geom.*;
public class DrawHouse extends ApplicationFrame {private House house = new House();
public DrawHouse() {super("DrawHouse");setSize(600, 600);center();setVisible(true);
}
public void paint(Graphics g) {. . .
}
public static void main(String[] args) {new DrawHouse();
}}
Modelling and transformation Java 2D 14/17
Draw House.java – Constructor / Main
import java.awt.*;import java.awt.geom.*;
public class DrawHouse extends ApplicationFrame {private House house = new House();
public DrawHouse() {super("DrawHouse");setSize(600, 600);center();setVisible(true);
}
public void paint(Graphics g) {. . .
}
public static void main(String[] args) {new DrawHouse();
}}
Modelling and transformation Java 2D 14/17
Draw House.java – Constructor / Main
import java.awt.*;import java.awt.geom.*;
public class DrawHouse extends ApplicationFrame {private House house = new House();
public DrawHouse() {super("DrawHouse");setSize(600, 600);center();setVisible(true);
}
public void paint(Graphics g) {. . .
}
public static void main(String[] args) {new DrawHouse();
}}
Modelling and transformation Java 2D 14/17
Draw House.java – Constructor / Main
import java.awt.*;import java.awt.geom.*;
public class DrawHouse extends ApplicationFrame {private House house = new House();
public DrawHouse() {super("DrawHouse");setSize(600, 600);center();setVisible(true);
}
public void paint(Graphics g) {. . .
}
public static void main(String[] args) {new DrawHouse();
}}
Modelling and transformation Java 2D 14/17
Draw House.java – Constructor / Main
import java.awt.*;import java.awt.geom.*;
public class DrawHouse extends ApplicationFrame {private House house = new House();
public DrawHouse() {super("DrawHouse");setSize(600, 600);center();setVisible(true);
}
public void paint(Graphics g) {. . .
}
public static void main(String[] args) {new DrawHouse();
}}
Modelling and transformation Java 2D 14/17
Draw House.java – Constructor / Main
import java.awt.*;import java.awt.geom.*;
public class DrawHouse extends ApplicationFrame {private House house = new House();
public DrawHouse() {super("DrawHouse");setSize(600, 600);center();setVisible(true);
}
public void paint(Graphics g) {. . .
}
public static void main(String[] args) {new DrawHouse();
}}
Modelling and transformation Java 2D 14/17
Draw House.java – paint()
Simply paint the house
public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g; // Promote to 2D contexthouse.paint(g); // Get House to paint itself
}
Translate to centre of Frame
public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g; // Promote to 2D context
// Translate the origin to middle of screenAffineTransform T =
AffineTransform.getTranslateInstance(300.0,300.0);g2.setTransform(T);
house.paint(g); // Get House to paint itself}
Modelling and transformation Java 2D 15/17
Draw House.java – paint()
Simply paint the house
public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g; // Promote to 2D contexthouse.paint(g); // Get House to paint itself
}
Translate to centre of Frame
public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g; // Promote to 2D context
// Translate the origin to middle of screenAffineTransform T =
AffineTransform.getTranslateInstance(300.0,300.0);g2.setTransform(T);
house.paint(g); // Get House to paint itself}
Modelling and transformation Java 2D 15/17
Draw House.java – paint()
Simply paint the house
public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g; // Promote to 2D contexthouse.paint(g); // Get House to paint itself
}
Translate to centre of Frame
public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g; // Promote to 2D context
// Translate the origin to middle of screenAffineTransform T =
AffineTransform.getTranslateInstance(300.0,300.0);g2.setTransform(T);
house.paint(g); // Get House to paint itself}
Modelling and transformation Java 2D 15/17
Draw House.java – paint()
Simply paint the house
public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g; // Promote to 2D contexthouse.paint(g); // Get House to paint itself
}
Translate to centre of Frame
public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g; // Promote to 2D context
// Translate the origin to middle of screenAffineTransform T =
AffineTransform.getTranslateInstance(300.0,300.0);g2.setTransform(T);
house.paint(g); // Get House to paint itself}
Modelling and transformation Java 2D 15/17
Draw House.java – paint()
Simply paint the house
public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g; // Promote to 2D contexthouse.paint(g); // Get House to paint itself
}
Translate to centre of Frame
public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g; // Promote to 2D context
// Translate the origin to middle of screenAffineTransform T =
AffineTransform.getTranslateInstance(300.0,300.0);g2.setTransform(T);
house.paint(g); // Get House to paint itself}
Modelling and transformation Java 2D 15/17
Draw House.java – paint()
Simply paint the house
public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g; // Promote to 2D contexthouse.paint(g); // Get House to paint itself
}
Translate to centre of Frame
public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g; // Promote to 2D context
// Translate the origin to middle of screenAffineTransform T =
AffineTransform.getTranslateInstance(300.0,300.0);g2.setTransform(T);
house.paint(g); // Get House to paint itself}
Modelling and transformation Java 2D 15/17
Draw House.java – paint()
Simply paint the house
public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g; // Promote to 2D contexthouse.paint(g); // Get House to paint itself
}
Translate to centre of Frame
public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g; // Promote to 2D context
// Translate the origin to middle of screenAffineTransform T =
AffineTransform.getTranslateInstance(300.0,300.0);g2.setTransform(T);
house.paint(g); // Get House to paint itself}
Modelling and transformation Java 2D 15/17
Draw House.java – paint()
Simply paint the house
public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g; // Promote to 2D contexthouse.paint(g); // Get House to paint itself
}
Translate to centre of Frame
public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g; // Promote to 2D context
// Translate the origin to middle of screenAffineTransform T =
AffineTransform.getTranslateInstance(300.0,300.0);g2.setTransform(T);
house.paint(g); // Get House to paint itself}
Modelling and transformation Java 2D 15/17
Draw House.java – paint()
Simply paint the house
public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g; // Promote to 2D contexthouse.paint(g); // Get House to paint itself
}
Translate to centre of Frame
public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g; // Promote to 2D context
// Translate the origin to middle of screenAffineTransform T =
AffineTransform.getTranslateInstance(300.0,300.0);g2.setTransform(T);
house.paint(g); // Get House to paint itself}
Modelling and transformation Java 2D 15/17
Draw House.java – paint()
Rotate and translate to centre of Frame
public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g; // Promote to 2D context
// Rotate by 180 degreesAffineTransform R = AffineTransform.getRotateInstance(Math.PI);
// Translate the origin to middle of screenAffineTransform T =
AffineTransform.getTranslateInstance(300.0,300.0);
T.concatenate(R); // Rotate, then translateg2.setTransform(T);
house.paint(g); // Get House to paint itself}
Modelling and transformation Java 2D 16/17
Draw House.java – paint()
Rotate and translate to centre of Frame
public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g; // Promote to 2D context
// Rotate by 180 degreesAffineTransform R = AffineTransform.getRotateInstance(Math.PI);
// Translate the origin to middle of screenAffineTransform T =
AffineTransform.getTranslateInstance(300.0,300.0);
T.concatenate(R); // Rotate, then translateg2.setTransform(T);
house.paint(g); // Get House to paint itself}
Modelling and transformation Java 2D 16/17
Draw House.java – paint()
Rotate and translate to centre of Frame
public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g; // Promote to 2D context
// Rotate by 180 degreesAffineTransform R = AffineTransform.getRotateInstance(Math.PI);
// Translate the origin to middle of screenAffineTransform T =
AffineTransform.getTranslateInstance(300.0,300.0);
T.concatenate(R); // Rotate, then translateg2.setTransform(T);
house.paint(g); // Get House to paint itself}
Modelling and transformation Java 2D 16/17
Draw House.java – paint()
Rotate and translate to centre of Frame
public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g; // Promote to 2D context
// Rotate by 180 degreesAffineTransform R = AffineTransform.getRotateInstance(Math.PI);
// Translate the origin to middle of screenAffineTransform T =
AffineTransform.getTranslateInstance(300.0,300.0);
T.concatenate(R); // Rotate, then translateg2.setTransform(T);
house.paint(g); // Get House to paint itself}
Modelling and transformation Java 2D 16/17
Draw House.java – paint()
Rotate and translate to centre of Frame
public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g; // Promote to 2D context
// Rotate by 180 degreesAffineTransform R = AffineTransform.getRotateInstance(Math.PI);
// Translate the origin to middle of screenAffineTransform T =
AffineTransform.getTranslateInstance(300.0,300.0);
T.concatenate(R); // Rotate, then translateg2.setTransform(T);
house.paint(g); // Get House to paint itself}
Modelling and transformation Java 2D 16/17
Draw House.java – paint()
Rotate and translate to centre of Frame
public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g; // Promote to 2D context
// Rotate by 180 degreesAffineTransform R = AffineTransform.getRotateInstance(Math.PI);
// Translate the origin to middle of screenAffineTransform T =
AffineTransform.getTranslateInstance(300.0,300.0);
T.concatenate(R); // Rotate, then translateg2.setTransform(T);
house.paint(g); // Get House to paint itself}
Modelling and transformation Java 2D 16/17
Draw House.java – paint()
Rotate and translate to centre of Frame
public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g; // Promote to 2D context
// Rotate by 180 degreesAffineTransform R = AffineTransform.getRotateInstance(Math.PI);
// Translate the origin to middle of screenAffineTransform T =
AffineTransform.getTranslateInstance(300.0,300.0);
T.concatenate(R); // Rotate, then translateg2.setTransform(T);
house.paint(g); // Get House to paint itself}
Modelling and transformation Java 2D 16/17
DrawHouse.java
No Transformations Translation Rotate, then translate
Draw objects in their own local coordinate system.
Use affine transformations to place them in the scene.
Modelling and transformation Java 2D 17/17
DrawHouse.java
No Transformations Translation Rotate, then translate
Draw objects in their own local coordinate system.
Use affine transformations to place them in the scene.
Modelling and transformation Java 2D 17/17
DrawHouse.java
No Transformations Translation Rotate, then translate
Draw objects in their own local coordinate system.
Use affine transformations to place them in the scene.
Modelling and transformation Java 2D 17/17
DrawHouse.java
No Transformations Translation Rotate, then translate
Draw objects in their own local coordinate system.
Use affine transformations to place them in the scene.
Modelling and transformation Java 2D 17/17
DrawHouse.java
No Transformations Translation Rotate, then translate
Draw objects in their own local coordinate system.
Use affine transformations to place them in the scene.
Modelling and transformation Java 2D 17/17
DrawHouse.java
No Transformations Translation Rotate, then translate
Draw objects in their own local coordinate system.
Use affine transformations to place them in the scene.
Modelling and transformation Java 2D 17/17