//
/* ---------------------------------------------------------------------------------------------- photo.java アナログ & デジタル ver. 1.00 (JDK 1.02) ueyama@infonet.co.jp 1998.09.01 ---------------------------------------------------------------------------------------------- */ import java.applet.Applet; import java.awt.*; import java.awt.image.*; public class photo extends Applet implements Runnable { int i,j; int Pgrd=0; // 写真の階調 0:256, 1:2, 2:4 ・・・ int Gx=400; // グラフ表示の X 座標値 int Gy=135; // グラフ表示の Y 座標値 int Data[]=new int[400*270]; // 写真の濃淡のデータ Image Photo[]=new Image[5]; Graphics gr; Button bt_start; Checkbox cb_256, cb_2, cb_4, cb_8, cb_16; Thread th=null; public void init() { gr=getGraphics(); setBackground(new Color(255,255,232)); MediaTracker mt=new MediaTracker(this); for(i=0,j=1;i<5;i++,j*=2) { Photo[i]=getImage(getCodeBase(),"photo"+j+".gif"); mt.addImage(Photo[i], 0); } try { mt.waitForID(0); } catch(InterruptedException e){}; CheckboxGroup cg=new CheckboxGroup(); Panel pb=new Panel(); pb.add(new Label("Gradation:")); pb.add(cb_2 =new Checkbox("2",cg,false)); pb.add(cb_4 =new Checkbox("4",cg,false)); pb.add(cb_8 =new Checkbox("8",cg,false)); pb.add(cb_16 =new Checkbox("16",cg,false)); pb.add(cb_256=new Checkbox("256",cg,true)); pb.add(bt_start=new Button("Graph")); setLayout(new BorderLayout()); add("South" ,pb); } public void start() { if(th==null) { th=new Thread(this); th.start(); } Gx=400; } public void update(Graphics g) { paint(g); } public int disp_grph(int x0, int y0) { int y1=340-(Data[Gy*400+x0] & 255)/4; y0=(x0==0)?y1:y0; gr.setColor(new Color(0,0,208)); // グラフの表示 gr.drawLine(x0,y0,x0,y1); return y1; } public void paint(Graphics g) { int c, y0=0; g.drawImage(Photo[Pgrd],0,0,400,270,this); g.clearRect(0,276,400,340); c=(Pgrd>1)? 2<<(Pgrd-1): 8; // c: Y軸目盛の本数 gr.setColor(new Color(0,224,224)); for(i=0;i戻る=400) th.suspend(); } } public boolean mouseDown(Event e, int mx, int my) { if(my<340 && Gx==400) { Gy=(my<270)? my:135; // 表示 Y 座標の変更 repaint(); } return true; } public boolean action(Event e, Object o) { if(e.target==cb_256) Pgrd=0; else if(e.target==cb_2) Pgrd=1; else if(e.target==cb_4) Pgrd=2; else if(e.target==cb_8) Pgrd=3; else if(e.target==cb_16) Pgrd=4; if(e.target==bt_start) { PixelGrabber pg=new PixelGrabber(Photo[Pgrd],0,0,400,270,Data,0,400); try { pg.grabPixels(); // 写真の濃淡データの取得 } catch (InterruptedException ie) {return false;} if((pg.status() & ImageObserver.ABORT) !=0) {return false;} th.resume(); } else th.suspend(); Gx=0; repaint(); return true; } public void stop() { if(th!=null) { th.stop(); th=null; } } } //