您好,欢迎光临本网站![请登录][注册会员]  
文件名称: ch03g-graphics.pdf
  所属分类: Java
  开发工具:
  文件大小: 342kb
  下载次数: 0
  上传时间: 2019-09-14
  提 供 者: yhe***
 详细说明:java 基础入门,总共18章节,联系上传。帮助大家学习。Drawingpanel Canvas"objects that represents windows drawing surfaces To create a window DrawingPanel name new DrawingPanel (width, height); Example DrawingPanel panel= new DrawingPanel(300, 200)i Drawing Panel File Help The window has nothing on it We draw shapes/ lines on it with another object of type Graphics Graphics Pen"or "paint brush"objects to draw ines and shapes Access it by calling getGraphics on your Drawing Panel. Graphics g= panel. getGraphics()i Draw shapes by calling methods on the Graphics object Drawing Panel File Help g.fi11Rect(10,30,60,35) g.fi11Ova1(80,40,50,70) Java class libraries, import Java class libraries: classes included with java's jDK organized into groups named packages To use a package put an import declaration in your program // put this at the very top of your program import packageName. x Graphics belongs to a package named java. awt import java.awt.大; To use Graphics, you must place the above line at the very top of your program, before the public class header. Coordinate system Each(x, y) position is a pixe/( picture element") Position(0, 0)is at the window's top-left corner. X increases rightward and the y increases downward The rectangle from( 0, o)to(200, 100)looks like this (0,0) X+ (200,100) y+ Graphics methods Method name Description g draWLine(x1, y1 x2, y2) line between points(X1, y1,(x2 y2 g drawOval(X, y, width, height); outline largest oval that fits in a box of size width* height with top-left at(x,n g drawRect(x, y, width, height) outline of rectangle of size width height with top-left at(x,n g drawstring(text x, y) text with bottom-left at(x) g filloval(X, y, width, height); fill largest oval that fits in a box of size width x height with top-left at(x n g fillRect(X, y, width, height); fill rectangle of size width* height with top left at(x n g setcolor( Color); set Graphics to paint any following shapes in the given color Color Specified as predefined color class constants Color, consTANt name Where constant name is one of BLACK, Bluer CYAN, DARK GRAY GRAYI GREEN,L工G班 T GRAY MAGENTA ORANGE P工 NK, RED WHITE YELLOW Or create one using Red-Green-Blue(rGB) values of 0-255 Color name= new Color(red, green, blue) Example: Color brown new color(192 12864) Using colors Pass a color to graphics object's setcolor method Subsequent shapes will be drawn in the new color 当 Drawing Panel g. setcolor(color. BLACK) File Help g.fi11Rect(10,30,100,50) g. drawline(20,0,10,30); g setColor (color. RED)i g.fi11ova1(60,40,40,70) Pass a color to Drawing panel's setBackground method Drawing Panel The overall window background color will change File Help Color brown new color(192 128 64)i panel setBackground (brown) Outlined shapes To draw a colored shape with an outline first fillit then draw the same shape in the outline color. import java. awt.*;// so I can use Graphics public class outlineExample i public static void main(string[ args) DrawingPanel panel new DrawingPanel(150,70)i Graphics g= pane. getGraphics ( // inner red fill g. setColor(Color. RED) g.111Rect(20,10,100,50); 当 Drawing Pa._回x Hle Help // black outline g setcolor(color. BlACK)i g drawRect(20,10,100,50) 10
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索: ch03g-graphics.pdf
 输入关键字,在本站1000多万海量源码库中尽情搜索: