?? developerworks java.htm
字號:
<P>drawAngleline(g, x, y, s, (PI / 2D + angle) - a);
<BR>drawAngleline(g, x, y, s, PI / 2D + angle + a);
<BR>g.setColor(color); <BR>g.setFont(font);
<BR>g.drawString(str, x, y + 15); </P></BLOCKQUOTE>
<P>} else { <BR></P>
<BLOCKQUOTE>
<P>drawAngleline(g, x, y, s, angle - PI / 2D - a);
<BR>drawAngleline(g, x, y, s, (angle - PI / 2D) + a);
<BR>g.setColor(color); <BR>g.setFont(font);
<BR>g.drawString(str, x, y - 10); </P></BLOCKQUOTE>
<P>} <BR>g.setColor(oldcolor); <BR>g.setFont(oldfont);
</P></BLOCKQUOTE>
<P>} <BR><BR>public void drawCircle(Graphics g, int x, int y, int
r, int startAngle, int arcAngle) {
<BR> g.drawArc(x - r, y - r, 2 * r, 2 * r,
startAngle, arcAngle); <BR>} <BR><BR>public void
drawMarrow(Graphics g, int x0, int y0, int len, double angle,
String str, <BR>Color color, Font font) { </P>
<BLOCKQUOTE>
<P>int s = 8; <BR>double a = PI / 12D; <BR>Color oldcolor =
g.getColor(); <BR>Font oldfont = g.getFont();
<BR>drawAnglemline(g, x0, y0, len, angle); <BR>int x = x0 +
(int)((double)len * Math.cos(angle)); <BR>int y = y0 +
(int)((double)len * Math.sin(angle)); <BR>if(angle <= PI /
2D) { </P>
<BLOCKQUOTE>
<P>drawAngleline(g, x, y, s, (PI / 2D + angle) - a);
<BR>drawAngleline(g, x, y, s, PI / 2D + angle + a);
<BR>g.setColor(color); <BR>g.setFont(font);
<BR>g.drawString(str, x, y + 15); </P></BLOCKQUOTE>
<P>} else { </P>
<BLOCKQUOTE>
<P>drawAngleline(g, x, y, s, angle - PI / 2D - a);
<BR>drawAngleline(g, x, y, s, (angle - PI / 2D) + a);
<BR>g.setColor(color); <BR>g.setFont(font);
<BR>g.drawString(str, x, y - 10); </P></BLOCKQUOTE>
<P>} <BR>g.setColor(oldcolor); <BR>g.setFont(oldfont);
</P></BLOCKQUOTE>
<P>} <BR><BR>public void drawFillarrow(Graphics g, int x0, int y0,
double angle) { <BR></P>
<BLOCKQUOTE>
<P>int s = 10; <BR>int x[] = new int[3]; <BR>int y[] = new
int[3]; <BR>double a = PI / 12D; <BR>Color oldcolor =
g.getColor(); <BR>g.setColor(Color.red); <BR>x[0] = x0; <BR>y[0]
= y0; <BR>if(angle <= PI / 2D) { </P>
<BLOCKQUOTE>
<P>x[1] = x[0] + (int)((double)s * Math.cos((PI / 2D + angle)
- a)); <BR>y[1] = y[0] + (int)((double)s * Math.sin((PI / 2D +
angle) - a)); <BR>x[2] = x[0] + (int)((double)s * Math.cos(PI
/ 2D + angle + a)); <BR>y[2] = y[0] + (int)((double)s *
Math.sin(PI / 2D + angle + a)); </P></BLOCKQUOTE>
<P>} else { </P>
<BLOCKQUOTE>
<P>x[1] = x[0] + (int)((double)s * Math.cos(angle - PI / 2D -
a)); <BR>y[1] = y[0] + (int)((double)s * Math.sin(angle - PI /
2D - a)); <BR>x[2] = x[0] + (int)((double)s * Math.cos((angle
- PI / 2D) + a)); <BR>y[2] = y[0] + (int)((double)s *
Math.sin((angle - PI / 2D) + a)); </P></BLOCKQUOTE>
<P>} <BR>g.fillPolygon(x, y, 3); <BR>g.setColor(oldcolor);
</P></BLOCKQUOTE>
<P>} <BR>public void drawMline(Graphics g, int x0, int y0, int x,
int y) { <BR></P>
<BLOCKQUOTE>
<P>double m1 = Math.sqrt((x - x0) * (x - x0) + (y - y0) * (y -
y0)); <BR>int num = (int)(m1 / 5D); <BR>int x1 = x0; <BR>int y1
= y0; <BR>for(int i = 0; i < num; i++) { </P>
<BLOCKQUOTE>
<P>int x2 = x0 + (int)Math.round((double)(5 * (i + 1) * (x -
x0)) / m1); <BR>int y2 = y0 + (int)Math.round((double)(5 * (i
+ 1) * (y - y0)) / m1); <BR>if(i % 2 == 0)
<BR> g.drawLine(x1, y1, x2, y2); <BR>x1
= x2; <BR>y1 = y2; </P></BLOCKQUOTE>
<P>} </P></BLOCKQUOTE>
<P>} <BR><BR>public void drawAnglemline(Graphics g, int x0, int
y0, int len, double angle) { <BR> int x =
x0 + (int)((double)len * Math.cos(angle));
<BR> int y = y0 + (int)((double)len *
Math.sin(angle)); <BR> drawMline(g, x0, y0,
x, y); <BR>} <BR><BR>public double angleOfline(int x0, int y0, int
x, int y) { <BR></P>
<BLOCKQUOTE>
<P>double s = Math.sqrt((x - x0) * (x - x0) + (y - y0) * (y -
y0)); <BR>double angle = Math.acos((double)(x - x0) / s);
<BR>if(y >= y0) <BR> return angle;
<BR>else <BR> return PI - angle;
</P></BLOCKQUOTE>
<P>} <BR><BR>public double angleOfoval(int x, int y, int x0, int
y0, int a, int b) { <BR></P>
<BLOCKQUOTE>
<P>double s = Math.sqrt(Math.pow(b, 4D) * (double)(x - x0) *
(double)(x - x0) + Math.pow(a, 4D) * (double)(y - y0) *
(double)(y - y0)); <BR>double angle = Math.acos((double)(a * a *
(y - y0)) / s); <BR>if(x >= x0) <BR>return PI - angle;
<BR>else <BR>return angle; </P></BLOCKQUOTE>
<P>} <BR><BR>public GraphicsBean() {
<BR> PI = 6.2831852000000001D; <BR>} </P>
<P>public void fillCircle(Graphics g, int x0, int y0, int r, Color
color) { <BR></P>
<BLOCKQUOTE>
<P>Color oldcolor = g.getColor(); <BR>g.setColor(color);
<BR>g.fillArc(x0 - r, y0 - r, 2 * r, 2 * r, 0, 360);
<BR>g.setColor(oldcolor); </P></BLOCKQUOTE>
<P>} <BR><BR>public void fillCircle(Graphics g, int x0, int y0,int
l, int r, Color color1,Color color2,double angle) { </P>
<BLOCKQUOTE>
<P>Color oldcolor = g.getColor(); <BR>int
x1=x0-(int)(r+l*Math.cos(angle)); <BR>int
y1=y0-(int)(r+l*Math.sin(angle)); <BR>g.setColor(color1);
<BR>g.fillOval(x1,y1,2*r,2*r); <BR><BR>g.setColor(oldcolor);
</P></BLOCKQUOTE>
<P>} <BR><BR>public void Bar(Graphics g,int x,int y,int w,int
h,int type) <BR>{ </P>
<BLOCKQUOTE>
<P>if (type==0)
<BR> g.setColor(Color.white); <BR>if
(type==1) <BR> g.setColor(Color.black);
<BR>g.drawLine(x,y,x+w,y); <BR>g.drawLine(x,y,x,y+h); <BR>if
(type==1) <BR> g.setColor(Color.white);
<BR>if (type==0)
<BR> g.setColor(Color.black);
<BR>g.drawLine(x+w,y,x+w,y+h); <BR>g.drawLine(x,y+h,x+w,y+h);
</P></BLOCKQUOTE>
<P>} <BR><BR>//函數說明:該函數將畫出小程序的邊框,type為0時,為外邊框;
<BR>//type為1時,為內邊框,其中(x、y)為起點,w、h分別為寬度和高。
<BR>//************************************************************
<BR>//畫小程序的邊框 <BR>public void drawborder(Graphics g,int width,int
height,int s) <BR>{
<BR> Bar(g,0,0,width-1,height-1,0);
<BR> Bar(g,s,s,width-(2*s+1),height-(2*s+1),1);
<BR>} <BR><BR>//畫三角形 <BR>public void drawTriangle(Graphics g,Color
color,int x1,int y1,int x2,int y2,int x3,int y3) <BR>{ </P>
<BLOCKQUOTE>
<P>Polygon filledPolygon=new Polygon();
<BR>filledPolygon.addPoint(x1,y1);
<BR>filledPolygon.addPoint(x2,y2);
<BR>filledPolygon.addPoint(x3,y3); <BR>g.setColor(color);
<BR>g.drawPolygon(filledPolygon); </P></BLOCKQUOTE>
<P>} </P>
<P>//畫三角形1 <BR>public void drawTriangle(Graphics g,Color
color,Point p1,Point p2,Point p3) <BR>{ </P>
<BLOCKQUOTE>
<P>Polygon filledPolygon=new Polygon();
<BR>filledPolygon.addPoint(p1.x,p1.y);
<BR>filledPolygon.addPoint(p2.x,p2.y);
<BR>filledPolygon.addPoint(p3.x,p3.y); <BR>g.setColor(color);
<BR>g.drawPolygon(filledPolygon);</P></BLOCKQUOTE>
<P>} <BR><BR>//填充三角形 <BR>public void fillTriangle(Graphics g,Color
color,int x1,int y1,int x2,int y2,int x3,int y3) <BR>{ </P>
<BLOCKQUOTE>
<P>Polygon filledPolygon=new Polygon();
<BR>filledPolygon.addPoint(x1,y1);
<BR>filledPolygon.addPoint(x2,y2);
<BR>filledPolygon.addPoint(x3,y3); <BR>g.setColor(color);
<BR>g.fillPolygon(filledPolygon); </P></BLOCKQUOTE>
<P>} <BR><BR>//填充三角形1 <BR>public void fillTriangle(Graphics
g,Color color,Point p1,Point p2,Point p3) <BR>{ </P>
<BLOCKQUOTE>
<P>Polygon filledPolygon=new Polygon();
<BR>filledPolygon.addPoint(p1.x,p1.y);
<BR>filledPolygon.addPoint(p2.x,p2.y);
<BR>filledPolygon.addPoint(p3.x,p3.y); <BR>g.setColor(color);
<BR>g.fillPolygon(filledPolygon); </P></BLOCKQUOTE>
<P>} <BR><BR>//畫四邊形 <BR>public void drawQuadrangle(Graphics
g,Color color,int x1,int y1,int length1,int length2, <BR>double
angle) <BR>{ </P>
<BLOCKQUOTE>
<P>angle=-angle; <BR>int x2,y2,x3,y3,x4,y4; <BR>Polygon
filledPolygon=new Polygon(); <BR>filledPolygon.addPoint(x1,y1);
<BR>x2=(int)(x1+length2*Math.cos(angle));
<BR>y2=(int)(y1-length2*Math.sin(angle));
<BR>filledPolygon.addPoint(x2,y2);
<BR>x3=(int)(x2-length1*Math.sin(angle));
<BR>y3=(int)(y2-length1*Math.cos(angle));
<BR>filledPolygon.addPoint(x3,y3);
<BR>x4=(int)(x1-length1*Math.sin(angle));
<BR>y4=(int)(y1-length1*Math.cos(angle));
<BR>filledPolygon.addPoint(x4,y4); <BR>g.setColor(color);
<BR>g.drawPolygon(filledPolygon); </P></BLOCKQUOTE>
<P>} <BR><BR>//填充四邊形 <BR>public void fillQuadrangle(Graphics
g,Color color,int x1,int y1,int length1,int length2, <BR>double
angle) <BR>{ </P>
<BLOCKQUOTE>
<P>angle=-angle; <BR>int x2,y2,x3,y3,x4,y4; <BR>Polygon
filledPolygon=new Polygon(); <BR>filledPolygon.addPoint(x1,y1);
<BR>x2=(int)(x1+length2*Math.cos(angle));
<BR>y2=(int)(y1-length2*Math.sin(angle));
<BR>filledPolygon.addPoint(x2,y2);
<BR>x3=(int)(x2-length1*Math.sin(angle));
<BR>y3=(int)(y2-length1*Math.cos(angle));
<BR>filledPolygon.addPoint(x3,y3);
<BR>x4=(int)(x1-length1*Math.sin(angle));
<BR>y4=(int)(y1-length1*Math.cos(angle));
<BR>filledPolygon.addPoint(x4,y4); <BR>g.setColor(color);
<BR>g.fillPolygon(filledPolygon); </P></BLOCKQUOTE>
<P>} <BR><BR>//填充四邊形1 <BR>public void fillQuadrangle(Graphics
g,Color color1,Color color2,int x1,int y1,int length1,int
length2,double angle) <BR>{ </P>
<BLOCKQUOTE>
<P>Color oldcolor=g.getColor(); <BR>angle=-angle; <BR>int
x2,y2,x3,y3,x4,y4; <BR>Polygon filledPolygon=new Polygon();
<BR>filledPolygon.addPoint(x1,y1);
<BR>x2=(int)(x1+length2*Math.cos(angle));
<BR>y2=(int)(y1-length2*Math.sin(angle));
<BR>filledPolygon.addPoint(x2,y2);
<BR>x3=(int)(x2-length1*Math.sin(angle));
<BR>y3=(int)(y2-length1*Math.cos(angle));
<BR>filledPolygon.addPoint(x3,y3);
<BR>x4=(int)(x1-length1*Math.sin(angle));
<BR>y4=(int)(y1-length1*Math.cos(angle));
<BR>filledPolygon.addPoint(x4,y4); <BR>g.setColor(color1);
<BR>g.fillPolygon(filledPolygon); <BR>g.setColor(color2);
<BR>g.drawPolygon(filledPolygon); <BR>g.setColor(oldcolor);
</P></BLOCKQUOTE>
<P>} </P></BLOCKQUOTE>
<P>} </P><BR></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR>
<TABLE cellSpacing=0 cellPadding=0 width="100%" bgColor=#000000 border=0>
<TBODY>
<TR>
<TD>
<TABLE cellSpacing=0 cellPadding=0 width=150 border=0>
<TBODY>
<TR>
<TD align=middle width=49><A class=a1
href="http://www.ibm.com/privacy/"><FONT
color=#ffffff>隱私</FONT></A></TD>
<TD width=1 bgColor=#959595><IMG height=21
src="C:\Documents and Settings\zonglei\桌面\book電子稿\java代碼\java\java繪圖功能的擴展\developerWorks java.files\c(5).gif"
width=1></TD>
<TD align=middle width=49><A class=a1
href="http://www.ibm.com/legal/"><FONT
color=#ffffff>法律</FONT></A></TD>
<TD width=1 bgColor=#959595><IMG height=1
src="C:\Documents and Settings\zonglei\桌面\book電子稿\java代碼\java\java繪圖功能的擴展\developerWorks java.files\c(5).gif"
width=1></TD>
<TD align=middle width=49><A class=a1
href="http://www.ibm.com/contact"><FONT
color=#ffffff>聯系</FONT></A></TD>
<TD width=1 bgColor=#959595><IMG height=1
src="C:\Documents and Settings\zonglei\桌面\book電子稿\java代碼\java\java繪圖功能的擴展\developerWorks java.files\c(5).gif"
width=1></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></BODY></HTML>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -