home *** CD-ROM | disk | FTP | other *** search
/ Internet 1996 World Exposition / park.org.s3.amazonaws.com.7z / park.org.s3.amazonaws.com / Japan / NTT / DM- / hotjava / classes / src / Ntt_07p.java < prev    next >
Encoding:
Java Source  |  2017-09-21  |  15.1 KB  |  475 lines

  1. /*
  2.  *
  3.  *     NTT-07P     (JAVA Beta2)
  4.  *
  5.  *     Nextage  Y.Amemoto
  6.  *                  1996/01/01
  7.  *
  8.  */
  9. import java.io.InputStream;
  10. import java.awt.*;
  11. import java.net.*;
  12. import java.applet.AudioClip;
  13.  
  14. public class Ntt_07p extends java.applet.Applet implements Runnable {
  15.     Thread kicker = null;
  16.     Image im,imLine;
  17.     Graphics off,offLine;
  18.     Image imBack;
  19.     Image mkokusai,mkokunai,mgaikoku,mkaitei,mcompu,mtel,mfax,mtan;
  20.     Ntt_07pLINE line[];
  21.     Ntt_07pKIKI kiki[];
  22.     Ntt_07pKOUKAN koukan[];
  23.     Ntt_07pDENPA denpa[];
  24.     Ntt_07pKAITEI kaitei;
  25.     boolean first = true;
  26.     int click = -1, step;
  27.  
  28.     public void init() {
  29.         int lXY[][] = {
  30.             { 55,205,100,185},  //compuA kokunaiA
  31.             { 75,225,100,185},  //telA   kokunaiA
  32.             {105,225,100,185},  //faxA   kokunaiA
  33.             {135,215,100,185},  //tanA   kokunaiA
  34.             {100,185,150,170},  //kokunaiA kokusaiA
  35.             {150,170,140,140},  //kokusaiA antenaA
  36.             {395,205,335,185},  //compuB kokunaiB
  37.             {365,225,335,185},  //telB   kokunaiB
  38.             {335,225,335,185},  //faxB   kokunaiB
  39.             {305,215,335,185},  //tanB   kokunaiB
  40.             {335,185,280,170},  // kokunaiB kokusaiB
  41.             {280,170,300,140}   // kokusaiB antenaB
  42.         };
  43.  
  44.         im = createImage(size().width, size().height);
  45.         off = im.getGraphics();
  46.         imLine = createImage(size().width, size().height);
  47.         offLine = imLine.getGraphics();
  48.  
  49.         kaitei = new Ntt_07pKAITEI(168,160, this);
  50.  
  51.         denpa = new Ntt_07pDENPA[2];
  52.         denpa[0] = new Ntt_07pDENPA(155,115,210,60);
  53.         denpa[1] = new Ntt_07pDENPA(280,115,220,60);
  54.  
  55.         line = new Ntt_07pLINE[12];
  56.         for (int i = 0; i < 12; i++)
  57.             line[i] = new Ntt_07pLINE(lXY[i][0],lXY[i][1],lXY[i][2],lXY[i][3]);
  58.  
  59.         koukan = new Ntt_07pKOUKAN[7];
  60.         koukan[0] = new Ntt_07pKOUKAN(85,155,"kokunai", this);//kokunaiA
  61.         koukan[1] = new Ntt_07pKOUKAN(135,135,"kokusai", this);//kokusaiA
  62.         koukan[2] = new Ntt_07pKOUKAN(125,115,"antenaA", this);//antenaA
  63.         koukan[3] = new Ntt_07pKOUKAN(200,20,"eisei", this);
  64.         koukan[4] = new Ntt_07pKOUKAN(285,115,"antenaB", this);//antenaB
  65.         koukan[5] = new Ntt_07pKOUKAN(265,135,"kokusai", this);//kokusaiB
  66.         koukan[6] = new Ntt_07pKOUKAN(315,155,"kokunai", this);//kokunaiB
  67.  
  68.         kiki = new Ntt_07pKIKI[8];
  69.         kiki[0] = new Ntt_07pKIKI( 35,185,"compu", "A", this);
  70.         kiki[1] = new Ntt_07pKIKI( 60,195,"tel", "A", this);
  71.         kiki[2] = new Ntt_07pKIKI( 90,210,"fax", "A", this);
  72.         kiki[3] = new Ntt_07pKIKI(125,205,"tan", "A", this);
  73.         kiki[4] = new Ntt_07pKIKI(379,185,"compu", "B", this);
  74.         kiki[5] = new Ntt_07pKIKI(360,195,"tel", "B", this);
  75.         kiki[6] = new Ntt_07pKIKI(315,210,"fax", "B", this);
  76.         kiki[7] = new Ntt_07pKIKI(285,205,"tan", "B", this);
  77.  
  78.         imBack = getImage(getCodeBase(), "images/titlec.gif");
  79.         mkokusai = getImage(getCodeBase(), "images/mkokusai.gif");
  80.         mkokunai = getImage(getCodeBase(), "images/mkokunai.gif");
  81.         mgaikoku = getImage(getCodeBase(), "images/mgaikoku.gif");
  82.         mkaitei = getImage(getCodeBase(), "images/mkaitei.gif");
  83.         mcompu = getImage(getCodeBase(), "images/mcompu.gif");
  84.         mtel = getImage(getCodeBase(), "images/mtel.gif");
  85.         mfax = getImage(getCodeBase(), "images/mfax.gif");
  86.         mtan = getImage(getCodeBase(), "images/mtan.gif");
  87.     }
  88.  
  89.     public void run() {
  90.         Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
  91.         while (kicker != null) {
  92.             if (click >= 0 && click < 4) {
  93.                 switch (++step) {
  94.                 case 0: kiki[click].CALL();  break;
  95.                 case 1: line[click].ON();    break;
  96.                 case 2: line[4].ON();        break;
  97.                 case 3: if ((int)(Math.random()*2) == 0) step = 4;
  98.                         else                             step = 9;
  99.                         continue;
  100.                 case 5: line[5].ON();        break;
  101.                 case 6: denpa[0].ON();       break;
  102.                 case 7: denpa[1].ON();       break;
  103.                 case 8: line[11].ON();       break;
  104.                 case 9: step++; continue;
  105.                 case 10: kaitei.ON();        break;
  106.                 case 11: line[10].ON();      break;
  107.                 case 12: line[click+6].ON(); break;
  108.                 case 13: kiki[click+4].RECEIVE(); break;
  109.                 case 14: break;
  110.                 case 15: allOff();           break;
  111.                 }
  112.                 repaint();
  113.                 try { Thread.sleep(500); } catch (InterruptedException e) { return; }
  114.             }
  115.  
  116.             if (click >= 4 && click < 8) {
  117.                 switch (++step) {
  118.                 case 0: kiki[click].CALL();  break;
  119.                 case 1: line[click+2].ON();  break;
  120.                 case 2: line[10].ON();       break;
  121.                 case 3: if ((int)(Math.random()*2) == 0) step = 4;
  122.                         else                             step = 9;
  123.                         continue;
  124.                 case 5: line[11].ON();       break;
  125.                 case 6: denpa[1].ON();       break;
  126.                 case 7: denpa[0].ON();       break;
  127.                 case 8: line[5].ON();        break;
  128.                 case 9: step++; continue;
  129.                 case 10: kaitei.ON();        break;
  130.                 case 11: line[4].ON();       break;
  131.                 case 12: line[click-4].ON(); break;
  132.                 case 13: kiki[click-4].RECEIVE(); break;
  133.                 case 14: break;
  134.                 case 15: allOff();           break;
  135.                 }
  136.                 repaint();
  137.                 try { Thread.sleep(500); } catch (InterruptedException e) { return; }
  138.             }
  139.             repaint();
  140.             try { Thread.sleep(10); } catch (InterruptedException e) { return; }
  141.         }
  142.     }
  143.  
  144.     public void allOff() {
  145.         for (int i = 0; i < 12; i++)
  146.             line[i].OFF();
  147.         for (int i = 0; i < 8; i++)
  148.             kiki[i].OFF();
  149.         denpa[0].OFF();
  150.         denpa[1].OFF();
  151.         kaitei.OFF();
  152.         click = -1;
  153.     }
  154.  
  155.     public void paint(Graphics g) {
  156.         update(g);
  157.     }
  158.     public void update(Graphics g) {
  159.         offLine.drawImage(imBack,0,30,this);
  160.         if (first) {
  161.             off.drawString("Loading...",0,20);
  162.             if (chkKiki() && chkKoukan()) {
  163.                 first = false;
  164.             }
  165.         }
  166.         else {
  167.             denpa[0].drawDENPA(offLine);
  168.             denpa[1].drawDENPA(offLine);
  169.             for (int i = 0; i < 12; i++) {
  170.                 line[i].drawLINE(offLine);
  171.             }
  172.         }
  173.         off.drawImage(imLine,0,0,this);
  174.         kaitei.drawKAITEI(off, this);
  175.         for (int i = 0; i < 7; i++)
  176.             koukan[i].drawKOUKAN(off, this);
  177.         for (int i = 0; i < 8; i++)
  178.             kiki[i].drawKIKI(off, this);
  179.  
  180.         off.drawImage(mkokusai,165,135,this);
  181.         off.drawImage(mkokusai,305,135,this);
  182.         off.drawImage(mkokunai, 30,160,this);
  183.         off.drawImage(mgaikoku,340,160,this);
  184.         off.drawImage(mkaitei,185,195,this);
  185.         off.drawImage(mcompu,  2,220,this);
  186.         off.drawImage(mcompu,385,220,this);
  187.         off.drawImage(mtel, 50,240,this);
  188.         off.drawImage(mtel,360,240,this);
  189.         off.drawImage(mfax, 95,243,this);
  190.         off.drawImage(mfax,325,243,this);
  191.         off.drawImage(mtan,140,240,this);
  192.         off.drawImage(mtan,270,240,this);
  193.  
  194.         g.drawImage(im, 0,0,this);
  195.         if (first) g.drawString("Loading...",0,20);
  196.     }
  197.  
  198.     boolean chkKiki() {
  199.         for (int i = 0; i < 8; i++) {
  200.             if (kiki[i].chkImage(this)==false) {
  201.                 return false;
  202.             }
  203.         }
  204.         return true;
  205.     }
  206.     boolean chkKoukan() {
  207.         for (int i = 0; i < 7; i++) {
  208.             if (koukan[i].chkImage(this)==false) {
  209.                 return false;
  210.             }
  211.         }
  212.         return true;
  213.     }
  214.     public void start() {
  215.         if (kicker == null) {
  216.             kicker = new Thread(this);
  217.             kicker.start();
  218.         }
  219.     }
  220.  
  221.     public void stop() {
  222.         kicker = null;
  223.     }
  224.     public boolean mouseDown(java.awt.Event evt, int x, int y) {
  225.         if (click != -1) return true;
  226.         for (int i = 0; i < 8; i++) {
  227.             if (kiki[i].chkArea(x,y)==true) {
  228.                 click = i;
  229.                 step = -1;
  230.             }
  231.         }
  232.         return true;
  233.     }
  234. }
  235.  
  236. class Ntt_07pKOUKAN {
  237.     int X,Y;
  238.     Image imKoukan;
  239.     Ntt_07pKOUKAN(int x, int y, String im_name, Ntt_07p parent) {
  240.         X = x;
  241.         Y = y;
  242.         imKoukan = parent.getImage(parent.getCodeBase(), "images/" + im_name + ".gif");
  243.     }
  244.     boolean chkImage(Ntt_07p parent) {
  245.         if (parent.prepareImage(imKoukan, parent) == false)
  246.             return false;
  247.         return true;
  248.     }
  249.     void drawKOUKAN(Graphics OS, Ntt_07p parent) {
  250.         OS.drawImage(imKoukan, X, Y, parent);
  251.     }
  252. }
  253.  
  254. class Ntt_07pKIKI {
  255.     int X,Y, width,height;
  256.     Image imKiki[];
  257.     AudioClip auCall[];
  258.     boolean GOT, ONOFF;
  259.     Ntt_07pKIKI(int x, int y, String name, String ab, Ntt_07p parent) {
  260.         GOT = ONOFF = false;
  261.         X = x;
  262.         Y = y;
  263.         imKiki = new Image[2];
  264.         auCall = new AudioClip[2];
  265.         for (int i = 0; i < 2; i++) {
  266.             imKiki[i] = parent.getImage(parent.getCodeBase(), "images/" + name + ab + i + ".gif");
  267.             auCall[i] = parent.getAudioClip(parent.getCodeBase(), "audio/" + name + i + ".au");
  268.         }
  269.     }
  270.     void OFF() {
  271.         ONOFF = false;
  272.     }
  273.     void CALL() {
  274.         ONOFF = true;
  275.         auCall[0].play();
  276.     }
  277.     void RECEIVE() {
  278.         ONOFF = true;
  279.         auCall[1].play();
  280.     }
  281.     boolean chkImage(Ntt_07p parent) {
  282.         for (int i = 0; i < 2; i++) {
  283.             if (parent.prepareImage(imKiki[i], parent) == false) {
  284.                 return false;
  285.             }
  286.         }
  287.         width = imKiki[0].getWidth(parent);
  288.         height = imKiki[0].getHeight(parent);
  289.         GOT = true;
  290.         return true;
  291.     }
  292.     void drawKIKI(Graphics OS, Ntt_07p parent) {
  293.         if (!ONOFF) {
  294.             OS.drawImage(imKiki[0], X, Y, parent);
  295.         }
  296.         else {
  297.             OS.drawImage(imKiki[1], X, Y, parent);
  298.         }
  299.     }
  300.     boolean chkArea(int x, int y) {
  301.         if (x > X && x < X+width && y > Y && y < Y+height)
  302.             return true;
  303.         return false;
  304.     }
  305. }
  306.  
  307. class Ntt_07pKAITEI {
  308.     int X,Y;
  309.     Image imKaitei[];
  310.     boolean ONOFF;
  311.     Ntt_07pKAITEI(int x, int y, Ntt_07p parent) {
  312.         ONOFF = false;
  313.         X = x;
  314.         Y = y;
  315.         imKaitei = new Image[2];
  316.         for (int i = 0; i < 2; i++)
  317.             imKaitei[i] = parent.getImage(parent.getCodeBase(), "images/kaitei" + i + ".gif");
  318.     }
  319.     void OFF() {
  320.         ONOFF = false;
  321.     }
  322.     void ON() {
  323.         ONOFF = true;
  324.     }
  325.     void drawKAITEI(Graphics OS, Ntt_07p parent) {
  326.         if (ONOFF) {
  327.             OS.drawImage(imKaitei[1], X, Y, parent);
  328.         }
  329.         else {
  330.             OS.drawImage(imKaitei[0], X, Y, parent);
  331.         }
  332.     }
  333. }
  334.  
  335. class Ntt_07pLINE {
  336.     int X1, Y1, X2, Y2;
  337.     boolean ONOFF;
  338.     Ntt_07pLINE(int x1, int y1, int x2, int y2) {
  339.         ONOFF = false;
  340.         X1 = x1; Y1 = y1; X2 = x2; Y2 = y2;
  341.     }
  342.     void ON() {
  343.         ONOFF = true;
  344.     }
  345.     void OFF() {
  346.         ONOFF = false;
  347.     }
  348.     void drawLINE(Graphics OS) {
  349.         if (ONOFF) {
  350.             Line(Color.yellow, OS);
  351.         }
  352.         else {
  353.             Line(Color.darkGray, OS);
  354.         }
  355.     }
  356.     void Line(Color col, Graphics OS) {
  357.         OS.setColor(col);
  358.         if (X1 == X2) {   // tate
  359.             for (int i = -2; i <= 1; i++) {
  360.                 OS.drawLine(X1+i,Y1,X1+i,Y2);
  361.             }
  362.         }
  363.         else {
  364.             if (Y1 == Y2) {   // yoko
  365.                 for (int i = -2; i <= 1; i++) {
  366.                     OS.drawLine(X1,Y1+i,X2,Y2+i);
  367.                 }
  368.             }
  369.             else {
  370.                 OS.drawLine(X1,Y1,X2,Y2);
  371.                 for (int i = 1; i <= 2; i++) {
  372.                     OS.drawLine(X1,Y1-i,X2-i,Y2);
  373.                     OS.drawLine(X1,Y1+i,X2-i,Y2);
  374.                     OS.drawLine(X1+i,Y1,X2,Y2+i);
  375.                     OS.drawLine(X1+i,Y1,X2,Y2-i);
  376.                 }
  377.             }
  378.         }
  379.     }
  380. }
  381.  
  382. class Ntt_07pDENPA {
  383.     int XX1, YY1, XX2, YY2;
  384.     boolean ONOFF;
  385.     Ntt_07pDENPA(int x1, int y1, int x2, int y2) {
  386.         ONOFF = false;
  387.         XX1 = x1; YY1 = y1; XX2 = x2; YY2 = y2;
  388.     }
  389.     void ON() {
  390.         ONOFF = true;
  391.     }
  392.     void OFF() {
  393.         ONOFF = false;
  394.     }
  395.     void drawDENPA(Graphics OS) {
  396.         if (ONOFF) {
  397.             int tx1, ty1, tx2, ty2;
  398.             if (XX1 < XX2) {
  399.                 tx1 = XX1+(XX2-XX1)/2+(int)(Math.random()*10)+5;
  400.                 tx2 = XX1+(XX2-XX1)/2-((int)(Math.random()*10)+5);
  401.             }
  402.             else {
  403.                 tx1 = XX1+(XX2-XX1)/2-(int)(Math.random()*10)+5;
  404.                 tx2 = XX1+(XX2-XX1)/2+((int)(Math.random()*10)+5);
  405.             }
  406.             ty1 = YY1+(YY2-YY1)/2+(int)(Math.random()*10)-5;
  407.             ty2 = YY1+(YY2-YY1)/2+(int)(Math.random()*10)-5;
  408.             Line(XX1,YY1,tx1,ty1,Color.yellow, OS);
  409.             Line(tx1,ty1,tx2,ty2,Color.yellow, OS);
  410.             Line(tx2,ty2,XX2,YY2,Color.yellow, OS);
  411.         }
  412.     }
  413.     void Line(int X1, int Y1, int X2, int Y2, Color col, Graphics OS) {
  414.         OS.setColor(col);
  415.         if (X1 == X2) {   // tate
  416.             for (int i = -2; i <= 1; i++) {
  417.                 OS.drawLine(X1+i,Y1,X1+i,Y2);
  418.             }
  419.         }
  420.         else {
  421.             if (Y1 == Y2) {   // yoko
  422.                 for (int i = -2; i <= 1; i++) {
  423.                     OS.drawLine(X1,Y1+i,X2,Y2+i);
  424.                 }
  425.             }
  426.             else {
  427.                 OS.drawLine(X1,Y1,X2,Y2);
  428.                 for (int i = 1; i <= 2; i++) {
  429.                     OS.drawLine(X1,Y1-i,X2-i,Y2);
  430.                     OS.drawLine(X1,Y1+i,X2-i,Y2);
  431.                     OS.drawLine(X1+i,Y1,X2,Y2+i);
  432.                     OS.drawLine(X1+i,Y1,X2,Y2-i);
  433.                 }
  434.             }
  435.         }
  436.     }
  437. }
  438.  
  439.  
  440. /*---------------------not use
  441. class Ntt_07pKOUKAN {
  442.     int X,Y;
  443.     Image imKoukan[];
  444.     boolean ONOFF;
  445.     Ntt_07pKOUKAN(int x, int y, String im_name, Ntt_07p parent) {
  446.         X = x;
  447.         Y = y;
  448.         ONOFF = false;
  449.         imKoukan = new Image[2];
  450.         for (int i = 0; i < 2; i++) {
  451.             imKoukan[i] = parent.getImage(parent.getCodeBase(), "images/" + im_name + i + ".gif");
  452.         }
  453.     }
  454.     boolean chkImage(Ntt_07p parent) {
  455.         for (int i = 0; i < 2; i++)
  456.             if (parent.prepareImage(imKoukan[i], parent) == false)
  457.                 return false;
  458.         return true;
  459.     }
  460.     void ON() {
  461.         ONOFF = true;
  462.     }
  463.     void OFF() {
  464.         ONOFF = false;
  465.     }
  466.     void drawKOUKAN(Graphics OS, Ntt_07p parent) {
  467.         if (ONOFF)
  468.             OS.drawImage(imKoukan[1], X, Y, parent);
  469.         else
  470.             OS.drawImage(imKoukan[0], X, Y, parent);
  471.     }
  472. }
  473. */
  474.  
  475.