2 1 Java 1.1: (paint, update) Frame Canvas java.awt.canvas java.awt.component java.lang.object paint Canvas Graphics update Canvas ( ) paint Graphics

Size: px
Start display at page:

Download "2 1 Java 1.1: (paint, update) Frame Canvas java.awt.canvas java.awt.component java.lang.object paint Canvas Graphics update Canvas ( ) paint Graphics"

Transcription

1 1 1 Java 1.1 (graphics) (graph) ( ) ( ) (discretization, sampling) (pixel) 1 (raster) (0, 0) x y (quantization) ( ) ( ) CRT(Cathode-Ray Tube) (LCD: Liquid-Crystal Display) ( ) ( ) ( / ) imac , , Frame Frame ( ) OS java.awt.frame java.awt.window java.awt.container java.awt.component java.lant.object Canvas Canvas ( )

2 2 1 Java 1.1: (paint, update) Frame Canvas java.awt.canvas java.awt.component java.lang.object paint Canvas Graphics update Canvas ( ) paint Graphics Graphics ( ) Canvas Graphics java.awt.graphics java.lang.object - Crossline.java (2 ) import java.awt.*; import java.awt.event.*; public class CrossLine extends Canvas { private static final int width = 400; // Canvas

3 private static final int height = 300; // Canvas private CrossLine() { super(); setsize(width, height); setbackground(color.white); setforeground(color.black); // Canvas // ( ) // ( ) Frame f = new Frame("CrossLine"); // Frame f.add(this); // Frame Canva f.pack(); // f.addwindowlistener(new WindowAdapter() { public void windowclosing(windowevent e) { System.exit(0); ); f.setvisible(true); // Frame public void paint(graphics g) { g.drawline(0, 0, width-1, height-1); // : g.drawline(0, height-1, width-1, 0); // : g.drawstring("hello, Graphics.", width/2, height/2); // : public static void main(string[] args) { new CrossLine(); // Canvas - Lines.java import java.awt.*; import java.awt.event.*; public class Lines extends Canvas { private static final int width = 600; private static final int height = 600; protected static final int[][] points = // Canvas // Canvas

4 4 1 Java (0,0) 600 (599,75) (599,150) 600 (599,300) (300,599) (599,599) 1.2: {{10, 599, {30, 599, {75, 599, {150, 599, {300, 599, {599, 599, ; {599, 300, {599, 150, {599, 75, {599, 30, {599, 10 protected Lines(String name) { super(); setsize(width, height); setbackground(color.white); setforeground(color.black); // Canvas // ( ) // ( ) Frame f = new Frame(name); // Frame f.add(this); // Frame Canva f.pack(); // f.addwindowlistener(new WindowAdapter() { public void windowclosing(windowevent e) { System.exit(0); ); f.setvisible(true); // Frame public void paint(graphics g) { for (int i = 0; i < points.length; i++) { g.drawline(0, 0, points[i][0], points[i][1]); //

5 public static void main(string[] args) { new Lines("Lines"); // Canvas - DotLines.java import java.awt.*; public class DotLines extends Lines { private DotLines(String name) { super(name); // Lines public void paint(graphics g) { for (int i = 0; i < points.length; i++) { if (points[i][0] >= points[i][1]) { // x >= y ( ) int n = points[i][0]; // : n = x double d = ((double)points[i][1])/n; // 1 for (int x = 0; x <= n; x++) { // n g.fillrect(x, (int)(d*x+0.5), 1, 1); // else { // x < y ( ) int n = points[i][1]; // : n = y double d = ((double)points[i][0])/n; // 1 for (int y = 0; y <= n; y++) { // n g.fillrect((int)(d*y+0.5), y, 1, 1); // public static void main(string[] args) { new DotLines("DotLines"); // Canvas 4 - DDALines.java

6 6 1 Java DDA(Digital Differential Analyzer) ( ) import java.awt.*; public class DDALines extends Lines { private DDALines(String name) { super(name); // Lines public void paint(graphics g) { for (int i = 0; i < points.length; i++) { if (points[i][0] >= points[i][1]) { // x >= y ( ) int n = points[i][0]; // : n = x int dn = points[i][1] << 1; // * 2n int dr = dn - (n << 1); // ( -1) * 2n int e = dn - n; // ( -0.5) * 2n for (int x = 0, y = 0; x <= n; x++) { // n g.fillrect(x, y, 1, 1); // if (e > 0) { // (y 1 ) y++; e += dr; // & else { // (y ) e += dn; // else { // x < y ( ) int n = points[i][1]; // : n = y int dn = points[i][0] << 1; // * 2n int dr = dn - (n << 1); // ( -1) * 2n int e = dn - n; // ( -0.5) * 2n for (int x = 0, y = 0; y <= n; y++) { // n g.fillrect(x, y, 1, 1); // if (e > 0) { // (x 1 ) x++; e += dr; // & else { // (x ) e += dn; //

7 x (x o, y o) r y 1.3: public static void main(string[] args) { new DDALines("DDALines"); // Canvas 5 ( ) - Circle.java ( ) (x o, y o ) r x = r cos θ + x o, y = r sin θ + y o (θ [ π, π]) import java.awt.*; import java.awt.event.*; public class Circle extends Canvas { private static final int width = 600; private static final int height = 600; private static final int centerx = 300; private static final int centery = 299; private static final int radius = 250; protected int[][] points; // Canvas // Canvas // x // y // //

8 8 1 Java protected Circle(String name, int numberofpoints) { super(); // Canvas setsize(width, height); setbackground(color.white); // ( ) setforeground(color.black); // ( ) points = new int[numberofpoints+1][]; : n+1 for (int i = 0; i <= numberofpoints; i++) {// P_0 = p_n double theta = 2.0 * Math.PI * i / numberofpoints; // : n points[i] = new int[2]; points[i][0] = (int)(radius * Math.cos(theta)) + centerx; points[i][1] = (int)(radius * Math.sin(theta)) + centery; Frame f = new Frame(name); // Frame f.add(this); // Frame Canva f.pack(); // f.addwindowlistener(new WindowAdapter() { public void windowclosing(windowevent e) { System.exit(0); ); f.setvisible(true); // Frame public void paint(graphics g) { for (int i = 0; i < points.length - 1; i++) { g.drawline(points[i][0], points[i][1], // P_i P_i+1 points[i+1][0], points[i+1][1]); public static void main(string[] args) { if (args.length == 0) System.err.println("Usage: java Circle #"); else new Circle("Circle", Integer.parseInt(args[0])); // Canvas

9 ( ) ( ) (cone) (rod) (cone) ( ) ( ) RGB(Red Green Blue) ( 3 ) RGB ( 1.0) RGB Color ( R G B ) Red ( ) Green ( ) Blue ( ) Cyan ( ) Magenta ( ) Yellow ( ) White ( ) Black ( )

10 10 1 Java Black (0 0 0) Red (1 0 0) x=300, y=225 Green (0 1 0) x=213.4, y=375 Yellow Magenta (1 1 0) (1 0 1) White (1 1 1) Cyan (0 1 1) Blue (0 0 1) x=386.6, y= : 3 (RGB ) 3 CMY (Cyan Magenta Yellow) ( 3 ) CMY ( ) ( 1.0) CMY Color ( C M Y ) Cyan ( ) Magenta ( ) Yellow ( ) Red ( ) Green ( ) Blue ( ) Black ( ) White ( ) RGB CMY ( R G B ) = ( ) ( C M Y ) (1.1) HSB(HSV ) H, S, B 3 H, S, B (Hue) (Saturation) (Brightness/Value) RGB HSB 1 ( ) Java ( (300,225),(213.4,375),(386.6,375)

11 ) R = ( ), G = ( ), B = ( ) 3 3 import java.awt.*; import java.awt.event.*; public class AdditiveColor extends Canvas { protected static final int width = 600; // Canvas protected static final int height = 600; // Canvas protected static final double radius2 = * 180.0; // 2 protected double[][] centers = // {{300.0, 225.0, {213.4, 375.0, {386.6, 375.0; protected AdditiveColor(String name) { super(); setsize(width, height); // Canvas Frame f = new Frame(name); // Frame f.add(this); // Frame Canva f.pack(); // f.addwindowlistener(new WindowAdapter() { public void windowclosing(windowevent e) { System.exit(0); ); f.setvisible(true); // Frame public void paint(graphics g) { for (int y = 0; y < height; y++) { // y for (int x = 0; x < width; x++) { // x float[] color = new float[3]; // RGB for (int i = 0; i < 3; i++) { // RGB double dist2 = (x - centers[i][0]) * (x - centers[i][0]) + (y - centers[i][1]) * (y - centers[i][1]); color[i] = (dist2 > radius2)? 0.0f : 1.0f; 1 / 0

12 12 1 Java Cyan (0 1 1) Blue (0 0 1) R=0 G=1~0 B=1 R=0 G=1 B=0~1 Green (0 1 0) Magenta (1 0 1) R=0~1 G=0 B=1 R=1 G=0 B=1~0 R=1~0 G=1 B=0 y R=1 G=0~1 B=0 Yellow (1 1 0) Red (1 0 0) x 1.5: g.setcolor(new Color(color[0], color[1], color[2])); // (RGB ) g.fillrect(x, y, 1, 1); // 1 public static void main(string[] args) { new AdditiveColor("Additive Color");// Canvas π θ [0, ) : Red ( ) Yellow ( ) θ [ π, 2π ) : Yellow ( ) Green ( ) θ [ 2π, π) : Green ( ) Cyan ( ) 4π θ [π, ) : Cyan ( ) Blue ( ) θ [ 4π, 5π) : Blue ( ) Magenta ( ) θ [ 5π, 2π] : Magenta ( ) Red ( ) import java.awt.*;

13 import java.awt.event.*; public class ColorRingRGB extends Canvas { protected static final int width = 600; protected static final int height = 600; protected static final int centerx = 300; protected static final int centery = 299; protected static final int radius = 250; protected Color[] colors; protected int[][] points; // Canvas // Canvas // x // y // // // protected ColorRingRGB(String name, int numberofpoints) { super(); // Canvas setsize(width, height); setbackground(color.black); // ( ) setdata(numberofpoints); Frame f = new Frame(name); // Frame f.add(this); // Frame Canva f.pack(); // f.addwindowlistener(new WindowAdapter() { public void windowclosing(windowevent e) { System.exit(0); ); f.setvisible(true); // Frame protected void setdata(int numberofpoints) { final float onesixth = 1.0f / 6.0f; final float twosixth = 2.0f / 6.0f; final float threesixth = 3.0f / 6.0f; final float foursixth = 4.0f / 6.0f; final float fivesixth = 5.0f / 6.0f; final float six = 6.0f; colors = new Color[numberOfPoints+1]; : n+1 points = new int[numberofpoints+1][]; : n+1 for (int i = 0; i <= numberofpoints; i++) { float ratio = (float)i / numberofpoints;

14 14 1 Java // if (ratio <= onesixth) { // 0 <= t <= 1/6 colors[i] = new Color(1.0f, ratio*six, 0.0f); else if (ratio <= twosixth) { // 1/6 < t <= 2/6 colors[i] = new Color((twoSixth-ratio)*six, 1.0f, 0.0f); else if (ratio <= threesixth) { // 2/6 < t <= 3/6 colors[i] = new Color(0.0f, 1.0f, (ratio-twosixth)*six); else if (ratio <= foursixth) { // 3/6 < t <= 4/6 colors[i] = new Color(0.0f, (foursixth-ratio)*six, 1.0f); else if (ratio <= fivesixth) { // 4/6 < t <= 5/6 colors[i] = new Color((ratio-fourSixth)*six, 0.0f, 1.0f); else { // 5/6 < t <= 1 colors[i] = new Color(1.0f, 0.0f, (1.0f-ratio)*six); double theta = 2.0 * Math.PI * ratio; // (radian) points[i] = new int[2]; points[i][0] = (int)(radius * Math.cos(theta)) + centerx; points[i][1] = (int)(radius * Math.sin(theta)) + centery; public void paint(graphics g) { for (int i = 0; i < points.length - 1; i++) { g.setcolor(colors[i]); // (RGB ) g.drawline(points[i][0], points[i][1], points[i+1][0], points[i+1][1]); // P_i P_i+1 public static void main(string[] args) { if (args.length == 0) System.err.println("Usage: java ColorRingRGB #"); else new ColorRingRGB("ColorRingRGB", Integer.parseInt(args[0])); HSB

15 HSB import java.awt.*; import java.awt.event.*; public class ColorDisk extends Canvas { protected static final int width = 600; protected static final int height = 600; protected static final int centerx = 300; protected static final int centery = 299; protected static final int radius = 250; // Canvas // Canvas // x // y // protected ColorDisk(String name) { super(); setsize(width, height); // Canvas Frame f = new Frame(name); // Frame f.add(this); // Frame Canva f.pack(); // f.addwindowlistener(new WindowAdapter() { public void windowclosing(windowevent e) { System.exit(0); ); f.setvisible(true); // Frame public void paint(graphics g) { for (int y = 0; y < height; y++) { // y for (int x = 0; x < width; x++) { // x double dx = (double)(x-centerx); // x double dy = (double)(y-centery); // y float h = (float)(math.atan2(dy, dx) / (2.0 * Math.PI)); // x / 2PI float s = (float)(math.sqrt(dx*dx + dy*dy) / radius); // float b = (s > 1.0f)? 0.0f : 1.0f; // 1 / 0 if (s > 1.0f) s = 0.0f; // s 1 g.setcolor(color.gethsbcolor(h, s, b)); // (HSB )

16 16 1 Java g.fillrect(x, y, 1, 1); // 1 public static void main(string[] args) { new ColorDisk("ColorDisk"); // Canvas 1.3 (interactive; ) (event) ( ) (event driven) (event source) ( ) Canvas Canvas ( ) EventListener ( ) EventListener( ) EventListener Canvas Component addeventlistener EventListener Java EventListener EventAdapter ( ) EventListener EventAdapter EventAdapter Canvas EventAdapter

17 MouseEvent Java ( ) MouseEvent MouseEvent MouseEvent EventListener/Adapter MOUSE CLICKED MouseListener/Adapter mouseclicked MOUSE ENTERED MouseListener/Adapter mouseentered MOUSE EXITED MouseListener/Adapter mouseexited MOUSE PRESSED MouseListener/Adapter mousepressed MOUSE RELEASED MouseListener/Adapter mousereleased MOUSE DRAGGED MouseMotionListener/Adapter mousedragged MOUSE MOVED MouseMotionListener/Adapter mousemoved MouseEvent ( ) getmodifiers MouseEvent getx gety - Background.java Canvas MouseEvent Canvas Background EventListener MouseAdapter BAMouseAdapter MouseEvent BAMouseAdapter mousepressed mousereleased Background mousepressed mousereleased MouseEvent BAMouseAdapter Backround ba import java.awt.*; import java.awt.event.*; public class Background extends Canvas { private static final int width = 200; private static final int height = 200; // Canvas // Canvas private Background() { super(); // Canvas setsize(width, height); setbackground(color.green); // ( ) addmouselistener(new BgMouseAdapter(this)); Frame f = new Frame("Background"); f.add(this); // Frame // Frame Canva

18 18 1 Java f.pack(); // f.setvisible(true); // Frame f.addwindowlistener(new WindowAdapter() { public void windowclosing(windowevent e) { System.exit(0); ); protected void mousepressed(mouseevent me) { setbackground(color.red); repaint(); // ( ) (update) protected void mousereleased(mouseevent me) { setbackground(color.green); // ( ) repaint(); (update) public static void main(string[] args) { new Background(); // Canvas class BgMouseAdapter extends MouseAdapter { private Background bg; public BgMouseAdapter(Background bg) { this.bg = bg; public void mousepressed(mouseevent me) { bg.mousepressed(me); public void mousereleased(mouseevent me) { bg.mousereleased(me); ( ) - BackgroundListener.java MouseAdapter MouseLinstener (

19 ) Background MouseListener EventListener import java.awt.*; import java.awt.event.*; public class BackgroundListener extends Canvas implements MouseListener { private static final int width = 200; // Canvas private static final int height = 200; // Canvas private BackgroundListener() { super(); setsize(width, height); setbackground(color.green); addmouselistener(this); // Canvas // ( ) Frame f = new Frame("BackgroundListener"); // Frame f.add(this); // Frame Canva f.pack(); // f.setvisible(true); // Frame f.addwindowlistener(new WindowAdapter() { public void windowclosing(windowevent e) { System.exit(0); ); public void mousepressed(mouseevent me) { setbackground(color.red); repaint(); public void mousereleased(mouseevent me) { setbackground(color.green); repaint(); public void mouseentered(mouseevent me) { public void mouseexited(mouseevent me) { // ( ) (update) // ( ) (update)

20 20 1 Java public void mouseclicked(mouseevent me) { public static void main(string[] args) { new BackgroundListener(); // Canvas ( ) - BackgroundInner.java MouseAdapter BgMouseAdapter BackgroundInner BackgroundInner BackgroundInner setbackground repaint BgMouseAdapter import java.awt.*; import java.awt.event.*; public class BackgroundInner extends Canvas { private static final int width = 200; private static final int height = 200; // Canvas // Canvas private BackgroundInner() { super(); // Canvas setsize(width, height); setbackground(color.green); // ( ) addmouselistener(new BgMouseAdapter()); Frame f = new Frame("BackgroundInner"); // Frame f.add(this); // Frame Canva f.pack(); // f.setvisible(true); // Frame f.addwindowlistener(new WindowAdapter() { public void windowclosing(windowevent e) { System.exit(0); ); class BgMouseAdapter extends MouseAdapter { public void mousepressed(mouseevent me) { setbackground(color.red); // ( )

21 repaint(); (update) public void mousereleased(mouseevent me) { setbackground(color.green); // ( ) repaint(); (update) public static void main(string[] args) { new BackgroundInner(); // Canvas ( ) - BackgroundAnonymous.java MouseAdapter f.addwindowlistener WindowAdapter import java.awt.*; import java.awt.event.*; public class BackgroundAnonymous extends Canvas { private static final int width = 200; // Canvas private static final int height = 200; // Canvas private BackgroundAnonymous() { super(); // Canvas setsize(width, height); setbackground(color.green); // ( ) addmouselistener(new MouseAdapter() { public void mousepressed(mouseevent me) { setbackground(color.red); // ( ) repaint(); (update) public void mousereleased(mouseevent me) { setbackground(color.green); // ( ) repaint(); (update) );

22 22 1 Java Frame f = new Frame("BackgroundAnonymous"); // Frame f.add(this); // Frame Canva f.pack(); // f.setvisible(true); // Frame f.addwindowlistener(new WindowAdapter() { public void windowclosing(windowevent e) { System.exit(0); ); public static void main(string[] args) { new BackgroundAnonymous(); // Canvas - Marker.java getmodifiers int getx gety repaint update import java.awt.*; import java.awt.event.*; public class Marker extends Canvas { private static final int width = 400; private static final int height = 400; private static final int SIZE = 10; // Canvas // Canvas // 1 private Marker() { super(); // Canvas setsize(width, height); setbackground(color.white); // ( ) addmouselistener(new MouseAdapter () { public void mousepressed(mouseevent me) { int modifiers = me.getmodifiers(); //

23 ); Graphics g = getgraphics(); // Graphics if ((modifiers & MouseEvent.BUTTON3_MASK)!= 0) g.setcolor(color.blue); // 3( ) // else if ((modifiers & MouseEvent.BUTTON2_MASK)!= 0) // g.setcolor(color.blue); // 2( ) Mac else g.setcolor(color.red); // ( ) int x = me.getx(); // x int y = me.gety(); // y g.fillrect(x - (SIZE/2), y - (SIZE/2), SIZE, SIZE); // Frame f = new Frame("Marker"); // Frame f.add(this); // Frame Canva f.pack(); // f.setvisible(true); // Frame f.addwindowlistener(new WindowAdapter() { public void windowclosing(windowevent e) { System.exit(0); ); public static void main(string[] args) { new Marker(); // Canvas - Rubberband.java MouseListener MuoseMotionListener ( ) ( ) import java.awt.*; import java.awt.event.*; public class Rubberband extends Canvas { private static final int width = 400; private static final int height = 400; private int startx; // Canvas // Canvas // x

24 24 1 Java private int starty; // y private Rubberband() { super(); // Canvas setsize(width, height); setbackground(color.white); // ( ) setforeground(color.black); // ( ) addmouselistener(new MouseAdapter() { public void mousepressed(mouseevent me) { startx = me.getx(); // x ( ) starty = me.gety(); // y ( ) ); addmousemotionlistener(new MouseMotionAdapter() { public void mousedragged(mouseevent me) { Graphics g = getgraphics(); // Graphics update(g); // int x = me.getx(); // x int y = me.gety(); // y g.drawline(startx, starty, x, y); // ); Frame f = new Frame("Rubberband"); // Frame f.add(this); // Frame Canva f.pack(); // f.setvisible(true); // Frame f.addwindowlistener(new WindowAdapter() { public void windowclosing(windowevent e) { System.exit(0); ); public static void main(string[] args) { new Rubberband(); // Canvas - Draw.java

25 import java.awt.*; import java.awt.event.*; public class Draw extends Canvas { private static final int width = 400; private static final int height = 400; private int oldx; private int oldy; // Canvas // Canvas // x // y private Draw() { super(); // Canvas setsize(width, height); setbackground(color.white); // ( ) setforeground(color.black); // ( ) addmouselistener(new MouseAdapter() { public void mousepressed(mouseevent me) { oldx = me.getx(); // x ( ) oldy = me.gety(); // y ( ) ); addmousemotionlistener(new MouseMotionAdapter() { public void mousedragged(mouseevent me) { int x = me.getx(); // x int y = me.gety(); // y getgraphics().drawline(oldx, oldy, x, y);// oldx = x; oldy = y; ); Frame f = new Frame("Draw"); // Frame f.add(this); // Frame Canva f.pack(); // f.setvisible(true); // Frame f.addwindowlistener(new WindowAdapter() { public void windowclosing(windowevent e) { System.exit(0); );

26 26 1 Java public static void main(string[] args) { new Draw(); // Canvas 1.4 ( ) 2 Canvas (tolerance) 2 ( ) - Tolerance.java public class Tolerance { public final static double EPSILON = 1.0e-6; 2 2 (x, y) 2 - Vector2D.java import java.util.*; public class Vector2D { private double x, y; public Vector2D(double x, double y) { ( ) this.x = x; this.y = y; public Vector2D(Vector2D v) { ( ) this.x = v.x; this.y = v.y; public Vector2D(String str) { ( ) StringTokenizer st = new StringTokenizer(str);

27 1.4. ( ) 2 27 this.x = Double.parseDouble(st.nextToken()); this.y = Double.parseDouble(st.nextToken()); public double x() { // x return this.x; public double y() { // y return this.y; public double norm() { // ( ) return Math.sqrt(this.x * this.x + this.y * this.y); public Vector2D add(vector2d v) { // return new Vector2D(this.x + v.x, this.y + v.y); public Vector2D subtract(vector2d v) { // return new Vector2D(this.x - v.x, this.y - v.y); public Vector2D scale(double d) { // ( ) return new Vector2D(this.x * d, this.y * d); public Vector2D normalize() { // double norm = this.norm(); if (norm > Tolerance.EPSILON) return this.scale(1.0 / norm); else return (new Vector2D(0.0, 0.0)); public String tostring() { // return "(" + x + ", " + y + ")"; (affine transformation) p = Mp + v M ( 2 2 ) v ( ) 2

28 28 1 Java - x, y s x, s y [ sx 0 M = 0 s y ] - θ [ cos θ sin θ M = sin θ cos θ ] - v = [ t x t y ] T v = [ ] tx t y Matrix2X2.java public class Matrix2X2 { private double xx, xy, yx, yy; // public Matrix2X2(double xx, double xy, double yx, double yy) { this.xx = xx; this.xy = xy; ( ) this.yx = yx; this.yy = yy; public Matrix2X2(Matrix2X2 m) { ( ) this.xx = m.xx; this.xy = m.xy; this.yx = m.yx; this.yy = m.yy; public Vector2D apply(vector2d v) { return new Vector2D(xx*v.x() + xy*v.y(), yx*v.x() + yy*v.y()); public Matrix2X2 multiply(matrix2x2 m) { // return new Matrix2X2((xx*m.xx + xy*m.yx), (xx*m.xy + xy*m.yy), (yx*m.xx + yy*m.yx), (yx*m.xy + yy*m.yy)); public static Matrix2X2 rotate(double t) { return new Matrix2X2(Math.cos(t), -Math.sin(t), Math.sin(t), Math.cos(t)); public static Matrix2X2 scale(double s) { return new Matrix2X2(s, 0.0, 0.0, s);

29 1.4. ( ) 2 29 Canvas - CGCanvas.java CGCanvas x, y 1 import java.awt.*; import java.awt.event.*; public class CGCanvas extends Canvas { private Frame f; private double x, y; private int width = 600; private int height = 600; private int originx = 300; private int originy = 299; protected double range = 2.0; protected double scale = width/range; protected int markersize = 5; // Frame // Canvas // Canvas // x // y ( ) // Canvas // ( ) public CGCanvas(String name) { super(); setsize(width, height); setbackground(color.white); setforeground(color.black); // Canvas // ( ) // ( ) f = new Frame(name); // Frame f.add(this); // Frame Canva f.pack(); // f.addwindowlistener(new WindowAdapter() { public void windowclosing(windowevent e) { System.exit(0); ); public void showframe() { f.setvisible(true); // Frame public void setorigin(int x, int y) { originx = x; originy = y; public void setrange(double r) {

30 30 1 Java Dimension d = getsize(); // Canvas width = d.width; height = d.height; range = r; scale = Math.min(width, height) / range; public void drawline(graphics g, Vector2D from, Vector2D to) { g.drawline(x(from), y(from), x(to), y(to)); // public void drawpoint(graphics g, Vector2D point) { g.fillrect(x(point), y(point), 1, 1); // public void drawpolygon(graphics g, Vector2D[] points) { int[] x = new int[points.length]; // ( ) int[] y = new int[points.length]; for (int i = 0; i < points.length; i++) { x[i] = x(points[i]); y[i] = y(points[i]); g.drawpolygon(x, y, points.length); public void drawcircle(graphics g, Vector2D point, int radius) { int dr = (int) (radius * scale); // g.drawoval(x(point) - dr, y(point) - dr, dr * 2, dr * 2); public void drawstring(graphics g, Vector2D point, String str) { g.drawstring(str, x(point), y(point)); // public void fillmarker(graphics g, Vector2D point) { g.fillrect(x(point) - markersize / 2, y(point) - markersize / 2, markersize, markersize); // ( ) public void fillpolygon(graphics g, Vector2D[] points) { int[] x = new int[points.length]; // ( ) int[] y = new int[points.length]; for (int i = 0; i < points.length; i++) { x[i] = x(points[i]); y[i] = y(points[i]); g.fillpolygon(x, y, points.length);

31 1.4. ( ) 2 31 public Vector2D point(int x, int y) { return new Vector2D((x - originx) / scale, (originy - y) / scale); // Canvas protected final int x(vector2d point) { return (int) (scale * point.x()) + originx; // Canvas x protected final int y(vector2d point) { return -(int) (scale * point.y()) + originy; // Canvas y protected final boolean inside(vector2d point) { int x = (int) (scale * point.x()) + originx; if (x < 0 x >= width) return false; int y = -(int) (scale * point.y()) + originy; if (y < 0 y >= height) return false; return true; ( ) - CGDiamondPattern.java CGCanvas import java.awt.*; public class CGDiamondPattern extends CGCanvas { private final static double radius = 0.8; // private Vector2D[] points; private CGDiamondPattern(int numberofpoints) { super("cgdiamondpattern"); // CGCanvas points = new Vector2D[numberOfPoints]; // for (int i = 0; i < numberofpoints; i++) { // double theta = 2.0 * Math.PI * i / numberofpoints; points[i] = new Vector2D(radius*Math.cos(theta), radius*math.sin(theta)); public void paint(graphics g) {

32 32 1 Java for (int i = 0; i < points.length - 1; i++) for (int j = i + 1; j < points.length; j++) drawline(g, points[i], points[j]); // 2 public static void main(string[] args) { if (args.length == 0) System.err.println("Usage: java CGDiamondPattern #"); else (new CGDiamondPattern(Integer.parseInt(args[0]))).showFrame(); 1.5 (Fractal) (self-similarity) (Hausdorff dimension) ( ) (1 ) (2 ) (3 ) n ( ) 1/s s n (Iterated Function System: IFS) Koch.java /3 4 log 3 4 = import java.awt.*; public class Koch extends CGCanvas { private int times; private Vector2D initp0; private Vector2D initp1;

33 : private Matrix2X2[] m; private Vector2D[] v; private Koch(int times) { super("koch"); this.times = times; setorigin(50, 299); setrange(1.2); initp0 = new Vector2D(0.0, 0.0); initp1 = new Vector2D(1.0, 0.0); // CGCanvas // // ( ) // m = new Matrix2X2[4]; v = new Vector2D[4]; m[0] = Matrix2X2.scale(1.0/3.0); // m[1] = Matrix2X2.scale(1.0/3.0). multiply(matrix2x2.rotate(math.pi/3.0)); m[2] = Matrix2X2.scale(1.0/3.0). multiply(matrix2x2.rotate(-math.pi/3.0)); m[3] = Matrix2X2.scale(1.0/3.0);

34 34 1 Java v[0] = new Vector2D(0.0, 0.0); v[1] = m[0].apply(new Vector2D(1.0, 0.0)).add(v[0]); v[2] = m[1].apply(new Vector2D(1.0, 0.0)).add(v[1]); v[3] = m[2].apply(new Vector2D(1.0, 0.0)).add(v[2]); public void paint(graphics g) { drawsegment(g, initp0, initp1, times); private void drawsegment(graphics g, Vector2D p0, Vector2D p1, int l) { if (l > 0) // for (int i = 0; i < m.length; i++) drawsegment(g, m[i].apply(p0).add(v[i]), m[i].apply(p1).add(v[i]), l-1); else // drawline(g, p0, p1); public static void main(string[] args) { if (args.length!= 1) System.err.println("Usage: Koch #iteration"); else (new Koch(Integer.parseInt(args[0]))).showFrame(); - Sierpinski.java 2 4 1/2 3 log 2 3 = import java.awt.*; public class Sierpinski extends CGCanvas { private int times; private Vector2D[] initpoints; private Matrix2X2[] m; private Vector2D[] v; private Sierpinski(int times) {

35 super("sierpinski"); // CGCanvas this.times = times; // setorigin(300, 84); setrange(2.4); initpoints = new Vector2D[3]; // 3 initpoints[0] = new Vector2D( 0.0, 0.0); initpoints[1] = new Vector2D(-1.0, -Math.sqrt(3.0)); initpoints[2] = new Vector2D( 1.0, -Math.sqrt(3.0)); m = new Matrix2X2[3]; v = new Vector2D[3]; m[0] = Matrix2X2.scale(1.0/2.0); // m[1] = Matrix2X2.scale(1.0/2.0); m[2] = Matrix2X2.scale(1.0/2.0); v[0] = new Vector2D( 0.0, 0.0); v[1] = new Vector2D(-0.5, -Math.sqrt(3.0)/2.0); v[2] = new Vector2D( 0.5, -Math.sqrt(3.0)/2.0); public void paint(graphics g) { drawtriangle(g, initpoints, times); private void drawtriangle(graphics g, Vector2D[] points, int l) { if (l > 0) { // for (int i = 0; i < m.length; i++) { Vector2D[] newpoints = new Vector2D[3]; for (int j = 0; j < 3; j++) newpoints[j] = m[i].apply(points[j]).add(v[i]); drawtriangle(g, newpoints, l-1); else { // g.setcolor(color.lightgray); fillpolygon(g, points); g.setcolor(color.black); drawpolygon(g, points);

36 36 1 Java public static void main(string[] args) { if (args.length!= 1) System.err.println("Usage: Sierpinski #iteration"); else (new Sierpinski(Integer.parseInt(args[0]))).showFrame(); 1.6 ( )t ( / ) 1 (parametric curve) x = g(t), y = h(t) { x = r cos t y = r sin t x = 2rt 1+t 2 y = r(1 t2 ) 1+t 2 CG (implicit curve) f(x, y) = 0 x 2 + y 2 r 2 = 0 (function curve) y x y = f(x) y = r 2 x 2 - ParametricCurve.java public interface ParametricCurve { public Vector2D evaluate(double t); public double begin(); public double end(); // - CurveCanvas.java import java.awt.*; public class CurveCanvas extends CGCanvas {

37 final static int NOP = 128; final static double RATIO = 8.0; protected ParametricCurve[] curves; // protected CurveCanvas(String name){ super(name); // CGCanvas protected void drawcurve(graphics g, ParametricCurve curve, double ts, double te, int nofpoints, double borderratio) { double delta = (te - ts)/nofpoints; // te -> ts Vector2D prev = null; // (prev ) boolean previn = false; // (prev ) for (int i = 0; i <= nofpoints; i++) { // nofpoints Vector2D point = curve.evaluate(ts + delta * i); // boolean in = inside(point); // if (prev!= null && (previn in)) drawline(g, prev, point); // 1 prev = point; // previn = in; protected void drawcurve(graphics g, ParametricCurve curve) { drawcurve(g, curve, curve.begin(), curve.end(), NOP, RATIO); public void paint(graphics g) { if (curves!= null) // curves for (int i = 0; i < curves.length; i++) if (curves[i]!= null) drawcurve(g, curves[i]); - DiagonalCanvas.java import java.awt.*; public class DiagonalCanvas extends CurveCanvas {

38 38 1 Java public DiagonalCanvas() { super("diagonal Canvas"); // CurveCanvas setrange(8.0); curves = new ParametricCurve[3]; curves[0] = new Sine(-Math.PI, 0.0); curves[1] = new Cosine(-Math.PI, 0.0); curves[2] = new Tangent(-Math.PI, 0.0); public void paint(graphics g) { g.setcolor(color.blue); // ( ) super.paint(g); // g.setcolor(color.black); // ( ) drawline(g, new Vector2D(-Math.PI, 4.0), new Vector2D(-Math.PI, -4.0)); drawline(g, new Vector2D(-4.0, 0.0), new Vector2D(4.0, 0.0)); // public static void main(string[] args) { new DiagonalCanvas().showFrame(); abstract class Diagonal implements ParametricCurve { protected Vector2D translation; Diagonal(double x, double y) { translation = new Vector2D(x, y); public double begin() { return -0.5 * Math.PI; public double end() { return 2.5 * Math.PI; class Sine extends Diagonal { Sine(double x, double y) { super(x, y); // ParametricCurve

39 public Vector2D evaluate(double t) { // return (new Vector2D(t, Math.sin(t))).add(translation); class Cosine extends Diagonal { Cosine(double x, double y) { super(x, y); // ParametricCurve public Vector2D evaluate(double t) { // return (new Vector2D(t, Math.cos(t))).add(translation); class Tangent extends Diagonal { Tangent(double x, double y) { super(x, y); // ParametricCurve public Vector2D evaluate(double t) { // return (new Vector2D(t, Math.tan(t))).add(translation); (Bézier curve) P 0, P 1,, P n 3 ( 3) P(t) = (1 t) 3 P 0 + 3(1 t) 2 tp 1 + 3(1 t)t 2 P 2 + t 3 P 3 0 t 1 1 (1 t) 3 + 3(1 t) 2 t + 3(1 t)t 2 + t 3 = ((1 t) + t) 3 = 1 t = 0, 1 P(0) = P 0, P(1) = P 3, dp dt (0) = 3(P 1 P 0 ), dp dt (1) = 3(P 3 P 2 ) 3 - CubicBezier.java public class CubicBezier implements ParametricCurve { private Vector2D[] points; //

40 40 1 Java public CubicBezier(Vector2D[] points) { this.points = points; // public Vector2D[] points() { return points; // public Vector2D evaluate(double t) { // double[] ts = new double[4]; ( ) double u = t; ts[0] = u*u*u; ts[1] = 3.0*u*u*t; ts[2] = 3.0*u*t*t; ts[3] = t*t*t; Vector2D point = new Vector2D(0.0, 0.0); for (int j = 0; j <= 3; j++) // 4 point = point.add(points[j].scale(ts[j])); return point; public double begin() { return 0.0; public double end() { return 1.0; - CubicBezierCanvas.java import java.awt.*; public class CubicBezierCanvas extends CurveCanvas { public CubicBezierCanvas() { ( ) super("cubic Bezier Canvas"); public CubicBezierCanvas(Vector2D[] points) { super("cubic Bezier Canvas"); ( ) curves = new ParametricCurve[1]; curves[0] = new CubicBezier(points);

41 public void paint(graphics g) { super.paint(g); // if (curves!= null) // for (int i = 0; i < curves.length; i++) drawpoints(g, ((CubicBezier)curves[i]).points()); private void drawpoints(graphics g, Vector2D[] points) { if (points!= null) { // Color tmpcolor = g.getcolor(); // (tmp) g.setcolor(color.blue); // ( ) fillmarker(g, points[0]); // 1 for (int i = 1; i < points.length; i++) { fillmarker(g, points[i]); drawline(g, points[i - 1], points[i]); g.setcolor(tmpcolor); // (tmp) public static void main(string[] args) { if (args.length!= 8) System.err.println( "Usage: java CubicBezierCanvas x0 y0 x1 y1 x2 y2 x3 y3"); else { Vector2D[] points = new Vector2D[4]; for (int i = 0; i < 4; i++) points[i] = new Vector2D(Double.parseDouble(args[2*i]), Double.parseDouble(args[2*i+1])); (new CubicBezierCanvas(points)).showFrame();

42 42 1 Java 1.7 JOGL OpenGL 3 ( ) C C++ Java JOGL JNI(Java Native Interface) JOGL Java (SDK) JOGL jogl.jar C/C++ JNI (OS ) OS JNI-jar JNI MacOS X jogl-natives-macosx.jar libjogl.jnilib, libjogl cg.jnilib Windows jogl-natives-win32.jar jogl.dll, jogl cg.dll JNI jar JNI-jar MacOS jogl.jar JNI /Library /Java/Extensions ca10101$ jar xf jogl-natives-macosx.jar ca10101$ mkdir ~/Library/Java ca10101$ mkdir ~/Library/Java/Extensions ca10101$ cp jogl.jar ~/Library/Java/Extensions ca10101$ cp libjogl.jnilib ~/Library/Java/Extensions ca10101$ cp libjogl_cg.jnilib ~/Library/Java/Extensions ca10101$ javac File.java ca10101$ java File ( ) 3 OpenGL/JOGL CFIVE jogl.jar JNI (MacOS )

43 : 1. / 3 2. (clipping) 3 (viewing volume) 3 (viewing frustum) (perspective transformation) (window-viewport transformation)

44 44 1 Java 1.8: 7. (rasterization) (JOGL/OpenGL ) ( ) ( ) 1.8 OpenGL void gluperspective(double fieldofview, double aspect, double near, double far); (GL_PROJECTION ) fieldofview y ( ) ( ) aspect xy near far void glulookat(double ex, double ey, double ez, double rx, double ry, double rz, double upx, double upy, double upz); (GL_MODEL_VIEW )

45 ex,ey,ez rx,ry,rz ( ) upx,upy,upz glbegin( ) glend() ( ) GL_POINTS GL_LINES 2 1 GL_LINE_STRIP GL_LINE_LOOP ( ) GL_TRIANGLES 3 1 GL_QUADS 4 1 GL_POLYGON GL_QUAD_STRIP ( ) GL_TRIANGLE_STRIP ( ) GL_TRIANGLE_FAN gl{vertex,color,normal{3,4{i,f,d[v] Vertex,Color,Normal:,, 3,4 : 3 4 i,f,d : int, float, double v : Z ( ) (RGB) (Z) ( ) ( ) JOGL(OpenGL) Z glenable(gl DEPTH TEST) ( glenable(gl CULL FACE)) Z JOGL(OpenGL)

46 46 1 Java P V P 2 P 2 P 3 P 3 P 1 P 1 P 0 P 0 1.9: 1.10: ( ) V 0 = [x 0 y 0 z 0 ] T, V 1 = [x 1 y 1 z 1 ] T V 0 V 1 = x 0 x 1 + y 0 y 1 + z 0 z 1 > 0 V 0, V 1 π 2 V 0 V 1 = 0 < 0 V 0, V 1 π 2 V 0, V 1 π 2 ( ) V 0 = [x 0 y 0 z 0 ] T, V 1 = [x 1 y 1 z 1 ] T y 0 z 1 y 1 z 0 V 0 V 1 = z 0 x 1 z 1 x 0 x 0 y 1 x 1 y 0 V 0, V 1 - CubePosition.java

47 vertices faces y import java.awt.*; import java.awt.event.*; import net.java.games.jogl.*; // jogl public class CubePosition implements GLEventListener { private Frame f; // Frame protected GL gl; // GL protected GLU glu; // GLU protected double eye_x = 4.0, eye_y = 3.0, eye_z = 7.0; // protected CubePosition(String name) { GLCanvas canvas = // JOGL GLCanvas GLDrawableFactory.getFactory(). createglcanvas(new GLCapabilities()); canvas.addgleventlistener(this); // GL f = new Frame(name); // Frame f.add(canvas); // Frame GLCanvas f.setsize(500, 500); f.addwindowlistener(new WindowAdapter() { public void windowclosing(windowevent e) { System.exit(0); ); protected CubePosition(String name, String[] args) { this(name); eye_x = Double.parseDouble(args[0]); // (x ) eye_y = Double.parseDouble(args[1]); // (y ) eye_z = Double.parseDouble(args[2]); // (z ) protected void showframe() { f.setvisible(true); // Frame

48 48 1 Java public void init(gldrawable drawable) { // gl = drawable.getgl(); // GL glu = drawable.getglu(); // GLU gl.glclearcolor(0.0f, 0.0f, 0.0f, 1.0f); // gl.glenable(gl.gl_depth_test); gl.glenable(gl.gl_cull_face); // public void reshape(gldrawable drawable, int x, int y, int w, int h) { final double fieldofview = 25.0, near = 1.0, far = 20.0; // ( ), / double aspect = (double) w / (double) h; // gl.glmatrixmode(gl.gl_projection); // gl.glloadidentity(); // glu.gluperspective(fieldofview, aspect, near, far); gl.glmatrixmode(gl.gl_modelview); // gl.glloadidentity(); // glu.glulookat(eye_x, eye_y, eye_z, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); public void display(gldrawable drawable) { // gl.glclear(gl.gl_color_buffer_bit GL.GL_DEPTH_BUFFER_BIT); cube(); ( ) void cube() { // float[][] vertices = { { -1.0f, -1.0f, -1.0f, { 1.0f, -1.0f, -1.0f, { 1.0f, 1.0f, -1.0f, { -1.0f, 1.0f, -1.0f, { -1.0f, -1.0f, 1.0f, { 1.0f, -1.0f, 1.0f, { 1.0f, 1.0f, 1.0f, { -1.0f, 1.0f, 1.0f ; // int[][] faces = { { 1, 2, 6, 5, { 2, 3, 7, 6, { 4, 5, 6, 7, { 0, 4, 7, 3, { 0, 1, 5, 4, { 0, 3, 2, 1 ; float[][] colors = { { 0.0f, 1.0f, 1.0f, { 1.0f, 0.0f, 1.0f, { 1.0f, 1.0f, 0.0f, { 0.0f, 0.5f, 0.5f, { 0.5f, 0.0f, 0.5f, { 0.5f, 0.5f, 0.0f ; //

49 1.9. (homogeneous coordinates) 49 gl.glbegin(gl.gl_quads); for (int i = 0; i < faces.length; i++) { gl.glcolor3fv(colors[i]); // for (int j = 0; j < faces[i].length; j++) gl.glvertex3fv(vertices[faces[i][j]]); gl.glend(); public void displaychanged(gldrawable drawable, boolean modechanged, boolean devicechanged) { ( ) public static void main(string[] args) { if (args.length == 3) // (new CubePosition("CubePosition Demo", args)).showframe(); else // (new CubePosition("CubePosition Demo")).showFrame(); 1.9 (homogeneous coordinates) P (3) = [x (3) y (3) z (3) ] T R 3 4 P = [x y z w] T R 4 P (3) P x = x (3) w, y = y (3) w, y = y (3) w, w 0 2 [x y z w] T [ x z w w 1]T 3 [ x (3) y (3) z (3) ] T w w w ( ) ( ) M ( ) x P y = z = MP = 1 y w s x s y s y x y z 1 = s x x s y y s z z 1

50 50 1 Java θ x P = x y z 1 = MP = cos θ sin θ 0 0 sin θ cos θ x y z 1 = x y cos θ z sin θ y sin θ + z cos θ 1 y P = x y z 1 = MP = cos θ 0 sin θ sin θ 0 cos θ x y z 1 = x cos θ + z sin θ y x sin θ + z cos θ 1 z P = x y z 1 = MP = cos θ sin θ 0 0 sin θ cos θ x y z 1 = x cos θ y sin θ x sin θ + y cos θ z 1 ( ) P = x y z 1 = MP = t x t y t z x y z 1 = x + t x y + t y z + t z 1 ( ) z x y z P = x y z 1 = MP = d d 0 x y z 1 = x y z 1 d z d xd z yd z d 1 z 1 M 1 M 2 M 3 P = M 1 (M 2 (M 3 P)) = (M 1 M 2 M 3 )P (identity matrix) 1

51 1.9. (homogeneous coordinates) 51 IP = x y z 1 = x y z 1 = P - CubeMatrix.java 1.8 CubePosition GL_MODEL_VIEW 1 import net.java.games.jogl.*; // jogl public class CubeMatrix extends CubePosition { protected CubeMatrix(String name) { super(name); protected CubeMatrix(String name, String[] args) { super(name, args); public void reshape(gldrawable drawable, int x, int y, int w, int h) { final double fieldofview = 25.0, near = 1.0, far = 20.0; // ( ), / double aspect = (double) w / (double) h; // gl.glmatrixmode(gl.gl_projection); // gl.glloadidentity(); // glu.gluperspective(fieldofview, aspect, near, far); gl.glmatrixmode(gl.gl_modelview); // gl.glloadidentity(); // double eye_xz = Math.sqrt(eye_x * eye_x + eye_z * eye_z); double eye_xyz = Math.sqrt(eye_xz * eye_xz + eye_y * eye_y); double[] translate = { // (z ) 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, -eye_xyz, 1.0f ; gl.glmultmatrixd(translate);

52 52 1 Java double sinp = eye_y / eye_xyz, cosp = eye_xz / eye_xyz; double[] rotatex = { // (x ) 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, cosp, sinp, 0.0f, 0.0f, -sinp, cosp, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f ; gl.glmultmatrixd(rotatex); double sint = eye_x / eye_xz, cost = eye_z / eye_xz; double[] rotatey = { // (y ) cost, 0.0f, sint, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, -sint, 0.0f, cost, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f ; gl.glmultmatrixd(rotatey); public static void main(string[] args) { if (args.length == 3) // (new CubeMatrix("CubeMatrix Demo", args)).showframe(); else // (new CubeMatrix("CubeMatrix Demo")).showFrame(); ( ) OpenGL 1 (GL_PROJECTION GL_MODEL_VIEW ) OpenGL ( ) ( A + B) 3. push A pop 4. push B pop A A B B 1.10

53 1.9. (homogeneous coordinates) 53 - CubeAngle.java 10 import net.java.games.jogl.*; // jogl public class CubeAngle extends CubePosition { private double fieldofview = 25.0, near = 1.0, far = 20.0; // ( ), / private float rotx = 20.0f, roty = -30.0f, rotz = 0.0f; // x,y,z CubeAngle(String name) { super(name); CubeAngle(String name, String[] args) { super(name); switch (args.length) { case 1: // fieldofview = Double.parseDouble(args[0]); break; case 2: near = Double.parseDouble(args[0]); far = Double.parseDouble(args[1]); break; case 3: // rotx = Float.parseFloat(args[0]); // x roty = Float.parseFloat(args[1]); // y rotz = Float.parseFloat(args[2]); // z public void reshape(gldrawable drawable, int x, int y, int w, int h) { double aspect = (double) w / (double) h; // gl.glmatrixmode(gl.gl_projection); // gl.glloadidentity(); // glu.gluperspective(fieldofview, aspect, near, far); gl.glmatrixmode(gl.gl_modelview); // gl.glloadidentity(); // gl.gltranslatef(0.0f, 0.0f, -10.0f); // (z )

54 54 1 Java public void display(gldrawable drawable) { // gl.glclear(gl.gl_color_buffer_bit GL.GL_DEPTH_BUFFER_BIT); ( ) gl.glpushmatrix(); // ( ) gl.glrotatef(rotx, 1.0f, 0.0f, 0.0f); // (x ) gl.glrotatef(roty, 0.0f, 1.0f, 0.0f); // (y ) gl.glrotatef(rotz, 0.0f, 0.0f, 1.0f); // (z ) cube(); // gl.glpopmatrix(); public static void main(string[] args) { if (args.length > 0 && args.length < 4) // (new CubeAngle("CubeAngle Demo", args)).showframe(); else // (new CubeAngle("CubeAngle Demo")).showFrame(); 1.10 JOGL Animator Animator (display ) JOGL ( ) JOGL repaint ( ) ( ) ( ) - ObjectRotate.java object()

55 import java.awt.*; import java.awt.event.*; import net.java.games.jogl.*; // jogl public abstract class ObjectRotate implements GLEventListener { private Frame f; // Frame protected GL gl; // GL protected GLU glu; // GLU private double fieldofview = 25.0, near = 1.0, far = 20.0; // ( ), / protected float rotx = 0.0f, roty = 0.0f, rotz = 0.0f; // x,y,z private int prevmousex, prevmousey; private int object; protected abstract void object(); public ObjectRotate(String name) { GLCanvas canvas = // JOGL GLCanvas GLDrawableFactory.getFactory(). createglcanvas(new GLCapabilities()); canvas.addgleventlistener(this); // GL f = new Frame(name); // Frame f.add(canvas); // Frame GLCanvas f.setsize(500, 500); final Animator animator = new Animator(canvas); // Animator f.addwindowlistener(new WindowAdapter() { public void windowclosing(windowevent e) { animator.stop(); // Animator System.exit(0); ); animator.start(); // Animator protected void showframe() { f.setvisible(true); // Frame

56 56 1 Java public void init(gldrawable drawable) { // gl = drawable.getgl(); // GL glu = drawable.getglu(); // GLU gl.glclearcolor(0.0f, 0.0f, 0.0f, 1.0f); // gl.glenable(gl.gl_depth_test); gl.glenable(gl.gl_cull_face); // object = gl.glgenlists(1); gl.glnewlist(object, GL.GL_COMPILE); // object(); // gl.glendlist(); // drawable.addmouselistener(new MouseAdapter() { public void mousepressed(mouseevent e) { prevmousex = e.getx(); prevmousey = e.gety(); ); drawable.addmousemotionlistener(new MouseMotionAdapter() { public void mousedragged(mouseevent e) { int x = e.getx(); int y = e.gety(); Dimension size = e.getcomponent().getsize(); float thetay = 360.0f*((float)(x-prevMouseX)/size.width); float thetax = 360.0f*((float)(prevMouseY-y)/size.height); rotx -= thetax; roty += thetay; prevmousex = x; prevmousey = y; ); public void reshape(gldrawable drawable, int x, int y, int w, int h) { double aspect = (double) w / (double) h; // gl.glmatrixmode(gl.gl_projection); // gl.glloadidentity(); // glu.gluperspective(fieldofview, aspect, near, far);

57 gl.glmatrixmode(gl.gl_modelview); // gl.glloadidentity(); // gl.gltranslatef(0.0f, 0.0f, -10.0f); // (z ) public void display(gldrawable drawable) { // gl.glclear(gl.gl_color_buffer_bit GL.GL_DEPTH_BUFFER_BIT); ( ) gl.glpushmatrix(); // ( ) gl.glrotatef(rotx, 1.0f, 0.0f, 0.0f); // (x ) gl.glrotatef(roty, 0.0f, 1.0f, 0.0f); // (y ) gl.glrotatef(rotz, 0.0f, 0.0f, 1.0f); // (z ) gl.glcalllist(object); gl.glpopmatrix(); public void displaychanged(gldrawable drawable, boolean modechanged, boolean devicechanged) { ( ) - CubeRotate.java ObjectRotate import net.java.games.jogl.*; // jogl public class CubeRotate extends ObjectRotate { public CubeRotate(String name) { super(name); rotx = 20.0f; // (x ) roty = -30.0f; // (y ) protected void object() { // float[][] vertices = { { -1.0f, -1.0f, -1.0f, { 1.0f, -1.0f, -1.0f, { 1.0f, 1.0f, -1.0f, { -1.0f, 1.0f, -1.0f, { -1.0f, -1.0f, 1.0f, { 1.0f, -1.0f, 1.0f, { 1.0f, 1.0f, 1.0f, { -1.0f, 1.0f, 1.0f ; //

58 58 1 Java int[][] faces = { { 1, 2, 6, 5, { 2, 3, 7, 6, { 4, 5, 6, 7, { 0, 4, 7, 3, { 0, 1, 5, 4, { 0, 3, 2, 1 ; float[][] colors = { { 0.0f, 1.0f, 1.0f, { 1.0f, 0.0f, 1.0f, { 1.0f, 1.0f, 0.0f, { 0.0f, 0.5f, 0.5f, { 0.5f, 0.0f, 0.5f, { 0.5f, 0.5f, 0.0f ; // gl.glbegin(gl.gl_quads); for (int i = 0; i < faces.length; i++) { gl.glcolor3fv(colors[i]); // for (int j = 0; j < faces[i].length; j++) gl.glvertex3fv(vertices[faces[i][j]]); gl.glend(); public static void main(string[] args) { (new CubeRotate("Cube Rotate")).showFrame(); - ConesWire.java gl.glpushmatrix() gl.glpopmatrix() ( ) Z import net.java.games.jogl.*; // jogl public class ConesWire extends ObjectRotate { public ConesWire(String name) { super(name); protected void object() { final int NOP = 16; // float[] foreground = { 1.0f, 1.0f, 0.0f ; // ( ) gl.glcolor3fv(foreground); // for (int i = 0; i < NOP; i++) { double t = 2.0 * Math.PI * i / NOP; // 2PI n gl.glpushmatrix(); // ( ) gl.gltranslated(1.6*math.cos(t), 1.6*Math.sin(t), 0.0);

59 gl.glscalef(0.3f, 0.3f, 1.4f); conewire(); gl.glpopmatrix(); // 1.6 // protected void conewire() { final int NOP = 16; float[] apex = { 0.0f, 0.0f, 1.0f ; float[][] circle = new float[nop][]; for (int i = 0; i < NOP; i++) { double t = 2.0 * Math.PI * i / NOP; // 2PI n circle[i] = new float[3]; circle[i][0] = (float)math.cos(t); circle[i][1] = (float)math.sin(t); circle[i][2] = -1.0f; gl.glbegin(gl.gl_line_loop); for (int i = 0; i < NOP; i++) gl.glvertex3fv(circle[nop-i-1]); gl.glend(); gl.glbegin(gl.gl_lines); for (int i = 0; i < NOP; i++) { gl.glvertex3fv(apex); // gl.glvertex3fv(circle[i]); // gl.glend(); public static void main(string[] args) { (new ConesWire("Cones Wire")).showFrame(); Z Z - ConesHiddenLine.java

60 60 1 Java ConesWire ( ) import net.java.games.jogl.*; // jogl public class ConesHiddenLine extends ConesWire { public ConesHiddenLine(String name) { super(name); public void init(gldrawable drawable) { // super.init(drawable); gl.glenable(gl.gl_polygon_offset_fill); gl.glpolygonoffset(1.0f, 1.0f); protected void object() { final int NOP = 16; // float[] background = { 0.0f, 0.0f, 0.0f ; // ( ) float[] foreground = { 1.0f, 1.0f, 0.0f ; // ( ) for (int i = 0; i < NOP; i++) { double t = 2.0 * Math.PI * i / NOP; // 2PI n gl.glpushmatrix(); // ( ) gl.gltranslated(1.6*math.cos(t), 1.6*Math.sin(t), 0.0); // 1.6 gl.glscalef(0.3f, 0.3f, 1.4f); // gl.glcolor3fv(foreground); // conewire(); gl.glcolor3fv(background); // conepolygon(); // gl.glpopmatrix(); private void conepolygon() { final int NOP = 16; float[] apex = { 0.0f, 0.0f, 1.0f ; float[][] circle = new float[nop+1][]; for (int i = 0; i <= NOP; i++) { double t = 2.0 * Math.PI * i / NOP; // 2PI n

61 circle[i] = new float[3]; circle[i][0] = (float)math.cos(t); circle[i][1] = (float)math.sin(t); circle[i][2] = -1.0f; gl.glbegin(gl.gl_polygon); for (int i = 0; i < NOP; i++) gl.glvertex3fv(circle[nop-i-1]); // gl.glend(); gl.glbegin(gl.gl_triangle_fan); gl.glvertex3fv(apex); // for (int i = 0; i <= NOP; i++) { // gl.glvertex3fv(circle[i]); // gl.glend(); public static void main(string[] args) { (new ConesHiddenLine("Cones HiddenLine")).showFrame(); JOGL(OpenGL) 3 RGB CMY HSB(HSV) RGB - ColorCube.java import net.java.games.jogl.*; // jogl public class ColorCube extends ObjectRotate { public ColorCube(String name) { super(name); protected void object() { // RGB float[][] vertices = { { -1.0f, -1.0f, -1.0f, { 1.0f, -1.0f, -1.0f, { 1.0f, 1.0f, -1.0f,

62 62 1 Java { -1.0f, 1.0f, -1.0f, { -1.0f, -1.0f, 1.0f, { 1.0f, -1.0f, 1.0f, { 1.0f, 1.0f, 1.0f, { -1.0f, 1.0f, 1.0f ; // float[][] colors = { { 0.0f, 0.0f, 0.0f, { 1.0f, 0.0f, 0.0f, { 1.0f, 1.0f, 0.0f, { 0.0f, 1.0f, 0.0f, { 0.0f, 0.0f, 1.0f, { 1.0f, 0.0f, 1.0f, { 1.0f, 1.0f, 1.0f, { 0.0f, 1.0f, 1.0f ; int[][] faces = { { 1, 2, 6, 5, { 2, 3, 7, 6, { 4, 5, 6, 7, { 0, 4, 7, 3, { 0, 1, 5, 4, { 0, 3, 2, 1 ; // gl.glbegin(gl.gl_quads); for (int i = 0; i < faces.length; i++) { for (int j = 0; j < faces[i].length; j++){ gl.glcolor3fv(colors[faces[i][j]]); gl.glvertex3fv(vertices[faces[i][j]]); gl.glend(); public static void main(string[] args) { (new ColorCube("Color Cube")).showFrame(); 1.11 ( ) RGB (ambient)

63 L n M V 1.11: ( ) I a k a I a k a (diffuse) ( ) L n θ cos θ ( 1.11 ) 2 L, n ( ) (Lambert) I d k d cos θ = I d k d nl I d k d (specular) L n ( 1.11 ) M = (L + V)/ L + V n α cos α 2 I s k s cos n α = I s k s (nm) n I s k s n (shininess ) ( ) OpenGL ( ) RGB I a k a + I d k d nl + I s k s (nm) n

64 64 1 Java void gllightfv(enum light, enum pname, const float *params); light (GL_LIGHTi) pname (GL.GL_AMBIENT, GL.GL_DIFFUSE, GL.GL_SPECULAR ) params void glmaterialfv(enum face, enum pname, const float *params); ( vertex ) face (GL.GL_FRONT, GL.GL_BACK, GL.GL_FRONT_AND_BACK) pname (GL.GL_AMBIENT, GL.GL_DIFFUSE, GL.GL_SPECULAR ) params void glnormal3dv(double v[3]); ( vertex ) v ( ) gl.glenable(gl.gl_normalize) - ObjectShade.java ObjectRotate object() import net.java.games.jogl.*; // jogl public abstract class ObjectShade extends ObjectRotate { protected float[] lightposition = { 5.0f, 5.0f, 10.0f, 0.0f ; // protected float[] lightambient = { 0.2f, 0.2f, 0.2f, 1.0f ; protected float[] lightdiffuse = { 1.0f, 1.0f, 1.0f, 1.0f ; protected float[] lightspecular = { 0.9f, 0.9f, 0.9f, 1.0f ; public ObjectShade(String name) { super(name); public void init(gldrawable drawable) { // super.init(drawable); // init gl.gllightfv(gl.gl_light0, GL.GL_POSITION, lightposition); // gl.gllightfv(gl.gl_light0, GL.GL_AMBIENT, lightambient);

65 // gl.gllightfv(gl.gl_light0, GL.GL_DIFFUSE, lightdiffuse); // gl.gllightfv(gl.gl_light0, GL.GL_SPECULAR, lightspecular); // gl.glenable(gl.gl_lighting); gl.glenable(gl.gl_light0); // gl.glenable(gl.gl_normalize); - CubeShade.java ObjectShade (material) import net.java.games.jogl.*; // jogl public class CubeShade extends ObjectShade { public CubeShade(String name) { super(name); rotx = 20.0f; // (x ) roty = -30.0f; // (y ) protected void object() { // float[][] vertices = { { -1.0f, -1.0f, -1.0f, { 1.0f, -1.0f, -1.0f, { 1.0f, 1.0f, -1.0f, { -1.0f, 1.0f, -1.0f, { -1.0f, -1.0f, 1.0f, { 1.0f, -1.0f, 1.0f, { 1.0f, 1.0f, 1.0f, { -1.0f, 1.0f, 1.0f ; // int[][] faces = { { 1, 2, 6, 5, { 2, 3, 7, 6, { 4, 5, 6, 7, { 0, 4, 7, 3, { 0, 1, 5, 4, { 0, 3, 2, 1 ; float[][] normals = { { 1.0f, 0.0f, 0.0f, { 0.0f, 1.0f, 0.0f, { 0.0f, 0.0f, 1.0f, { -1.0f, 0.0f, 0.0f, { 0.0f, -1.0f, 0.0f, { 0.0f, 0.0f, -1.0f ; float[] diffuse = { 0.8f, 0.8f, 0.2f, 1.0f ; float[] specular = { 0.9f, 0.9f, 0.9f, 1.0f ;

66 66 1 Java gl.glmaterialfv(gl.gl_front, GL.GL_AMBIENT_AND_DIFFUSE, diffuse); gl.glmaterialfv(gl.gl_front, GL.GL_SPECULAR, specular); gl.glmaterialf(gl.gl_front, GL.GL_SHININESS, 100.0f); // shininess gl.glshademodel(gl.gl_flat); gl.glbegin(gl.gl_quads); for (int i = 0; i < faces.length; i++) { gl.glnormal3fv(normals[i]); // ( ) for (int j = 0; j < faces[i].length; j++) gl.glvertex3fv(vertices[faces[i][j]]); gl.glend(); public static void main(string[] args) { (new CubeShade("Cube Shade")).showFrame(); 20 - IcosahedronShade.java ObjectShade import net.java.games.jogl.*; // jogl public class IcosahedronShade extends ObjectShade { public IcosahedronShade(String name) { super(name); protected void object() { // 20 float[] diffuse = { 0.8f, 0.3f, 0.8f, 1.0f ; float[] specular = { 0.9f, 0.9f, 0.9f, 1.0f ; gl.glmaterialfv(gl.gl_front, GL.GL_AMBIENT_AND_DIFFUSE, diffuse); gl.glmaterialfv(gl.gl_front, GL.GL_SPECULAR, specular); gl.glmaterialf(gl.gl_front, GL.GL_SHININESS, 100.0f);

67 // shininess final float R = (float)math.sqrt(2.0); // final float X = (float)((math.sqrt(5.0) + 1.0) / 2.0); final float Y = (float)(r / Math.sqrt(1.0 + X*X)); final float Z = (float)(x * Y); float[][] vertices = // 20 { { 0.0f, Y, Z, { 0.0f, -Y, Z, { 0.0f, -Y, -Z, { 0.0f, Y, -Z, { Z, 0.0f, Y, { Z, 0.0f, -Y, { -Z, 0.0f, -Y, { -Z, 0.0f, Y, { Y, Z, 0.0f, { -Y, Z, 0.0f, { -Y, -Z, 0.0f, { Y, -Z, 0.0f ; int[][] faces = { { 0, 1, 4, { 0, 4, 8, { 0, 8, 9, { 0, 9, 7, { 0, 7, 1, { 1, 10, 11, { 1, 11, 4, { 4, 11, 5, { 4, 5, 8, { 8, 5, 3, { 8, 3, 9, { 9, 3, 6, { 9, 6, 7, { 7, 6, 10, { 7, 10, 1, { 2, 10, 6, { 2, 6, 3, { 2, 3, 5, { 2, 5, 11, { 2, 11, 10 ; gl.glshademodel(gl.gl_flat); gl.glbegin(gl.gl_triangles); for (int i = 0; i < faces.length; i++) { gl.glnormal3fv(normal(vertices[faces[i][0]], vertices[faces[i][1]], vertices[faces[i][2]])); // ( ) for (int j = 0; j < faces[i].length; j++) gl.glvertex3fv(vertices[faces[i][j]]); gl.glend(); private float[] normal(float[] pnt0, float[] pnt1, float[] pnt2) { return crossproduct(subtract(pnt1, pnt0), subtract(pnt2, pnt0)); - 2 private float[] subtract(float[] vec0, float[] vec1) { float[] answer = new float[3]; for (int i = 0; i < 3; i++) answer[i] = vec0[i] - vec1[i]; return answer; private float[] crossproduct(float[] vec0, float[] vec1) {

68 68 1 Java float[] answer = new float[3]; answer[0] = vec0[1] * vec1[2] - vec0[2] * vec1[1]; answer[1] = vec0[2] * vec1[0] - vec0[0] * vec1[2]; answer[2] = vec0[0] * vec1[1] - vec0[1] * vec1[0]; return answer; public static void main(string[] args) { (new IcosahedronShade("Icosahedron Shade")).showFrame(); - SubdivideShade.java ( ) import net.java.games.jogl.*; // jogl public class SubdivideShade extends ObjectShade { static int depth = 0; public SubdivideShade(String name) { super(name); protected void object() { float[] diffuse = { 0.8f, 0.3f, 0.8f, 1.0f ; float[] specular = { 0.9f, 0.9f, 0.9f, 1.0f ; gl.glmaterialfv(gl.gl_front, GL.GL_AMBIENT_AND_DIFFUSE, diffuse); gl.glmaterialfv(gl.gl_front, GL.GL_SPECULAR, specular); gl.glmaterialf(gl.gl_front, GL.GL_SHININESS, 100.0f); // shininess final float R = (float)math.sqrt(2.0); // final float X = (float)((math.sqrt(5.0) + 1.0) / 2.0);

69 final float Y = (float)(r / Math.sqrt(1.0 + X*X)); final float Z = (float)(x * Y); float[][] vertices = // 20 { { 0.0f, Y, Z, { 0.0f, -Y, Z, { 0.0f, -Y, -Z, { 0.0f, Y, -Z, { Z, 0.0f, Y, { Z, 0.0f, -Y, { -Z, 0.0f, -Y, { -Z, 0.0f, Y, { Y, Z, 0.0f, { -Y, Z, 0.0f, { -Y, -Z, 0.0f, { Y, -Z, 0.0f ; int[][] faces = { { 0, 1, 4, { 0, 4, 8, { 0, 8, 9, { 0, 9, 7, { 0, 7, 1, { 1, 10, 11, { 1, 11, 4, { 4, 11, 5, { 4, 5, 8, { 8, 5, 3, { 8, 3, 9, { 9, 3, 6, { 9, 6, 7, { 7, 6, 10, { 7, 10, 1, { 2, 10, 6, { 2, 6, 3, { 2, 3, 5, { 2, 5, 11, { 2, 11, 10 ; for (int i = 0; i < faces.length; i++) { subdivide(vertices[faces[i][0]], vertices[faces[i][1]], vertices[faces[i][2]], depth); // 20 protected void subdivide (float[] pnt0, float[] pnt1, float[] pnt2, int depth) { if (depth == 0) { // gl.glshademodel(gl.gl_flat); gl.glbegin(gl.gl_triangles); gl.glnormal3fv(normal(pnt0, pnt1, pnt2)); // gl.glvertex3fv(pnt0); // gl.glvertex3fv(pnt1); gl.glvertex3fv(pnt2); gl.glend(); else { float[] pnt01 = split(pnt0, pnt1); // 2 float[] pnt12 = split(pnt1, pnt2); float[] pnt20 = split(pnt2, pnt0); subdivide(pnt0, pnt01, pnt20, depth-1); subdivide(pnt1, pnt12, pnt01, depth-1); subdivide(pnt2, pnt20, pnt12, depth-1); subdivide(pnt01, pnt12, pnt20, depth-1); // 4

70 70 1 Java private float[] normal(float[] pnt0, float[] pnt1, float[] pnt2) { float[] answer = new float[3]; for (int i = 0; i < 3; i++) answer[i] = pnt0[i] + pnt1[i] + pnt2[i]; return answer; protected float[] split(float[] pnt0, float[] pnt1) { float[] ans = new float[3]; // for (int i = 0; i < 3; i++) ans[i] = pnt0[i] + pnt1[i]; float ratio = (float)(math.sqrt(2.0) / Math.sqrt(ans[0]*ans[0]+ans[1]*ans[1]+ans[2]*ans[2])); for (int i = 0; i < 3; i++) ans[i] *= ratio; return ans; public static void main(string[] args) { if (args.length == 1) depth = Integer.parseInt(args[0]); (new SubdivideShade("Subdivide Shade")).showFrame(); ( ) ( ) ( ) (Phong) ( ) (Gouraud) 2 OpenGL ( ) - SphereShade.java 4 20 import net.java.games.jogl.*;

71 public class SphereShade extends SubdivideShade { public SphereShade(String name) { super(name); protected void subdivide (float[] pnt0, float[] pnt1, float[] pnt2, int depth) { if (depth == 0) { // gl.glshademodel(gl.gl_smooth); gl.glbegin(gl.gl_triangles); gl.glnormal3fv(pnt0); // ( ) gl.glvertex3fv(pnt0); // gl.glnormal3fv(pnt1); gl.glvertex3fv(pnt1); gl.glnormal3fv(pnt2); gl.glvertex3fv(pnt2); gl.glend(); else { float[] pnt01 = split(pnt0, pnt1); // 2 float[] pnt12 = split(pnt1, pnt2); float[] pnt20 = split(pnt2, pnt0); subdivide(pnt0, pnt01, pnt20, depth-1); subdivide(pnt1, pnt12, pnt01, depth-1); subdivide(pnt2, pnt20, pnt12, depth-1); subdivide(pnt01, pnt12, pnt20, depth-1); // 4 public static void main(string[] args) { if (args.length == 1) depth = Integer.parseInt(args[0]); (new SphereShade("Sphere Shade")).showFrame();

72

73 73 2 V , 2, 3, 4, n n 2 (1.1 x y 2.1:

74 74 2 V

75 , 2, ( /CMY ) (CMY ) (RGB ) 1.4 ( (1.1) 5 ) White (0 0 0) Cyan (1 0 0) x=300, y=225 Magenta (0 1 0) x=213.4, y=375 Blue Green (1 1 0) (1 0 1) Black (1 1 1) Red (0 1 1) Yellow (0 0 1) x=386.6, y= : 3 (CMY ) 2.5 HSB HSB (S = 1, B = 1 ) HSB HSB HSB 2.3

76 76 2 V 2.3:

Chapter JDK KeyListener keypressed(keyevent e ) keyreleased(keyevent e ) keytyped(keyevent e ) MouseListener mouseclicked(mouseeven

Chapter JDK KeyListener keypressed(keyevent e ) keyreleased(keyevent e ) keytyped(keyevent e ) MouseListener mouseclicked(mouseeven Chapter 11. 11.1. JDK1.1 11.2. KeyListener keypressed(keyevent e ) keyreleased(keyevent e ) keytyped(keyevent e ) MouseListener mouseclicked(mouseevent e ) mousepressed(mouseevent e ) mousereleased(mouseevent

More information

3D 描画 Step2 マウスで回転できるようにする ベクトル (a, b, c) を軸として右回りに rot 度の回転は glrotatef(rot, a, b, c); で実行される 従って 座標軸の回転はそれぞれ x 軸まわり,y 軸まわりの回転量 (degree で表す ) を rotx, roty をとすると x 軸まわりの回転は glrotatef(rotx, 1.0f, 0.0f, 0.0f);

More information

KeyListener init addkeylistener addactionlistener addkeylistener addkeylistener( this ); this.addkeylistener( this ); KeyListener public void keytyped

KeyListener init addkeylistener addactionlistener addkeylistener addkeylistener( this ); this.addkeylistener( this ); KeyListener public void keytyped KeyListener keypressed(keyevent e) keyreleased(keyevent e) keytyped(keyevent e) MouseListener mouseclicked(mouseevent e) mousepressed(mouseevent e) mousereleased(mouseevent e) mouseentered(mouseevent e)

More information

このような 回転や平行移動による座標変換の情報は ModelView 行列 が持っている ModelView 行列は gl.glpushmatrix() でいったん保存しておき 回転や平行移動を重ねて描画した後 gl.glpopmatrix() で保存した状態に戻すことができる ワールド座標系とウィ

このような 回転や平行移動による座標変換の情報は ModelView 行列 が持っている ModelView 行列は gl.glpushmatrix() でいったん保存しておき 回転や平行移動を重ねて描画した後 gl.glpopmatrix() で保存した状態に戻すことができる ワールド座標系とウィ 3D 描画 Step3 元素名を 2D 描画する OpenGL には文字描画の概念がないこと 元素名は回転してほしくないことの 2 点の理由から 元素名は 2D 描画する そのために 原子の 3 次元空間の座標から 文字を描画するウィンドウ上の座標を求める < 座標変換について > 座標変換について まとまった詳しい解説は OpenGL による 3D 描画の基礎知識 の 3 ページ以降に記述してあるので

More information

r3.dvi

r3.dvi 10 3 2010.9.21 1 1) 1 ( 1) 1: 1) 1.0.1 : Java 1 import java.awt.*; import javax.swing.*; public class Sample21 extends JPanel { public void paintcomponent(graphics g) { g.setcolor(new Color(255, 180, 99));

More information

I 4 p.2 4 GUI java.awt.event.* import /* 1 */ import mouseclicked MouseListener implement /* 2 */ init addmouselistener(this) this /* 3 */ this mousec

I 4 p.2 4 GUI java.awt.event.* import /* 1 */ import mouseclicked MouseListener implement /* 2 */ init addmouselistener(this) this /* 3 */ this mousec I 4 p.1 4 GUI GUI GUI 4.1 4.1.1 MouseTest.java /* 1 */ public class MouseTest extends JApplet implements MouseListener /* 2 */ { int x=50, y=20; addmouselistener(this); /* 3 */ public void mouseclicked(mouseevent

More information

r2.dvi

r2.dvi 2002 2 2003.1.29 1 2.1-2.3 (1) (2) 2.4-2.6 (1)OO (2)OO / 2.7-2.10 (1)UML (2) Java 3.1-3.3 (1) (2)GoF (3)WebSphere (4) 3.4-3.5 3.6-3.9 Java (?) 2/12( ) 20:00 2 (2 ) 3 Java (?)1 java.awt.frame Frame 1 import

More information

I. (i) Foo public (A). javac Foo.java java Foo.class (C). javac Foo java Foo (ii)? (B). javac Foo.java java Foo (D). javac Foo java Foo.class (A). Jav

I. (i) Foo public (A). javac Foo.java java Foo.class (C). javac Foo java Foo (ii)? (B). javac Foo.java java Foo (D). javac Foo java Foo.class (A). Jav 2018 06 08 11:00 12:00 I. I III II. III. IV. ( a d) V. VI. 80 40 40 100 60 : A ActionListener aa addactionlistener AE ActionEvent K KeyListener ak addkeylistener KE KeyEvent M MouseListener am addmouselistener

More information

r3.dvi

r3.dvi 00 3 2000.6.10 0 Java ( 7 1 7 1 GSSM 1? 1 1.1 4 4a 4b / / 0 255 HTML X 0 255 16 (0,32,255 #0020FF Java xclock -bg #0020FF xclock ^C (Control C xclock 4c 1 import java.applet.applet; import java.awt.*;

More information

やさしいJavaプログラミング -Great Ideas for Java Programming サンプルPDF

やさしいJavaプログラミング -Great Ideas for Java Programming サンプルPDF pref : 2004/6/5 (11:8) pref : 2004/6/5 (11:8) pref : 2004/6/5 (11:8) 3 5 14 18 21 23 23 24 28 29 29 31 32 34 35 35 36 38 40 44 44 45 46 49 49 50 pref : 2004/6/5 (11:8) 50 51 52 54 55 56 57 58 59 60 61

More information

3D 描画 Step1-1 まず O 原子となる球を 1 つ描画する <WaterPanel.java の作成 > 1.Chemical プロジェクトをインポート 共有フォルダから Chemical.zip をコピーして workspace 内にはりつけ パッケージ エクスプローラで右クリック イン

3D 描画 Step1-1 まず O 原子となる球を 1 つ描画する <WaterPanel.java の作成 > 1.Chemical プロジェクトをインポート 共有フォルダから Chemical.zip をコピーして workspace 内にはりつけ パッケージ エクスプローラで右クリック イン GUI プログラミング第 4 回演習 3DChemical ~ OpenGL(JOGL) による 3D 描画 : 水の化学式モデルを書いてみる ~ 104.45 実際は背景は黒くする 1.eclipse.zip を D: ドライブにコピーし 右クリック ここに解凍 2.workspace を S: ドライブから D: ドライブにコピー 3.eclipse.exe を起動

More information

(Microsoft PowerPoint - \223\306\217KJAVA\221\346\202R\224\ ppt)

(Microsoft PowerPoint - \223\306\217KJAVA\221\346\202R\224\ ppt) 独習 Java 第 3 版 14.1 代行イベントモデル 14.2 イベントクラス 14.3 イベントリスナ 14.1 代行イベントモデル (1/3) アプレットは GUI を提供する GUI ベースのプログラムはイベントドリブンであり コンソールアプリケーションはイベントドリブンでない イベントドリブンとは ユーザや他のプログラムが実行した操作 ( イベント ) に対応して処理を行なうプログラムの実行形式

More information

Applet java.lang.object java.awt.component java.awt.container java.awt.panel java.applet.applet

Applet java.lang.object java.awt.component java.awt.container java.awt.panel java.applet.applet 13 Java 13.9 Applet 13.10 AppletContext 13.11 Applet java.lang.object java.awt.component java.awt.container java.awt.panel java.applet.applet Applet (1/2) Component GUI etc Container Applet (2/2) Panel

More information

r14.dvi

r14.dvi 2007 14 2008.1.29 1 1.1 (Ruby Java ) 1 (thread) 1 ( 1 ) main main 1: 1 ( 1 ) CPU CPU 1 while(true) { 0.1 0.1 GUI CPU 1 OS 1.2 Java Java Thread new start()? Thread 0 run() Thread run() run() start() Java

More information

Chapter 20. [ ] ; [ ] = new [ ] ; Color colors [ ] = new Color[ 20 ]; // 20 Button operations [ ] = new Button[ 10 ]; // 10 colors[ 3 ] = new Color( 1

Chapter 20. [ ] ; [ ] = new [ ] ; Color colors [ ] = new Color[ 20 ]; // 20 Button operations [ ] = new Button[ 10 ]; // 10 colors[ 3 ] = new Color( 1 Chapter 20. [ ] ; [ ] = new [ ] ; Color colors [ ] = new Color[ 20 ]; // 20 Button operations [ ] = new Button[ 10 ]; // 10 colors[ 3 ] = new Color( 10, 30, 40 ); gc.setcolor( colors[ 3 ] ); operations[

More information

以下に java.awt.graphics クラスの主なメソッドを示す (Graphics クラスの ) メソッド drawline(int x1, int y1, int x2, int y2) drawrect(int x, int y, int width, int height) fillr

以下に java.awt.graphics クラスの主なメソッドを示す (Graphics クラスの ) メソッド drawline(int x1, int y1, int x2, int y2) drawrect(int x, int y, int width, int height) fillr 第 5 章グラフィックス, スレッドとマウスイベントによる描画処理 描画処理およびマルチスレッドの基礎についてそれぞれ理解し,Java を用いてイベント処理を組み合わせたプログラムを作成する 5.1 描画処理 最初に, パネル上にグラフィックス描画を行う方法について説明する グラフィックスを表示するにはフレームにパネルを配置し, 処理内容を paintcomponent メソッド内に記述する paintcomponent

More information

Java学習教材

Java学習教材 Java 2016/4/17 Java 1 Java1 : 280 : (2010/1/29) ISBN-10: 4798120987 ISBN-13: 978-4798120980 2010/1/29 1 Java 1 Java Java Java class FirstExample { public static void main(string[] args) { System.out.println("

More information

Java演習(4) -- 変数と型 --

Java演習(4)   -- 変数と型 -- 50 20 20 5 (20, 20) O 50 100 150 200 250 300 350 x (reserved 50 100 y 50 20 20 5 (20, 20) (1)(Blocks1.java) import javax.swing.japplet; import java.awt.graphics; (reserved public class Blocks1 extends

More information

5 p Point int Java p Point Point p; p = new Point(); Point instance, p Point int 2 Point Point p = new Point(); p.x = 1; p.y = 2;

5 p Point int Java p Point Point p; p = new Point(); Point instance, p Point int 2 Point Point p = new Point(); p.x = 1; p.y = 2; 5 p.1 5 JPanel (toy example) 5.1 2 extends : Object java.lang.object extends... extends Object Point.java 1 public class Point { // public int x; public int y; Point x y 5.1.1, 5 p.2 5 5.2 Point int Java

More information

Assignment_.java /////////////////////////////////////////////////////////////////////// // 課題 星の画像がマウスカーソルを追従するコードを作成しなさい 次 ///////////////////

Assignment_.java /////////////////////////////////////////////////////////////////////// // 課題 星の画像がマウスカーソルを追従するコードを作成しなさい 次 /////////////////// Assignment_.java 0 0 0 0 0 /////////////////////////////////////////////////////////// // 課題 次のようにマウスのカーソルに同期しメッセージを /////////////////////////////////////////////////////////// class Assignment_ extends

More information

2 p.2 2 Java Hello0.class JVM Hello0 java > java Hello0.class Hello World! javac Java JVM java JVM : Java > javac 2> Q Foo.java Java : Q B

2 p.2 2 Java Hello0.class JVM Hello0 java > java Hello0.class Hello World! javac Java JVM java JVM : Java > javac 2> Q Foo.java Java : Q B 2 p.1 2 Java Java JDK Sun Microsystems JDK javac Java java JVM appletviewer IDESun Microsystems NetBeans, IBM 1 Eclipse 2 IDE GUI JDK Java 2.1 Hello World! 2.1.1 Java 2.1.1 Hello World Emacs Hello0.java

More information

Java演習(9) -- クラスとメソッド --

Java演習(9)   -- クラスとメソッド -- Java (9) Java (9) Java (9) 3 (x, y) x 1 30 10 (0, 50) 1 2 10 10 (width - 10, 80) -2 3 50 10 (width / 2, 110) 2 width 3 (RectMove4-1.java) import javax.swing.japplet; import javax.swing.timer; import java.awt.graphics;

More information

PowerPoint Presentation

PowerPoint Presentation 上級プログラミング 2( 第 3 回 ) 工学部情報工学科 木村昌臣 今日のテーマ GUI プログラミング入門 AWT Java で GUI を作る方法 (API) AWT Abstract Window Toolkit GUIをつくるクラス群を提供 ( 基本!) OSによらない外観 Swing 逆にいえば OS ネイティブな look and feel ではない AWT をもとに JavaFX JDK1.8

More information

B02-095 2007 2 15 1 3 2 4 2.1............................. 4 2.2........................................ 5 2.3........................................ 6 3 7 3.1................................. 7 3.2..............................

More information

I. (i) Java? (A). Foo_Bar (B). G day (C). 999 (D). Golgo13 (ii)? (A). Java public (B). Java (C). Java JavaScript (D). Java C Java C (iii)? (A). Java (

I. (i) Java? (A). Foo_Bar (B). G day (C). 999 (D). Golgo13 (ii)? (A). Java public (B). Java (C). Java JavaScript (D). Java C Java C (iii)? (A). Java ( 2016 07 29 10:30 12:00 I. I V II. III. IV. ( a d) V. VI. 80 100 60 : A ActionListener aa addactionlistener AE ActionEvent K KeyListener ak addkeylistener KE KeyEvent M MouseListener am addmouselistener

More information

JOGLによるOpenGL入門

JOGLによるOpenGL入門 OpenGL と GLUT を組み合わせれば UNIX 系 OS(Linux FreeBSD 等を含む ) と Windows と Mac のいずれでも動く リアルタイムに三次元表示を行うプログラムが とっても簡単に書けてしまう という三拍子そろったメリットが得られます org.jogamp.jogl jogl-all-main 2.*.* grep -lr 'javax\.media\.opengl'

More information

問1

問1 2008/12/10 OOP 同演習小テスト問題 問 1. 次のプログラムの出力結果を a~d の中から選べ public class Problem1 { public static void main(string[] args){ int i =2; int j =3; System.out.println( i + j ); a) 23 b) 5 c) ij d) i+j 問 2. 次のプログラムの出力結果を

More information

I HTML HashMap (i) (ii) :.java import java.net.*; import java.io.*; import java.util.hashmap; public class SimpleStopWatch { public static voi

I HTML HashMap (i) (ii) :.java import java.net.*; import java.io.*; import java.util.hashmap; public class SimpleStopWatch { public static voi II Java 10 2 12 10:30 12:00 I. I III II. III. IV. ( a d) V. : this==null, T == N A ActionListener C class D actionperformed G getsource I implements K KeyListener J JApplet L addmouselistener M MouseListener

More information

r2.dvi

r2.dvi 2 /Fitzz 2012.10.16 1 Reading 1.1 HCI bit ( ) HCI ( ) ( ) ( ) HCI ( ) HCI ( ) ^_^; 1 1.2,,!,, 2000 1.3 D. A.,,?,, 1990 1? 1 (interface) ( ) ( / ) (User Interface, UI) 2 :? import java.awt.*; import java.awt.event.*;

More information

II Java :30 12:00 I. I IV II. III. IV. ( a d) V. : this==null, T == N A ActionListener C class D actionperformed G getsource I implements K

II Java :30 12:00 I. I IV II. III. IV. ( a d) V. : this==null, T == N A ActionListener C class D actionperformed G getsource I implements K II Java 09 2 13 10:30 12:00 I. I IV II. III. IV. ( a d) V. : this==null, T == N A ActionListener C class D actionperformed G getsource I implements K KeyListener J JApplet L addmouselistener M MouseListener

More information

r4.dvi

r4.dvi 00 4 2000.6.24 0 GUI GUI GUI GUI 1 1.1 3 2 1 import java.applet.applet; import java.awt.*; public class r3ex2 extends Applet { Figure[] figs = new Figure[]{ new Circle(Color.blue, 100.0, 100.0, 30.0, 1.1,

More information

r6.dvi

r6.dvi I 2005 6 2005.11.18 1 1.1 2 Hello, World public class r5ex2 extends JApplet { Font fn = new Font("Helvetica", Font.BOLD, 24); g2.setfont(fn); for(int i = 0; i < 10; ++i) { g2.setpaint(new Color(100+i*5,

More information

I. java.awt.rectangle java.lang.math random Java TM API java.awt Rectangle Rectangle (x,y)... public int x Rectangle X public int y Rectangle Y public

I. java.awt.rectangle java.lang.math random Java TM API java.awt Rectangle Rectangle (x,y)... public int x Rectangle X public int y Rectangle Y public 2018 08 03 10:30 12:00 I. IV III II. III. IV. ( a d) V. VI. 70 III 30 100 60 : A ActionListener aa addactionlistener AE ActionEvent K KeyListener ak addkeylistener KE KeyEvent M MouseListener am addmouselistener

More information

I. (i) Java? (A). 2Apples (B). Vitamin-C (C). Peach21 (D). Pine_Apple (ii) Java? (A). Java (B). Java (C). Java (D). JavaScript Java JavaScript Java (i

I. (i) Java? (A). 2Apples (B). Vitamin-C (C). Peach21 (D). Pine_Apple (ii) Java? (A). Java (B). Java (C). Java (D). JavaScript Java JavaScript Java (i 12 7 27 10:30 12:00 I. I VI II. III. IV. ( a d) V. VI. 80 100 60 : this==null, T == N A ActionListener A addactionlistener C class D actionperformed E ActionEvent G getsource I implements J JApplet K KeyListener

More information

ソフトウェア開発方法論2

ソフトウェア開発方法論2 ソフトウェア開発方法論 2 情報システム工学特別講義 ( 渕田 ) 開発依頼 研究法人 AA 研究所では 構造立体研究の一部として 以下のような図形管理を行うシステムを発注する 名称 : 図形管理システム 機能 : 以下の機能を持つ 1. 画面の何もないところをクリックすることで 図形を画面上に配置することができる 配置できる図形は円 三角 四角の3つを選択でき 大きさは決まっている 2. 図形の色は

More information

6 29 ( )1 6 15 1 mousepressed mouseclicked mousemoved mousedragged mousereleased mousewheel keypressed keyreleased keytyped Shift OK Shift mousewheel void mousewheel(mouseevent event) { void keytyped()

More information

Microsoft PowerPoint prog1_doc2x.pptx

Microsoft PowerPoint prog1_doc2x.pptx アプレット public class extends Applet { public void paint(graphics g) { // アプレット描画 g.drawstring( Hello World, 10, 20 ); page 1 アプレット : 色 public class extends Applet { Color col; // カラークラス int red, grn, blu;

More information

Java 2 p.2 2 Java Hello0.class JVM Hello0 java > java Hello0.class Hello World! javac Java JVM java JVM : Java > javac 2> Q Foo.java Java : Q 2.

Java 2 p.2 2 Java Hello0.class JVM Hello0 java > java Hello0.class Hello World! javac Java JVM java JVM : Java > javac 2> Q Foo.java Java : Q 2. Java 2 p.1 2 Java Java JDK Sun Microsystems Oracle JDK javac Java java JVM appletviewer IDE Sun Microsystems NetBeans, IBM 1 Eclipse 2 IDE GUI JDK Java 2.1 Hello World! 2.1.1 Java 2.1.1 Hello World Emacs

More information

GUIプログラムⅣ

GUIプログラムⅣ GUI プログラム Ⅳ 画像指定ウィンドウの生成 ファイル名 :awtimage.java import java.awt.*; import java.awt.event.*; public class awtimage extends Frame // コンポーネントクラスの宣言 Button btnbrowse; Label lblcaption7; TextField txtimage; //

More information

Java 3 p.2 3 Java : boolean Graphics draw3drect fill3drect C int C OK while (1) int boolean switch case C Calendar java.util.calendar A

Java 3 p.2 3 Java : boolean Graphics draw3drect fill3drect C int C OK while (1) int boolean switch case C Calendar java.util.calendar A Java 3 p.1 3 Java Java if for while C 3.1 if Java if C if if ( ) 1 if ( ) 1 else 2 1 1 2 2 1, 2 { Q 3.1.1 1. int n = 2; if (n

More information

:30 12:00 I. I VII II. III. IV. ( a d) V. VI : this==null, T == N A ActionListener A addactionlistener C class D actionperforme

:30 12:00 I. I VII II. III. IV. ( a d) V. VI : this==null, T == N A ActionListener A addactionlistener C class D actionperforme 2014 8 01 10:30 12:00 I. I VII II. III. IV. ( a d) V. VI. 80 100 60 : this==null, T == N A ActionListener A addactionlistener C class D actionperformed E ActionEvent G getsource I implements J JApplet

More information

text_13.dvi

text_13.dvi C 13 2000 7 9 13 Java(8) { Swing(2)(, ) 1 13.1 13 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 1 13.2 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :

More information

r5.dvi

r5.dvi 00 5 2000.7.1 0 GUI API ( )! smp smm smo 1 : CSV CSV 1, 2,, N? CSV CSVString 1 CSVString csv = new CSVString(line); 1 int count = csv.getcount(); String second = csv.getfield(1); // 0 ( CSVString ) CSVString

More information

ÿþ˜u#u·0¹0Æ0à0

ÿþ˜u#u·0¹0Æ0à0 応用プログラミング - イベント処理 - イベント : プログラムへの働きかけ (GUI のボタンをクリックする, キーボードよりデータを入力するなど ) イベント処理 ( イベントハンドリング ): イベントに対する応答及びそのプログラム処理 イベントを処理するプログラムは イベントが発生した場合にのみ 呼び出される ( イベントドリブン ) GUI イベント イベント処理のプログラム イベント処理の仕組みと流れ

More information

2 p.2 2 Java Hello0.class JVM Hello0 java > java Hello0.class Hello World! javac Java JVM java JVM : Java > javac 2> Q Foo.java Java : Q B

2 p.2 2 Java Hello0.class JVM Hello0 java > java Hello0.class Hello World! javac Java JVM java JVM : Java > javac 2> Q Foo.java Java : Q B 2 p.1 2 Java Java JDK Sun Microsystems Oracle JDK javac Java java JVM appletviewer IDESun Microsystems NetBeans, IBM 1 Eclipse 2 IDE GUI JDK Java 2.1 Hello World! 2.1.1 Java 2.1.1 Hello World Emacs Hello0.java

More information

class IntCell { private int value ; int getvalue() {return value; private IntCell next; IntCell next() {return next; IntCell(int value) {this.value =

class IntCell { private int value ; int getvalue() {return value; private IntCell next; IntCell next() {return next; IntCell(int value) {this.value = Part2-1-3 Java (*) (*).class Java public static final 1 class IntCell { private int value ; int getvalue() {return value; private IntCell next; IntCell next() {return next; IntCell(int value) {this.value

More information

libaux.dvi

libaux.dvi AUX OpenGL 1 OpenGL (AUX libaux.a) OpenGL Programming Guide () OpenGL 1 OpenGL OS (API) OS OS OS OpenGL Windows Windows X X OpenGL Programming Guide AUX toolkit AUX OS OpenGL SGI OpenGL OS OpenGL AUX Windows

More information

2 static final int DO NOTHING ON CLOSE static final int HIDE ON CLOSE static final int DISPOSE ON CLOSE static final int EXIT ON CLOSE void setvisible

2 static final int DO NOTHING ON CLOSE static final int HIDE ON CLOSE static final int DISPOSE ON CLOSE static final int EXIT ON CLOSE void setvisible 12 2013 7 2 12.1 GUI........................... 12 1 12.2............................... 12 4 12.3..................................... 12 7 12.4....................................... 12 9 12.5 : FreeCellPanel.java............................

More information

class IntCell { private int value ; int getvalue() {return value; private IntCell next; IntCell next() {return next; IntCell(int value) {this.value =

class IntCell { private int value ; int getvalue() {return value; private IntCell next; IntCell next() {return next; IntCell(int value) {this.value = Part2-1-3 Java (*) (*).class Java public static final 1 class IntCell { private int value ; int getvalue() {return value; private IntCell next; IntCell next() {return next; IntCell(int value) {this.value

More information

10/ / /30 3. ( ) 11/ 6 4. UNIX + C socket 11/13 5. ( ) C 11/20 6. http, CGI Perl 11/27 7. ( ) Perl 12/ 4 8. Windows Winsock 12/11 9. JAV

10/ / /30 3. ( ) 11/ 6 4. UNIX + C socket 11/13 5. ( ) C 11/20 6. http, CGI Perl 11/27 7. ( ) Perl 12/ 4 8. Windows Winsock 12/11 9. JAV tutimura@mist.i.u-tokyo.ac.jp kaneko@ipl.t.u-tokyo.ac.jp http://www.misojiro.t.u-tokyo.ac.jp/ tutimura/sem3/ 2002 12 11 p.1/33 10/16 1. 10/23 2. 10/30 3. ( ) 11/ 6 4. UNIX + C socket 11/13 5. ( ) C 11/20

More information

新・明解Java入門

新・明解Java入門 537,... 224,... 224,... 32, 35,... 188, 216, 312 -... 38 -... 38 --... 102 --... 103 -=... 111 -classpath... 379 '... 106, 474!... 57, 97!=... 56 "... 14, 476 %... 38 %=... 111 &... 240, 247 &&... 66,

More information

Microsoft PowerPoint prog1_doc2.pptx

Microsoft PowerPoint prog1_doc2.pptx 2011 年 12 月 6 日 ( 火 ) プログラミング Ⅰ Java Applet プログラミング 文教大学情報学部経営情報学科堀田敬介 アプレット Applet public class クラス名 extends Applet { public void paint(graphics g) { // アプレット描画 g.drawstring( Hello World, 10, 20); 10

More information

Local variable x y i paint public class Sample extends Applet { public void paint( Graphics gc ) { int x, y;... int i=10 ; while ( i < 100 ) {... i +=

Local variable x y i paint public class Sample extends Applet { public void paint( Graphics gc ) { int x, y;... int i=10 ; while ( i < 100 ) {... i += Safari AppletViewer Web HTML Netscape Web Web 13-1 Applet Web Applet init Web paint Web start Web HTML stop destroy update init Web paint start Web update Event Driven paint Signature Overwriting Overriding

More information

アプレットの作成

アプレットの作成 - 1 - import java.applet.applet; import java.awt.graphics; public class HelloWorld extends Applet { public void init() { resize(150,60) ; public void paint ( Graphics g ) { g.drawstring("hello, world!",

More information

2008 e-learning T050050

2008 e-learning T050050 e-learning T050050 e-learning B NintendoDS e-learning html 1 e-learning Java Applet html 2 2008 e-learning T050050 1 1 1.1.................................. 1 1.2............................ 1 2 2 2.1..............................

More information

Thread

Thread 14 2013 7 16 14.1....................................... 14 1 14.2 Thread................................... 14 1 14.3............................. 14 5 14.4....................................... 14 10

More information

<4D F736F F F696E74202D AC C8899E D834F E >

<4D F736F F F696E74202D AC C8899E D834F E > Java 簡単な応用プログラム ( その 2) Java は すでにある部品群を上手く使ってプログラムを組み立てます 前回と同様に Frame を使って ウインドウを表示するプログラムを作りましょう. Frameは ウインドウを作るための部品で フレーム ( 枠 ) とタイトルおよび, 決められた仕組みが入っています. java.awt パッケージは, ウインドウ関連の部品が多くあります. javax.swing

More information

6 p.1 6 Java GUI GUI paintcomponent GUI mouseclicked, keypressed, actionperformed mouseclicked paintcomponent thread, 1 GUI 6.0.2, mutlithread C

6 p.1 6 Java GUI GUI paintcomponent GUI mouseclicked, keypressed, actionperformed mouseclicked paintcomponent thread, 1 GUI 6.0.2, mutlithread C 6 p.1 6 Java GUI GUI paintcomponent GUI mouseclicked, keypressed, actionperformed mouseclicked paintcomponent 6.0.1 thread, 1 GUI 6.0.2, mutlithread CPU 1 CPU CPU +----+ +----+ +----+ Java 1 CPU 6 p.2

More information

untitled

untitled Java 1 1 Java 1.1 Java 1.2 Java JavaScript 2 2.1 2.2 2.3 Java VM 3 3.1 3.2 3.3 3.4 4 Java 4.1 Java 4.2 if else 4.3 switch case 4.4 for 4.5 while 4.6 do-while 4.7 break, continue, return 4.8 try-catch-finally

More information

I java A

I java A I java 065762A 19.6.22 19.6.22 19.6.22 1 1 Level 1 3 1.1 Kouza....................................... 3 1.2 Kouza....................................... 4 1.3..........................................

More information

:30 12:00 I. I V II. III. IV. ( a d) V. VI : A ActionListener aa addactionlistener AE ActionEvent K KeyListener ak addkeyliste

:30 12:00 I. I V II. III. IV. ( a d) V. VI : A ActionListener aa addactionlistener AE ActionEvent K KeyListener ak addkeyliste 2017 07 28 10:30 12:00 I. I V II. III. IV. ( a d) V. VI. 80 100 60 : A ActionListener aa addactionlistener AE ActionEvent K KeyListener ak addkeylistener KE KeyEvent M MouseListener am addmouselistener

More information

次の演習課題(1),(2)のプログラムを完成させよ

次の演習課題(1),(2)のプログラムを完成させよ 次の演習課題 (1),(2) のプログラムを作成せよ. 課題 (1) ボタン押下時の処理を追加し以下の実行結果となるようにプログラムを作成しなさい ( ボタン押下時の処理 ) import java.lang.*; class Figure extends JFrame implements ActionListener{ JPanel panel; JScrollPane scroll; JTextArea

More information

Java演習(2) -- 簡単なプログラム --

Java演習(2)   -- 簡単なプログラム -- Java public class Hello Hello (class) (field)... (method)... Java main Hello World(Hello.java) public class Hello { public static void main(string[ ] args) { public() (package) Hello World(Hello.java)

More information

r14.dvi

r14.dvi 2008 14 2009.1.30 3e/3f paint (0 n rn() ) 1 / import java.awt.*; import javax.swing.*; public class ex33ef extends JFrame { public ex33ef() { setdefaultcloseoperation(exit_on_close); setpreferredsize(new

More information

GUIプログラムⅤ

GUIプログラムⅤ GUI プログラム Ⅴ 前回課題の制作例 ファイル名 :awttest.java public class awttest public static void main(string arg[]) //=============================================== // ウィンドウ (Frame クラス ) のインスタンスを生成 //===============================================

More information

2 p.2 2 Java Hello0.class JVM Hello0 java > java Hello0.class Hello World! javac Java JVM java JVM : Java > javac 2> Q Foo.java Java : Q B

2 p.2 2 Java Hello0.class JVM Hello0 java > java Hello0.class Hello World! javac Java JVM java JVM : Java > javac 2> Q Foo.java Java : Q B 2 p.1 2 Java Java JDK Sun Microsystems Oracle JDK javac Java java JVM appletviewer IDESun Microsystems NetBeans, IBM 1 Eclipse 2 IDE GUI JDK Java 2.1 Hello World! 2.1.1 Java 2.1.1 Hello World Emacs Hello0.java

More information

Microsoft Word - Java3.DOC

Microsoft Word - Java3.DOC Java 入門 ( 5) 科名 T u t o r i a l g r o u p 氏 名 1 Abstract Window Toolkit(AWT) Abstract Window Toolkit(AWT) は Java の GUI(Graphical User Interface) 構築の最も基本となるライブラリパッケージである Abstract Window Toolkit(AWT) の特徴は

More information

2 1 Web Java Android Java 1.2 6) Java Java 7) 6) Java Java (Swing, JavaFX) (JDBC) 7) OS 1.3 Java Java

2 1 Web Java Android Java 1.2 6) Java Java 7) 6) Java Java (Swing, JavaFX) (JDBC) 7) OS 1.3 Java Java 1 Java Java 1.1 Java 1) 2) 3) Java OS Java 1.3 4) Java Web Start Web / 5) Java C C++ Java JSP(Java Server Pages) 1) OS 2) 3) 4) Java Write Once, Run Anywhere 5) Java Web Java 2 1 Web Java Android Java

More information

任意の加算プログラム

任意の加算プログラム HP Java CG Java Graphics CG CG CG paint CG CG paint CG paint Windows paint paint 17 // public Frame1() { enableevents(awtevent.window_event_mask); try { jbinit(); catch(exception e) { e.printstacktrace();

More information

< F2D F B834E2E6A7464>

< F2D F B834E2E6A7464> ランダムウォーク [Java アプレット ] [Java アプレリケーョン ] 1. はじめに 酔っぱらいは前後左右見境なくふらつきます 酔っぱらいは目的地にたどり着こうと歩き回っているうちに何度も同じところに戻って来てしまったりするものです 今 酔っぱらいが数直線上の原点にいるとします 原点を出発して30 回ふらつくとき 30 回目に酔っぱらいがいる位置は 出発点である原点からどれくらい離れてしまっているのでしょうか

More information

Microsoft PowerPoint - prog10.ppt

Microsoft PowerPoint - prog10.ppt プログラミング言語 3 第 10 回 (2007 年 12 月 03 日 ) 1 今日の配布物 片面の用紙 1 枚 今日の課題が書かれています 本日の出欠を兼ねています 2/40 今日やること http://www.tnlab.ice.uec.ac.jp/~s-okubo/class/java06/ にアクセスすると 教材があります 2007 年 12 月 03 日分と書いてある部分が 本日の教材です

More information

Safari AppletViewer Web HTML Netscape Web Web 15-1 Applet Web Applet init Web paint Web start Web HTML stop destroy update init Web paint start Web up

Safari AppletViewer Web HTML Netscape Web Web 15-1 Applet Web Applet init Web paint Web start Web HTML stop destroy update init Web paint start Web up Safari AppletViewer Web HTML Netscape Web Web 15-1 Applet Web Applet init Web paint Web start Web HTML stop destroy update init Web paint start Web update Event Driven paint Signature Overwriting Overriding

More information

入門Java解答.doc

入門Java解答.doc //2 1Mon2_1.java package moji; import java.awt.*; import java.awt.event.*; import java.applet.*; public class Mon2_1 extends Applet { public void paint(graphics g){ } g.drawstring("java ", 100, 100); g.drawstring("",

More information

1 JAVA APPLET 実習 1. はじめに Java フォルダに applet フォルダを作成する 2. 実習問題の作成 J01.java public class J01 extends Applet{ public void paint(graphics kaku){ kaku.drawstring("hello World from Java!",60,70); j01.html

More information

Microsoft PowerPoint - prog10.ppt

Microsoft PowerPoint - prog10.ppt プログラミング言語 3 第 10 回 (2007 年 12 月 03 日 ) 1 今日の配布物 片面の用紙 1 枚 今日の課題が書かれています 本日の出欠を兼ねています 2/40 1 今日やること http://www.tnlab.ice.uec.ac.jp/~s-okubo/class/java06/ にアクセスすると 教材があります 2007 年 12 月 03 日分と書いてある部分が 本日の教材です

More information

K227 Java 2

K227 Java 2 1 K227 Java 2 3 4 5 6 Java 7 class Sample1 { public static void main (String args[]) { System.out.println( Java! ); } } 8 > javac Sample1.java 9 10 > java Sample1 Java 11 12 13 http://java.sun.com/j2se/1.5.0/ja/download.html

More information

19 3!! (+) (>) (++) (+=) for while 3.1!! (20, 20) (1)(Blocks1.java) import javax.swing.japplet; import java.awt.graphics;

19 3!! (+) (>) (++) (+=) for while 3.1!! (20, 20) (1)(Blocks1.java) import javax.swing.japplet; import java.awt.graphics; 19 3!!...... (+) (>) (++) (+=) for while 3.1!! 3.1.1 50 20 20 5 (20, 20) 3.1.1 (1)(Blocks1.java) public class Blocks1 extends JApplet { public void paint(graphics g){ 5 g.drawrect( 20, 20, 50, 20); g.drawrect(

More information

Java言語 第1回

Java言語 第1回 Java 言語 第 8 回ウインドウ部品を用いる (1) 知的情報システム工学科 久保川淳司 kubokawa@me.it-hiroshima.ac.jp 前回の課題 (1) マウスを使って, 前回課題で作成した 6 4 のマスの図形で, \ をマウスクリックによって代わるようにしなさい 前回の課題 (2) import java.applet.applet; import java.awt.*;

More information

< F2D E E6A7464>

< F2D E E6A7464> ピタゴラス数 [Java アプレット ] [Java アプリケーション ] 1. はじめに 2 2 2 三平方の定理 a +b =c を満たす3つの自然数の組 ( a, b, c) をピタゴラス数と言います ピタゴラス数の最も簡単な例として (3,4,5) がありますね このピタゴラス数を求めるには ピタゴラスの方法とプラトンの方法の2つの方法があります 2 2 ピタゴラス数 (a,b,c) に対して

More information

表示の更新もそういた作業のひとつに当たる スレッドの使用アニメーション アニメーションやシミュレーションなどは画面の更新が一定のタイミングで行われていく この連続した画面の更新をスレッドを利用して行う しかし paint() メソッドを直接呼び出して表示を更新することはできない その理由

表示の更新もそういた作業のひとつに当たる スレッドの使用アニメーション アニメーションやシミュレーションなどは画面の更新が一定のタイミングで行われていく この連続した画面の更新をスレッドを利用して行う しかし paint() メソッドを直接呼び出して表示を更新することはできない その理由 Java 独習第 3 版 13.12 スレッドの使用 13.13 ダブルバッファリング 2006 年 7 月 12 日 ( 水 ) 南慶典 表示の更新もそういた作業のひとつに当たる 13.12 スレッドの使用アニメーション アニメーションやシミュレーションなどは画面の更新が一定のタイミングで行われていく この連続した画面の更新をスレッドを利用して行う しかし paint() メソッドを直接呼び出して表示を更新することはできない

More information

Microsoft PowerPoint ppt

Microsoft PowerPoint ppt 独習 Java 第 3 版 13.9 Applet クラス 13.10 AppletContext インターフェイス 13.11 イメージの使用 Applet クラス 右の図は Applet クラスのスーパークラスの継承関係を示す 上の 4 つのクラスから Applet クラスに状態と動作が継承される java.lang.object Java.awt.Component java.awt.container

More information

PowerPoint プレゼンテーション

PowerPoint プレゼンテーション (1a) JAVA 言語の概要とインストール (1/2) JAVA 言語を使うメリットコンパイル 実行環境が無料であること OSや計算機に依存しないこと描画が簡単なこと参考書や情報ウェブサイトが豊富なこと文法やコマンドがC/C++ 言語に類似していること 科学技術計算から趣味 ゲームまで広範囲に利用可能 JAVAの種類 JAVA SE (JAVA Standard Edition): 他に EE (Enterprise

More information

PowerPoint プレゼンテーション

PowerPoint プレゼンテーション オブジェクト指向 プログラミング演習 第 3 回継承 オーバーライド インタフェース 前回までのお話 モジュール化 大きなプログラムは部品に分けて設計する オブジェクト指向 モノ中心に考える プログラムでは クラス ( モノの種類 ) を定義する ある特定のモノは インスタンスで表す クラスは型 インスタンスは値 プログラムを書くときも部品ごとに書く モノの部品であるモノはフィールドに書く 手順の部品である手順はメソッドに書く

More information

< F2D82518E9F8AD CC834F CC8CFC82AB82C68D4C>

< F2D82518E9F8AD CC834F CC8CFC82AB82C68D4C> 2 次関数のグラフの向きと広がり [Java アプレット ] [Java アプリケーション ] 1. はじめに 2 2 y=ax のグラフについて x の係数 aが正のときと負のときでは グラフにどのような違いがあるでしょうか 2 2 y=ax のグラフについて x の係数 aが正のとき 係数 aの値が大きくなるにつれて グラフの広がりはどうなるでしょうか 2 2 y=ax のグラフについて x の係数

More information

第7章 レンダリング

第7章 レンダリング 7 April 11, 2017 1 / 59 7.1 ( ) CG 3 ( ) 2 / 59 7.2 7.2.1 ( ) 3 (rendering) 1 / (hidden line/surface calculation) a (outer normal algorithm) b Z (Z-buffer algorithm) c (scan-line algorithm) 2 (shading)

More information

< F2D BCA82CC978E89BA82CC8EC08CB12E6A7464>

< F2D BCA82CC978E89BA82CC8EC08CB12E6A7464> パチンコ玉の落下の実験 [Java アプレット ] [Java アプリケーション ] 1. はじめに 1 個のパチンコ玉が釘に当たって左右に分かれながら落下するとき パチンコ玉はどこに落下するのでしょうか ただし パチンコ玉が釘に当たって左右に分かれるとき その分かれ方は左右半々であるとします パチンコ玉が落下し易い場所はあるのでしょうか それとも どこの場所も同じなのでしょうか シミュレーションソフト

More information

第7章 レンダリング

第7章 レンダリング 7 May 18, 2012 1 / 60 71 ( ) CG 3 ( ) 2 / 60 72 71 ( ) 3 (rendering) 1 / (hidden line/surface calculation) a (outer normal algorithm) b Z (Z-buffer algorithm) c (scan-line algorithm) 2 (shading) a (flat

More information

< F2D82518E9F8AD CC95BD8D7388DA93AE2E6A7464>

< F2D82518E9F8AD CC95BD8D7388DA93AE2E6A7464> 2 次関数のグラフの平行移動 [Java アプレット ] [Java アプリケーション ] 1. はじめに 2 2 y=ax のグラフとy=a(x-b) +c のグラフは 位置は違うけれど 形も広がりも全く同じです 2 2 y=a(x-b) +c のグラフは y=ax のグラフをx 軸方向に ( 右方向に ) +b y 軸方向に ( 上方向に ) +c だけ平行移動したものです 2 シミュレーションソフト

More information

1.1 (1) (2) (3) (4) 2

1.1 (1) (2) (3) (4) 2 1 Part2-1-1 1 1.1 (1) (2) (3) (4) 2 2 JAVA (*) Java : 1. Java 2. 3. 4. Java Java 3 3 int[] a; a = new int[3]; new int[3] a i a[i] 32bit a[i] 4 4 class Point { // double x, y, weight; // Point(double x,

More information

text_12.dvi

text_12.dvi C 12 2000 7 2 12 Java(7) { Swing(, ), 1 12.1 12 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 1 12.2 Swing : : : : : : : : : : : : : : : : : : : : : : : : : : : : :

More information

:30 12:00 I. I VII II. III. IV. ( a d) V. VI : this==null, T == N A ActionListener A addactionlistener C class D actionperformed

:30 12:00 I. I VII II. III. IV. ( a d) V. VI : this==null, T == N A ActionListener A addactionlistener C class D actionperformed 11 7 29 10:30 12:00 I. I VII II. III. IV. ( a d) V. VI. 80 100 60 : this==null, T == N A ActionListener A addactionlistener C class D actionperformed E ActionEvent G getsource I implements J JApplet K

More information

vol.30.}...`.X...b.h

vol.30.}...`.X...b.h Manabu Nakamura mondo@its.hiroshima-cu.ac.jp q w e e e for (int i = 0; i < N; i++) { calculators[i] = new Calculator(); calculators[i].run(); 70 JAVA PRESS Vol.30 import java.math.biginteger; public class

More information

Color.cyan, Color.yellow, Color.pink, Color.orange, Color.white, Color.black, Color.gray, Color.darkGray, Color.lightGray ; Button barray [ ] = new Bu

Color.cyan, Color.yellow, Color.pink, Color.orange, Color.white, Color.black, Color.gray, Color.darkGray, Color.lightGray ; Button barray [ ] = new Bu Chapter 18. [ ] ; [ ] = new [ ] ; Color colors [ ] = new Color[ 20 ]; // 20 Button operations [ ] = new Button[ 10 ]; // 10 colors[ 3 ] = new Color( 10, 30, 40 ); g.setcolor( colors[ 3 ] ); operations[

More information

IE6 2 BMI chapter1 Java 6 chapter2 Java 7 chapter3 for if 8 chapter4 : BMI 9 chapter5 Java GUI 10 chapter6 11 chapter7 BMI 12 chap

IE6 2 BMI chapter1 Java 6 chapter2 Java 7 chapter3 for if 8 chapter4 : BMI 9 chapter5 Java GUI 10 chapter6 11 chapter7 BMI 12 chap 1-1 1-2 IE6 2 BMI 3-1 3-2 4 5 chapter1 Java 6 chapter2 Java 7 chapter3 for if 8 chapter4 : BMI 9 chapter5 Java GUI 10 chapter6 11 chapter7 BMI 12 chapter8 : 13-1 13-2 14 15 PersonTest.java KazuateGame.java

More information

解きながら学ぶJava入門編

解きながら学ぶJava入門編 44 // class Negative { System.out.print(""); int n = stdin.nextint(); if (n < 0) System.out.println(""); -10 Ÿ 35 Ÿ 0 n if statement if ( ) if i f ( ) if n < 0 < true false true false boolean literalboolean

More information

< F2D A839382CC906A2E6A7464>

< F2D A839382CC906A2E6A7464> ビュホンの針 1. はじめに [Java アプレット ] [Java アプリケーション ] ビュホン ( Buffon 1707-1788) は 針を投げて円周率 πを求めることを考えました 平面上に 幅 2aの間隔で 平行線を無数に引いておきます この平面上に長さ2bの針を落とすと この針が平行線と交わる確立 pは p=(2b) (aπ) 1 となります ただし b

More information

10K pdf

10K pdf #1 #2 Java class Circle { double x; // x double y; // y double radius; // void set(double tx, double ty){ x = tx; y = ty; void set(double tx, double ty, double r) { x = tx; y = ty; radius = r; // Circle

More information

Javaセキュアコーディングセミナー2013東京第1回 演習の解説

Javaセキュアコーディングセミナー2013東京第1回 演習の解説 Java セキュアコーディングセミナー東京 第 1 回オブジェクトの生成とセキュリティ 演習の解説 2012 年 9 月 9 日 ( 日 ) JPCERT コーディネーションセンター脆弱性解析チーム戸田洋三 1 演習 [1] 2 演習 [1] class Dog { public static void bark() { System.out.print("woof"); class Bulldog

More information

extends (*) (*) extend extends 2

extends (*) (*) extend extends 2 2007-2-1-4 1 1.1 1 extends (*) (*) extend extends 2 class Person { private String name; String name() {return name; Person(String name) { this.name=name; class Worker extends Person { private int salary;

More information

Animals サンプル Step3 張り付けた動物の上をクリックすると それぞれの鳴き声で鳴く その鳴く間 一定時間 ( ここでは 1 秒間 ) 画像が別のものに変わる <アニメーションの基礎 : タイマーについて> アニメーションは アプリケーションが指定する間 一定間隔でどんどん画像をおきかえ

Animals サンプル Step3 張り付けた動物の上をクリックすると それぞれの鳴き声で鳴く その鳴く間 一定時間 ( ここでは 1 秒間 ) 画像が別のものに変わる <アニメーションの基礎 : タイマーについて> アニメーションは アプリケーションが指定する間 一定間隔でどんどん画像をおきかえ Animals サンプル Step3 張り付けた動物の上をクリックすると それぞれの鳴き声で鳴く その鳴く間 一定時間 ( ここでは 1 秒間 ) 画像が別のものに変わる アニメーションは アプリケーションが指定する間 一定間隔でどんどん画像をおきかえていくものである このサンプルでは 動物画像の上をクリックすると画像を切り替え 1 秒後 もとの画像に戻す操作をする

More information