向窗体中加入面板 将一个Pnel对象加入到窗体中,在其上绘 实例: Othello world java 量 OthE11oor1d 回囟 Not a Hello, World program 2021/2/24 北京理工大学计算机系(共48页)
2021/2/24 北京理工大学计算机系(共48页) 6 向窗体中加入面板 ◼ 将一个JPanel对象加入到窗体中,在其上绘 图 ◼ 实例:NotHelloWorld.java
Java4标系统 (0,0) Xaxis Y axis 2021/2/24 北京理工大学计算机系(共48页) 7
2021/2/24 北京理工大学计算机系(共48页) 7 Java坐标系统
图形上下文与图形对象 Graphics context(图形上下文) 用于在屏幕上绘图 Graphics对象管理图形上下文 Graphics类是一个抽象基类,必须派生出具 体子类以实现绘图功能。 类 Component有一个 paint方法,采用一个 Graphics对象作为参数 public void paint( Graphics g 通过调用类 Component的 repaint方法来调用 paInt 2021/2/24 北京理工大学计算机系(共48页)
2021/2/24 北京理工大学计算机系(共48页) 8 图形上下文与图形对象 ◼ Graphics context(图形上下文) ◼ 用于在屏幕上绘图 ◼ Graphics对象管理图形上下文 ◼ Graphics类是一个抽象基类,必须派生出具 体子类以实现绘图功能。 ◼ 类Component 有一个 paint方法,采用一个 Graphics 对象作为参数 public void paint( Graphics g ) ◼ 通过调用类Component的repaint方法来调用 paint
颜色控制 类co1or用于处理颜色 三原色原理: R-Red:0~255 G-Green: 0-255 B-Blue: 0-255 2021/2/24 北京理工大学计算机系(共48页)
2021/2/24 北京理工大学计算机系(共48页) 9 颜色控制 ◼ 类 Color用于处理颜色 ◼ 三原色原理: R-Red: 0~255 G-Green: 0~255 B-Blue: 0~255
颜色常数 Color constant Color RGBvalue public final static Color orange orange 2552000 public final static color pink nk 255.175.175 public final static Color cyan cyan 0.255.255 public final static color magenta magenta public final static color yellow rello 255,255,0 public final static Color black black 0,0,0 public final static Color white white 255,255,255 public final static color gray 128.128.128 public final static Color lightGray light gray 192.192.192 public final static Color darkGray dark gray64,64,64 public final static Color red re 255,0,0 public final static color green green public final static color blue blue 0,0,255 Fig.11.3 Color class static constants and RGB values 2021/2/24 北京理工大学计算机系(共48页) 10
2021/2/24 北京理工大学计算机系(共48页) 10 颜色常数 Color Constant Color RGB value public final static Color orange orange 255, 200, 0 public final static Color pink pink 255, 175, 175 public final static Color cyan cyan 0, 255, 255 public final static Color magenta magenta 255, 0, 255 public final static Color yellow yellow 255, 255, 0 public final static Color black black 0, 0, 0 public final static Color white white 255, 255, 255 public final static Color gray gray 128, 128, 128 public final static Color lightGray light gray 192, 192, 192 public final static Color darkGray dark gray 64, 64, 64 public final static Color red red 255, 0, 0 public final static Color green green 0, 255, 0 public final static Color blue blue 0, 0, 255 Fig. 11.3 Color c lass static c onstants and RGB values