r4.dvi
|
|
|
- ゆき うとだ
- 7 years ago
- Views:
Transcription
1 ( ) ( 1 ) ( 1 ) (a) (b) 1: 1 javax.swing.timer ( ) start() 1) 1) javax.swing.timer new javax.swing.timer(30, ).start(); // 30 java.util.timer Timer? AcitonListener actionperformed() 2) 2) ActionEvent 1 1
2 ActionListener actionperformed() new javax.swing.timer(30, new ActionListener() { public void actionperformed(actionevent evt) { // ).start(); 6-1: 1 ( 2) 2: 2 String format() 1 2 3) % 3) %wd w %wx w 16 %w.lf w l w w w 4) 4)5) Figure Circle Text import java.awt.*; 5)ActionListener import java.awt.event.*; java.awt.event import javax.swing.*; import java.util.*; 2
3 public class Sample61 extends JPanel { ArrayList<Figure> figs = new ArrayList<Figure>(); Circle c1 = new Circle(Color.BLUE, 100, 100, 30); Text t1 = new Text(20, 40, "?", new Font("Serif", Font.BOLD, 36)); public Sample61() { setopaque(false); figs.add(t1); figs.add(c1); final long tm0 = System.currentTimeMillis(); new javax.swing.timer(30, new ActionListener() { public void actionperformed(actionevent evt) { double tm = 0.001*(System.currentTimeMillis()-tm0); t1.settext(string.format("%4.2f", tm)); c1.moveto(20 + (int)(tm*100) % 250, 100); repaint(); ).start(); public void paintcomponent(graphics g) { for(figure f: figs) { f.draw(g); public static void main(string[] args) { JFrame app = new JFrame(); app.add(new Sample61()); app.setsize(400, 300); app.setdefaultcloseoperation(jframe.exit_on_close); app.setvisible(true); setopaque() tm0 System. currenttimemillis() 6) final 6) long final 1 System.currentTimeMillis() tm String.format() 4 2 Text 7) % 2 Circle X 100 X ) Y repaint() 0 Text Circle 3
4 interface Figure { public void draw(graphics g); static class Circle implements Figure { Color col; int xpos, ypos, rad; public Circle(Color c, int x, int y, int r) { col = c; xpos = x; ypos = y; rad = r; public boolean hit(int x, int y) { return (xpos-x)*(xpos-x)+(ypos-y)*(ypos-y)<=rad*rad; public void setcolor(color c) { col = c; public void moveto(int x, int y) { xpos = x; ypos = y; public void draw(graphics g) { g.setcolor(col); g.filloval(xpos-rad, ypos-rad, rad*2, rad*2); static class Text implements Figure { int xpos, ypos; String txt; Font fn; public Text(int x, int y, String t, Font f) { xpos = x; ypos = y; txt = t; fn = f; public void settext(string t) { txt = t; public void draw(graphics g) { g.setcolor(color.black); g.setfont(fn); g.drawstring(txt, xpos, ypos); // 6-1 Sample51.java a. b. c. 4
5 d e. 6-1-abcd )9)10) 8) c1 Y ypos import java.awt.*; import javax.swing.*; import java.util.*; public class ex61abcd extends JPanel { 9) c2 XY ArrayList<Figure> figs = new ArrayList<Figure>(); sin 2 ( Circle c1 = new Circle(Color.BLUE, 100, 100, 30); 6.28) Circle c2 = new Circle(Color.RED, 160, 100, 30); (X Y int ypos = 100; Text t1 = new Text(20, 40, "?", new Font("Serif", Font.BOLD, 36)); 10) c1 public ex61abcd() { setopaque(false); figs.add(t1); figs.add(c1); figs.add(c2); final long tm0 = System.currentTimeMillis(); new javax.swing.timer(30, new ActionListener() { public void actionperformed(actionevent evt) { double tm = 0.001*(System.currentTimeMillis()-tm0); t1.settext(string.format("%4.2f", tm)); ypos += (int)(40*math.random() - 20); c1.moveto(20 + (int)(tm*100) % 250, ypos); c2.moveto(200 + (int)(50*math.sin(tm)), 80 + (int)(80*math.sin(tm + 1.0))); c1.setcolor(color.gethsbcolor((float)((0.03*tm)%1), 1f, 1f)); c2.setcolor(new Color[]{Color.PINK, Color.RED, Color.BLUE [(int)(0.3*tm) % 3]); repaint(); ).start(); // paintcomponent Sample61 Color.GetHSBColor() c
6 ( ) 6-2: ( 3) 3 3: import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; public class Sample62 extends JPanel { ArrayList<Figure> figs = new ArrayList<Figure>(); Circle c1 = new Circle(Color.BLUE, 150, 100, 30); Text t1 = new Text(20, 40, "Click whien red", new Font("Serif", Font.BOLD, 36)); long tm0 = System.currentTimeMillis(); double tmc = *Math.random(); double tm1 = 0.0; public Sample62() { setopaque(false); figs.add(c1); figs.add(t1); new javax.swing.timer(30, new ActionListener() { public void actionperformed(actionevent evt) { double tm = 0.001*(System.currentTimeMillis()-tm0); if(tmc!= 0.0 && tm >= tmc) { tm1 = tm; tmc = 0.0; c1.setcolor(color.red); repaint(); 6
7 ).start(); addmouselistener(new MouseAdapter() { public void mousepressed(mouseevent evt) { if(tmc == 0.0 && c1.hit(evt.getx(), evt.gety())) { double tm = 0.001*(System.currentTimeMillis()-tm0); t1.settext(string.format("%.3f", tm-tm1)); c1.setcolor(color.blue); tmc = tm *Math.random(); repaint(); ); // paintcompnent Sampel61 11)12) 11) tmc Sample62.java tm1 tmc 0 a. 12) ( ) 13) tm1 b. ( 3 ) c. 13) d τ c e f. 30 (?) g. 6-2-b Fitzz 6-2-a c1.moveto(20+(int)(360*math.random()), 20+(int)(260*Math.random())); 6-2-c / xpos ypos 50 XY dx dy 7
8 int xpos = 150, ypos = 100, dx, dy; dx dy dx dy dx dy public void actionperformed(actionevent evt) { double tm = 0.001*(System.currentTimeMillis()-tm0); if(tmc!= 0.0 && tm >= tmc) { tm1 = tm; tmc = 0.0; c1.setcolor(color.red); dx = 10 + (int)(30 * Math.random()); dy = 10 + (int)(20 * Math.random()); repaint(); else if(tmc == 0.0) { xpos += dx; ypos += dy; if(xpos < 0 && dx < 0 xpos > getwidth() && dx > 0) dx = -dx; if(ypos < 0 && dy < 0 ypos > getheight() && dy > 0) dy = -dy; c1.moveto(xpos, ypos); repaint(); 6-2-def ) 15) Text Circle GameCircle GameCirlce count 16) 40 16) import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; public class ex62def extends JPanel { ArrayList<Figure> figs = new ArrayList<Figure>(); Font fn = new Font("Serif", Font.BOLD, 36); Text t1 = new Text(20, 30, "Click when red", fn); Text t2 = new Text(20, 60, "0", fn); GameCircle[] a = new GameCircle[5]; int count; public ex62def() { setopaque(false); figs.add(t1); figs.add(t2); for(int i = 0; i < 5; ++i) { a[i] = new GameCircle(Color.BLUE, 50+50*i, 100, 20); figs.add(a[i]); final long tm0 = System.currentTimeMillis(); new javax.swing.timer(30, new ActionListener() { double tmc = *Math.random(); double tm = 0.0; 8
9 public void actionperformed(actionevent evt) { if(tm >= 40.0) { return; tm = 0.001*(System.currentTimeMillis()-tm0); if(tm >= tmc) { tmc = tm + (40.0-tm)*0.1*Math.random(); int i = (int)(a.length * Math.random()); if(a[i].getcolor()!= Color.RED) { a[i].setcolor(color.red); a[i].start(); for(gamecircle c1: a) { c1.proceed(); t1.settext(string.format("%2.2f", 40.0-tm)); repaint(); ).start(); addmouselistener(new MouseAdapter() { public void mousepressed(mouseevent evt) { for(gamecircle c1: a) { if(c1.getcolor() == Color.RED && c1.hit(evt.getx(), evt.gety())) { c1.setcolor(color.blue); ++count; t2.settext(string.format("%d", count)); ); // paintcomponent GameCircle GameCiecle start() proceed() repaint() GameCircle Y ybase 20 mcount 17) 17) start() mcount 20 proceed() mcount 0 ( ) mcount 1 mcount super() Y mcount 0 5 static class GameCircle extends Circle { int ybase, mcount; public GameCircle(Color c, int x, int y, int r) { super(c, x, y, r); ybase = y; public Color getcolor() { return col; public void start() { mcount = 20; public void proceed() { if(mcount <= 0) { return; mcount -= 1; 9
10 ypos = ybase Math.abs(mcount-10) * 10; if(mcount == 0) { col = Color.BLUE; 18) GameCircle proceed() ypos Y Circle Cirlce ( Circle ) ( ) moveto() ypos ( 4) 4:? 18) 19) 19) 1 A 10
11 X Y X Y? 20)21) 20)X Y? X Y N 3 : 2 N ArrayList ( ) 21) 1 ArrayList MyList<E> X Y X Y static class MyList<E> implements Iterable<E> { ArrayList<E> a = new ArrayList<E>(); public void add(e x) { a.add(x); public void set(int i, E x) { a.set(i, x); public E get(int i) { return a.get(i); public int size() { return a.size(); public void remove(e x) { a.remove(x); public Iterator<E> iterator() { return a.iterator(); X Y mixin mixin 1 mixin E 22) E ArrayList<E> Java 1 ArrayList 22)foreach? Java implements Iterable<E> 23) 23) ArrayList draw() Java E Figure ( E draw() ) <E extends Figure> static class MyList<E extends Figure> implements Iterable<E>, Figure { ArrayList<E> a = new ArrayList<E>(); public void add(e x) { a.add(x); public void set(int i, E x) { a.set(i, x); 11
12 public E get(int i) { return a.get(i); public int size() { return a.size(); public void remove(e x) { a.remove(x); public Iterator<E> iterator() { return a.iterator(); public void draw(graphics g) { for(figure f1: a) { f1.draw(g); Figure draw() ArrayList MyList<Figure> figs = new MyList<Figure>(); paintcomponent draw() public void paintcomponent(graphics g) { figs.draw(g); 4 24) 24)? ( ) 3 ( 5 ) ( ) ( 5 ) 5: A B B 25) 25) B A B 12
13 7-1: 26) 26) ( 6) 6-1 6: figs anim 2 figs 3 (100,200) 5 (200,60) 4 5 anim 27) 27) import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; public class Sample71 extends JPanel { ArrayList<Figure> figs = new ArrayList<Figure>(); ArrayList<Animation> anim = new ArrayList<Animation>(); public Sample71() { Color col1 = Color.BLACK, col2 = Color.RED; Circle c1 = new Circle(col1, 100, 200, 20); figs.add(c1); anim.add(new LinearMove(c1, 3, 100, 200, 5, 200, 60)); anim.add(new ColorTrans(c1, 4, col1, 5, col2)); setopaque(false); final long tm0 = System.currentTimeMillis(); new javax.swing.timer(30, new ActionListener() { public void actionperformed(actionevent evt) { float tm = 0.001f*(System.currentTimeMillis()-tm0); for(animation a: anim) { a.settime(tm); repaint(); 13
14 ).start(); 28) float 28) 50 float 29) double paintcomponent() main() public void paintcomponent(graphics g) { 29) for(figure f: figs) { f.draw(g); public static void main(string[] args) { JFrame app = new JFrame(); app.add(new Sample71()); app.setsize(400, 240); app.setdefaultcloseoperation(jframe.exit_on_close); app.setvisible(true); Figure draw() moveto() setcolor() Animation interface Figure { public void draw(graphics g); public void moveto(float x, float y); public void setcolor(color c); interface Animation { public void settime(float dt); SmpleFigure Circle SimpleFigure 30) super. ( ) draw() 30)31) static abstract class SimpleFigure implements Figure { Color col; SimpleFigure draw() 31)Circle hit() ( 7-2) float xpos, ypos; public SimpleFigure(Color c, float x, float y) { col = c; xpos = x; ypos = y; public void moveto(float x, float y) {xpos=x;ypos=y; public void setcolor(color c) { col = c; public void draw(graphics g) { g.setcolor(col); static class Circle extends SimpleFigure { Color col; float rad; 14
15 public Circle(Color c, float x, float y, float r) { super(c, x, y); rad = r; public boolean hit(float x, float y) { return (xpos-x)*(xpos-x)+(ypos-y)*(ypos-y)<=rad*rad; public void draw(graphics g) { int x = (int)(xpos-rad), y = (int)(ypos-rad); super.draw(g); g.filloval(x, y, (int)rad*2, (int)rad*2); LineaMove ColorTrans XY ( ) XY ( 32) settime() 32) RGBA t p q 33) 33) p = t 2 t t 2 t 1, q = 1.0 p ( = t t 1 t 2 t 1 ) 1.0 p q XY RGBA px 1 + qx 2 Figure XY static class LinearMove implements Animation { Figure fig; float time1, xpos1, ypos1, time2, xpos2, ypos2; public LinearMove(Figure f, float t1, float x1, float y1, float t2, float x2, float y2) { time1 = t1; xpos1 = x1; ypos1 = y1; time2 = t2; xpos2 = x2; ypos2 = y2; fig = f; public void settime(float t) { if(t < time1 time2 < t) { return; float p = (time2-t)/(time2-time1), q = 1.0f - p; fig.moveto(p*xpos1 + q*xpos2, p*ypos1 + q*ypos2); static class ColorTrans implements Animation { Figure fig; float time1, time2; int r1, g1, b1, a1, r2, g2, b2, a2; public ColorTrans(Figure f, float t1, Color c1, float t2, Color c2) { 15
16 fig = f; time1 = t1; time2 = t2; r1 = c1.getred(); g1 = c1.getgreen(); b1 = c1.getblue(); a1 = c1.getalpha(); r2 = c2.getred(); g2 = c2.getgreen(); b2 = c2.getblue(); a2 = c2.getalpha(); public void settime(float t) { if(t < time1 time2 < t) { return; float p = (time2-t)/(time2-time1), q = 1.0f - p; fig.setcolor(new Color((int)(p*r1+q*r2), (int)(p*g1+q*g2),(int)(p*b1+q*b2),(int)(p*a1+q*a2))); // Sample71.java a. 34)A B C b ) 35) : Animation c. ON Animation Figure d. 4 Figure 36) 36) ( e. )moveto() setcolor() 37) 38) 37)2 1 setcolor() f. Color darker() brighter() / b 38) Animation 16
17 static class ZigzagMove implements Animation { Figure fig; float time1, xpos1, ypos1, xpos2, ypos2; public ZigzagMove(Figure f, float t1, float x1, float y1, float x2, float y2) { time1 = t1; xpos1 = x1; ypos1 = y1; xpos2 = x2; ypos2 = y2; fig = f; public void settime(float t) { float q = (t % time1) / time1, p = 1.0f - q; fig.moveto(p*xpos1 + q*xpos2, p*ypos1 + q*ypos2); static class TimedAnimation implements Animation { Animation anim; float time1, time2; public TimedAnimation(Animation a, float t1, float t2) { anim = a; time1 = t1; time2 = t2; public void settime(float t) { if(t < time1 time2 < t) { return; anim.settime(t - time1); static class TimedAppearance implements Figure, Animation { Figure fig; float time, time1, time2; public TimedAppearance(Figure f, float t1, float t2) { fig = f; time1 = t1; time2 = t2; public void moveto(float x, float y) { fig.moveto(x, y); public void setcolor(color c) { fig.setcolor(c); public void settime(float t) { time = t; public void draw(graphics g) { if(time1 <= time && time <= time2) { fig.draw(g); ZigzagMove LinearMove Animation 39)TimedAnimation Animation 39) 6-1 Animation settime() time1 TimedApperance Figure draw() % time1 Figure draw() 0.0f 1.0f 40) ( 0 q ) Circle c1 = new Circle(Color.RED, 100, 200, 20); TimedAppearance t1 = new TimedAppearance(c1, 1, 8); figs.add(t1); anim.add(t1); Animation a1 = new ZigzagMove(c1, 1, 100, 200, 200, 100); anim.add(new TimedAnimation(a1, 3, 7)); 40) Figure Animation implements moveto() setcolor() Figure 7-1-c 17
18 41) 41) Color s1 = new Color(50,50,100), s2 = new Color(220,220,250); Rect sky = new Rect(s1, 200, 100, 400, 210); Circle c1 = new Circle(Color.YELLOW, 200, 60, 20); Color pc1 = new Color(180,110,60), pc2 = new Color(150,80,30); Color pc3 = new Color(160,100,40,0); Triangle p1 = new Triangle(pc1, 260, 110, 180, 180, 290, 180); Triangle p2 = new Triangle(pc2, 260, 110, 290, 180, 350, 180); Rect grnd = new Rect(new Color(100,40,40), 200, 220, 400, 80); figs.add(sky); figs.add(c1); figs.add(p1); figs.add(p2); figs.add(grnd); anim.add(new LinearMove(c1, 3, 200, 60, 5, 20, 220)); anim.add(new ColorTrans(c1, 5, Color.YELLOW, 6, Color.RED)); anim.add(new LinearMove(c1, 6, 20, 220, 8, 200, 60)); anim.add(new ColorTrans(sky, 6, s1, 8, s2)); anim.add(new ColorTrans(p1, 10, pc1, 12, pc3)); anim.add(new ColorTrans(p2, 10, pc2, 12, pc3)); 42) 42)43)44) hit() static class Rect extends SimpleFigure { 43) Color col; 2 3 float width, height; public Rect(Color c, float x, float y, float w, float h) { super(c, x, y); width = w; height = h; 44) public boolean hit(float x, float y) { new int[] return xpos-width/2 <= x && x <= xpos+width/2 && ypos-height/2 <= y && y <= ypos+height/2; public void draw(graphics g) { int x = (int)(xpos-width/2), y = (int)(ypos-height/2); super.draw(g); g.fillrect(x, y, (int)width, (int)height); static class Triangle extends SimpleFigure { Color col; float dx1, dy1, dx2, dy2; public Triangle(Color c, float x, float y, float x1, float y1, float x2, float y2) { super(c, x, y); dx1 = x1-x; dy1 = y1-y; dx2 = x2-x; dy2 = y2-y; public void draw(graphics g) { int[] xs = {(int)xpos, (int)(xpos+dx1), (int)(xpos+dx2); int[] ys = {(int)ypos, (int)(ypos+dy1), (int)(ypos+dy2); super.draw(g); g.fillpolygon(xs, ys, 3); 7-1-e 18
19 (!) Human m1 = new Human(new Color(200,80,120), 10, 100, 120); House h1 = new House(new Color(50,150,200), 25, 100, 150); Car c1 = new Car(Color.GREEN, 10, 350, 50); figs.add(m1); figs.add(h1); figs.add(c1); anim.add(new LinearMove(c1, 2, 350, 50, 4, 200, 180)); anim.add(new LinearMove(m1, 4, 100, 120, 6, 200, 120)); anim.add(new TimedAnimation(c1, 7, 10)); anim.add(new LinearMove(c1, 7, 200, 180, 10, 500, 180)); anim.add(new LinearMove(m1, 7, 200, 120, 10, 500, 120)); 45) 45) float 1 4 Figure moveto() Animation 46) moveto() class Car implements Figure, Animation { Triangle t1, t2; Rect r1; Circle c1, c2; float unit, time; public Car(Color c, float u, float x, float y) { t1 = new Triangle(c, x-u*3, y, x-u*2, y-u*2, x+u*3, y); t2 = new Triangle(c, x-u*2, y-u*2, x+u*2, y-u*2, x+u*3, y); r1 = new Rect(c, x, y+u, u*8, u*2); c1 = new Circle(c.darker(), x-u*2, y+u*2, u); c2 = new Circle(c.darker(), x+u*2, y+u*2, u); unit = u; public void moveto(float x, float y) { float d = {0f, unit/4, 0f, -unit/4[(int)(10*time) % 4]; t1.moveto(x-unit*3, y); t2.moveto(x-unit*2, y-unit*2); r1.moveto(x, y+unit); c1.moveto(x-unit*2, y+unit*2+d); c2.moveto(x+unit*2, y+unit*2-d); public void setcolor(color c) { t1.setcolor(c); t2.setcolor(c); r1.setcolor(c); c1.setcolor(c.darker()); c2.setcolor(c.darker()); public void settime(float t) { time = t; public void draw(graphics g) { t1.draw(g);t2.draw(g);r1.draw(g);c1.draw(g);c2.draw(g); 46) TimedAnimation 7 5 (state) (transition) (state transition diagram) 19
20 7-2: 7 47) 47) 8 7: 4 8: 4 1 ( ) ( ) Figure Animation figs anim 1 Scene 20
21 static class Scene { ArrayList<Figure> figs = new ArrayList<Figure>(); ArrayList<Animation> anim = new ArrayList<Animation>(); boolean ended = false; Scene next = null; public void draw(graphics g) { for(figure f: figs) { f.draw(g); public void settime(float t) { for(animation a: anim) { a.settime(t); public void press(int x, int y) { public boolean isended() { return ended; public Scene getnext() { return next;?? static class Scene1 extends Scene { Circle c1 = new Circle(Color.YELLOW, 100, 100, 60); Circle c2 = new Circle(Color.YELLOW, 250, 100, 60); public Scene1() { Picture p1 = new Picture("kuno1.png", 0, 0); Picture p2 = new Picture("sun1.png", 0, 0); figs.add(c1); figs.add(c2); figs.add(p1); figs.add(p2); anim.add(new ShakeMove(p1, 100, 100, 10, 10)); anim.add(new ShakeMove(p2, 250, 100, 10, 10)); figs.add(new Text(20, 25, " ", new Font("serif", Font.BOLD, 18))); public void press(int x, int y) { if(c1.hit(x, y)) { next = new Scene2(); ended = true; else if(c2.hit(x, y)) { next = new Scene4(); ended = true; 48) ended = (t > 5) 2 5 ended t > ( 1 5 ) 48) ended true false 21 5 true
22 static class Scene2 extends Scene { public Scene2() { next = new Scene3(); figs.add(new Text(20, 90, " ", new Font("serif", Font.BOLD, 18))); public void press(int x, int y) { ended = true; public void settime(float t) { ended = (t > 5); 3 49) figs anim 49) settime() settime() ended true static class Scene3 extends Scene { public Scene3() { next = new Scene1(); // ; figs anim public void settime(float t) { super.settime(t); ended = (t > 14); ok ZigzagMove static class Scene4 extends Scene { Font fn = new Font("serif", Font.BOLD, 18); Text t1 = new Text(20, 25, " ", fn); Text t2 = new Text(20, 55, "0.00", fn); Circle c1 = new Circle(Color.BLUE, 60, 200, 20); boolean ok = false; float curtime = 0f, endtime = 60f; public Scene4() { next = new Scene1(); figs.add(t1); figs.add(t2); figs.add(c1); anim.add(new ZigzagMove(c1, 1f, 60, 200, 340, 40)); public void press(int x, int y) { if(!c1.hit(x, y)) { return; ok = true; c1.setcolor(color.red); endtime = curtime + 5; t1.settext((curtime<3f)?"good Job!":"So-so"); public void settime(float t) { super.settime(t); curtime = t; ended = (t > endtime); if(!ok) { t2.settext(string.format("%4.2f", t)); 22
23 press() ok true 5 Good Job! So-so settime() settime() ok cur 50) cur press() 50) 1 settime() 51) 51) import java.awt.*; import java.awt.event.*; import java.awt.image.*; import java.io.*; import java.util.*; import javax.imageio.*; import javax.swing.*; public class Sample72 extends JPanel { Scene cur = new Scene1(); long tm0 = System.currentTimeMillis(); public Sample72() { setopaque(false); addmouselistener(new MouseAdapter() { public void mousepressed(mouseevent evt) { cur.press(evt.getx(), evt.gety()); ); new javax.swing.timer(30, new ActionListener() { public void actionperformed(actionevent evt) { float tm = 0.001f*(System.currentTimeMillis()-tm0); cur.settime(tm); repaint(); if(cur.isended()) { cur = cur.getnext(); tm0 = System.currentTimeMillis(); ).start(); Text Picture SimpleFigure // paintcomponent, main, Scene Scene4 23
24 // Figure, Animation, SimpleFigure, Circle, Rect, Triangle static class Text extends SimpleFigure { String txt; Font fn; public Text(int x, int y, String t, Font f) { super(color.black, x, y); txt = t; fn = f; public void settext(string t) { txt = t; public void draw(graphics g) { super.draw(g); g.setfont(fn); g.drawstring(txt, (int)xpos, (int)ypos); static class Picture extends SimpleFigure { BufferedImage img; int width, height; public Picture(String fname, int x, int y) { super(color.white, x, y); try { img = ImageIO.read(new File(fname)); catch(exception ex) { xpos = x; ypos = y; width = img.getwidth(); height = img.getheight(); public void draw(graphics g) { int x = (int)xpos-width/2, y = (int)ypos-height/2; g.drawimage(img, x, y, null); // // Scene 7-2 Sample72.java a. b. Good Job c. Schene d. Scene2 Scene2 Text 24
25 TextScene 4 52) 52) e. 1 getnext() ( N Scene ) 1 DiceScene f. 53) 53) 7-2-d 1 TextScene static class TextScene extends Scene { Text t1; float endtime; public TextScene(Text t, float e, Scene n) { t1 = t; endtime = e; next = n; figs.add(t); public void press(int x, int y) { ended = true; public void settime(float t) { ended = (t > endtime); public void setnext(scene s) { next = s; public Scene getnext() { ended = false; return next; getnext() setnext() 54) 54) 55) Font fn = new Font("sansserif", Font.BOLD, 72); TextScene s3 = new TextScene(new Text(90,90," ",fn),5f,null); TextScene s2 = new TextScene(new Text(90,90," ",fn),5f,s3); TextScene s1 = new TextScene(new Text(90,90," ",fn),5f,s2); cur = new TextScene(new Text(100, 100, " ", fn), 5, s1); s3.setnext(cur); 55) "sansserif" ( ) 25
26 7-2-d DiceScene 56) draw() 56) 57) 57) static class DiceScene extends Scene { getnext() Picture[] pics; Scene[] scenes; int sel = 0, fin = -1; float curtime, endtime = 20f; public DiceScene(Picture[] ps, Scene[] ss) { pics = ps; scenes = ss; public void draw(graphics g) { pics[sel].draw(g); public void press(int x, int y) { fin = sel; next = scenes[sel]; endtime = curtime + 3; public void settime(float t) { curtime = t; ended = (t > endtime); if(fin < 0) { sel = (int)(t*8) % pics.length; public Scene getnext() { ended = false; fin = -1; endtime = 20f; return next; 58) ) 3 6 Font fn = new Font("sansserif", Font.BOLD, 72); TextScene s0 = new TextScene(new Text(10,90," ",fn), 5f, null); TextScene s1 = new TextScene(new Text(90,90," ",fn),5f,s0); TextScene s2 = new TextScene(new Text(90,90," ",fn),5f,s0); TextScene s3 = new TextScene(new Text(90,90," ",fn),5f,s0); DiceScene d1 = new DiceScene( new Picture[]{new Picture("d1.png",90,90), new Picture("d2.png",190,90),new Picture("d3.png",290,90), new Scene[]{s1, s2, s3); s0.setnext(d1); cur = s0; 6 26
27 1 Scene figs anim Scene Scene 27
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));
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.*;
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
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;
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
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
: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
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
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 IDESun Microsystems Oracle NetBeans, IBM 1 Eclipse 2, JetBrains IntelliJ IDEA IDE GUI JDK Java 2.1 Hello World! 2.1.1 Java 2.1.1 GUI
やさしい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
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
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
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
[email protected] [email protected] 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
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
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
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..........................................
< F2D82518CC282CC D2E6A7464>
2 個のさいころ 1. はじめに [Java アプレット ] [Java アプリケーション ] 2 個のさいころを同時に投げたときの目の出方を考えてみましょう この 2 個のさいころをそれぞれ さいころ Ⅰ さいころ Ⅱ とすると その目の出方は順に 1 1 2 1 3 1 4 1 5 1 6 1 1 2 2 2 3 2 4 2 5 2 6 2 1 3 2 3 3 3 4 3 5 3 6 3 1 4
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("
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
< 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 の係数
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............................
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
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
2.2 Java C main Java main 2 C 6 C Java 3 C Java ( ) G101Hello.java G101Hello main G101Hello.java /* G101Hello */ class G101Hello { /* main */ public s
2 2013 4 16 2.1............................... 2 1 2.2 Java......................... 2 2 2.3............. 2 2 2.4................................ 2 4 2.5............................ 2 5 2.6............................
2 p.2 2 Java > javac Hello0.java Hello0.class JVM Hello0 java > java Hello0.class Hello World! javac Java JVM java JVM : Java > javac 2> Q Foo.j
2 p.1 2 Java Java JDK Sun Microsystems Oracle JDK javac Java java JVM appletviewer IDESun Microsystems Oracle NetBeans, IBM 1 Eclipse 2, JetBrains IntelliJ IDEA IDE GUI JDK Java 2.1 Hello World! 2.1.1
< F2D825282CC947B909482CC A815B83682E6A>
3 の倍数のトランプカード 1. はじめに [Java アプレット ] [Java アプリケーション ] ここにトランプが 1 組あります ジョーカー 2 枚を除いて 52 枚を使います 3 の倍数は スペード クローバ ダイヤ ハートに それぞれ 3 と 6 と 9 と 12 の 4 枚ずつあるので 4 4=16 枚あります この 52 枚のトランプから 1 枚引いたとき そのカードが 3 の倍数である確率を考えます
課題
float xball;// 円の中心の X 座標 float yball; // 円の中心の Y 座標 float rball; // 円の半径 color cball; // 円の色 // 円を移動させる void updateball(){ yball -= 1; if(yball+rball< 0){ yball = height+rball; // 円を描く void drawball(){
< F2D A839382CC906A2E6A7464>
ビュホンの針 1. はじめに [Java アプレット ] [Java アプリケーション ] ビュホン ( Buffon 1707-1788) は 針を投げて円周率 πを求めることを考えました 平面上に 幅 2aの間隔で 平行線を無数に引いておきます この平面上に長さ2bの針を落とすと この針が平行線と交わる確立 pは p=(2b) (aπ) 1 となります ただし b
新・明解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,
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
< F2D F B834E2E6A7464>
ランダムウォーク [Java アプレット ] [Java アプレリケーョン ] 1. はじめに 酔っぱらいは前後左右見境なくふらつきます 酔っぱらいは目的地にたどり着こうと歩き回っているうちに何度も同じところに戻って来てしまったりするものです 今 酔っぱらいが数直線上の原点にいるとします 原点を出発して30 回ふらつくとき 30 回目に酔っぱらいがいる位置は 出発点である原点からどれくらい離れてしまっているのでしょうか
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
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
< 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 シミュレーションソフト
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;
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
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
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
: : : TSTank 2
Java (8) 2008-05-20 Lesson6 Lesson5 Java 1 Lesson 6: TSTank1, TSTank2, TSTank3 java 2 car1 car2 Car car1 = new Car(); Car car2 = new Car(); car1.setcolor(red); car2.setcolor(blue); car2.changeengine(jet);
Java言語 第1回
Java 言語 第 10 回ウインドウ型アプリケーション (1) 知的情報システム工学科 久保川淳司 [email protected] 前回の課題 (1) ボーダーレイアウト, グリッドレイアウト, パネルを使用して, 電卓風のボタンを実現する BorderLayout で NORTH, CENTER, SOUTH に分割 NORTHにはテキストフィールドを設定 CENTERにはパネルを使って9つのボタンを設定
Java言語 第1回
Java 言語 第 8 回ウインドウ部品を用いる (1) 知的情報システム工学科 久保川淳司 [email protected] 前回の課題 (1) マウスを使って, 前回課題で作成した 6 4 のマスの図形で, \ をマウスクリックによって代わるようにしなさい 前回の課題 (2) import java.applet.applet; import java.awt.*;
/ ( ) 8/7/2003 13:21 p.2/64
B 12 I [email protected] N208 8/7/2003 13:21 p.1/64 / ( ) 8/7/2003 13:21 p.2/64 8/7/2003 13:21 p.3/64 2! 12 7/ 8 1 13 7/15 2 / ( ) 11 (SFC ) ( 5 ) 8/7/2003 13:21 p.4/64 10 2003/7/22 23:59 JST 11 ( )
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
PowerPoint プレゼンテーション
2016/03/11 NetBeans ではじめる Java 第二回 画像処理ソフトウェアの開発 ArkOak 代表 加納徹 Java 講習会の流れ 5. 画像の入出力 6. マウスによる画像情報の取得 7. 画像の上からお絵描き 8. 画像処理ソフトウェアの開発 2 5. 画像の入出力 新規プロジェクト ImageProcessing を作ろう 画像の入出力 1. 以下のようにラベルとボタンを配置
次の演習課題(1),(2)のプログラムを完成させよ
次の演習課題 (1),(2) のプログラムを作成せよ. 課題 (1) ボタン押下時の処理を追加し以下の実行結果となるようにプログラムを作成しなさい ( ボタン押下時の処理 ) import java.lang.*; class Figure extends JFrame implements ActionListener{ JPanel panel; JScrollPane scroll; JTextArea
r1.dvi
2006 1 2006.10.6 ( 2 ( ) 1 2 1.5 3 ( ) Ruby Java Java Java ( Web Web http://lecture.ecc.u-tokyo.ac.jp/~kuno/is06/ / ( / @@@ ( 3 ) @@@ : ( ) @@@ (Q&A) ( ) 1 http://www.sodan.ecc.u-tokyo.ac.jp/cgi-bin/qbbs/view.cgi
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
JavaプログラミングⅠ
Java プログラミング Ⅰ 3 回目変数 今日の講義で学ぶ内容 変数とは 変数の使い方 キーボード入力の仕方 変 数 変 数 一時的に値を記憶させておく機能です 変数は 型 ( データ型ともいいます ) と識別子をもちます 2 型 変数に記憶できる値の種類です型は 値の種類に応じて次の 8 種類があり これを基本型といいます 基本型値の種類値の範囲または例 boolean 真偽値 true または
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(
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)
PowerPoint Presentation
ソフトウェア演習 B GUI を持つ Java プログラムの 設計と実装 4.1 例題 :GUI を持った電卓を作ろう プロジェクトCalculator パッケージ名 :example ソースファイル : Calculator.java GUI.java EventProcessor.java 2 4.2 GUI とイベント処理 GUI の構成 :Swing GUI の場合 フレーム JFrame:
