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(); public void paint(graphics g) { g.setcolor(color.green); g.fillrect(10,50,200,100); paint Graphics g Graphics setcolor() Graphics CG fillrect(x,y,w,h) x1,y1 w h CG (0,0,) y 18
CG getgraphics() paint CG CG Graphics getgraphics() background 19
void jbuttondraw_actionperformed(actionevent e) { Graphics g=jpanel1.getgraphics(); //Graphics g.setcolor(color.blue); g.drawline(0,0,100,100); Graphics getgraphics() Graphics Graphics g drawline(x1,x2,y1,y2) (x1,y1) (x2,y2) Graphics g CG getgraphics() Graphics CG 20
21
void jbuttonline_actionperformed(actionevent e) { Graphics g=jpanel1.getgraphics(); g.setcolor(color.blue); g.drawline(0,0,100,100); void jbuttonoval_actionperformed(actionevent e) { Graphics g=jpanel1.getgraphics(); g.setcolor(color.blue); g.drawoval(10,10,200,100); void jbuttonrect_actionperformed(actionevent e) { Graphics g=jpanel1.getgraphics(); g.setcolor(color.blue); g.drawrect(10,10,150,100); 22
void jbuttonclear_actionperformed(actionevent e) { int XMax=jPanel1.getWidth(); // int YMax=jPanel1.getHeight(); // Graphics g=jpanel1.getgraphics(); g.setcolor(color.white); g.fillrect(0,0,xmax,ymax); drawoval(x1,y1,w,h) (x1,y1) w h w (x1,y1) h (x1+w,y1+h) drawrect(x1,y1,w,h) (x1,y1) getwidth() getheight() draw fill 23
void jbuttondraw_actionperformed(actionevent e) { Graphics g=jpanel1.getgraphics(); if(jradiobuttonline.isselected()) { LineDraw(g); // else if(jradiobuttonrect.isselected()) { RectDraw(g); // else { OvalDraw(g); // LineDraw(g) RectDraw(g) OvalDraw(g) 24
(zukeidraw) (circle) 25
name jpanel1 jtextfieldradius jcheckboxfill Circle() void jbuttondraw_actionperformed(actionevent e) { Graphics g=jpanel1.getgraphics(); int r=integer.parseint(jtextfieldradius.gettext()); // Color cl; //Color boolean Fill=jCheckBoxFill.isSelected(); // int xc=jpanel1.getwidth()/2; // int yc=jpanel1.getheight()/2; // if( jradiobuttonred.isselected() ) { // cl=color.red; // cl else if ( jradiobuttonblue.isselected() ) { // cl=color.blue; // cl else { // cl=color.green; // cl Circle(g,xc,yc,r,cl,Fill); // 26
(polygon) Polygon void jbuttondraw_actionperformed(actionevent e) { Graphics g=jpanel1.getgraphics(); int xc=jpanel1.getwidth()/2; // int yc=jpanel1.getheight()/2; // int x[]=new int[3]; // int y[]=new int[3]; // y x[0]=xc-50; x[1]=xc; x[2]=xc+50; // y[0]=yc-10; y[1]=yc-40; y[2]=yc-10; // g.setcolor(color.blue); g.drawpolygon(x,y,3); // y[0]=yc+50; y[1]=yc+20; y[2]=yc+50; //y 60 g.fillpolygon(x,y,3); // drawpolygon(x,y,n) x[0],y[0] (x[n-1],y[n-1]) x[0],y[0] fillpolygon(x,y,n) 27
x[1] x[2] [] N 1 x 2 N x[1] x[2] x[n] N int x[]=new int[n]; double x[]=new double[n]; String x[]=new String[N]; Polygon 28
(ichimatsu) (daiya) 29
(flag) 2 (chaos) 3 drawline(x1,y1,x2,y2) (X1,Y1),(X2,Y2),(X3,Y3) (Xn,Yn) (Xn,Yn) Xn+1 Yn+1 Xn+1=Yn 0.97*Xn + 5 (1+Xn 2 ) 5 Yn+1 0.995* X1,Y1 =(1,0) Xn 30
1000 30000 Xn+1 Yn+1 6*Xn+1 6*Yn+1 6 Image 200 Xn+1 Yn+1 6 Xn+1 Yn+1 drawline 31