c15建立窗口和菜单.pptVIP

  • 4
  • 0
  • 约 23页
  • 2016-11-27 发布于河南
  • 举报
c15建立窗口和菜单

建立窗口和菜单 第十五章 回顾 异常的定义 异常的分类 try、catch 和 finally 语句的用法 throw、throws子句的用法 如何定义自己的异常 Java异常机制的优点 目标 Component 类常用方法 建立窗口和菜单 Component 类常用方法 Component 类是所有组件的父类,其方法为所有组件公共功能的体现。所有组件都继承这些方法。因此,掌握Component 类常用方法是很“值得”的。 常用方法 组件颜色设置 组件字体设置 组件大小与位置 组件激活与可见性 组件上的光标 paint方法与repaint方法 组件颜色设置 颜色 Color 类 Color(int?r, int?g, int?b) // r,g,b---[0,255] 定义了常用颜色:BLACK 、BLUE 、CYAN等 组件颜色设置 public void setBackground(Color?c) public Color getBackground() public void setForeground(Color?c) public Color getForeground() 组件字体设置 字体 Font 类 public Font(String?name, int?style, int?size) 常见样式定义:BOLD、ITALIC 等 获取计算机上可用字体 GraphicsEnvironment en = GraphicsEnvironment. getLocalGraphicsEnvironment(); String[] fontNames = en.getAvailableFontFamilyNames() ; 组件字体设置 public void setFont(Font?f) public Font getFont() 组件大小与位置 2-1 常用方法 public void setSize(int?width, int?height) public Dimension getSize() public void setLocation(int?x, int?y) public Point getLocation () public void setBounds(int?x, int?y, int?width, int?height) public Rectangle getBounds() 组件大小与位置 2-2 相关类 Point public Point(int?x, int?y) public double getX() public double getY() Rectangle public Rectangle(int?x, int?y, int?width, int?height) public double getX() public double getY() public double getWidth() public double getHeight() public boolean contains(int?x, int?y) public boolean contains(Rectangle?r) public boolean intersects(Rectangle?r) public Rectangle union(Rectangle?r) 组件激活与可见性 激活 public void setEnabled(boolean?b) public boolean isEnabled() 可见性 public void setVisible(boolean?b) public boolean isVisible() 组件上的光标 设置光标 public void setCursor(Cursor?cursor) public Cursor getCursor() 光标 Cursor public Cursor(int?type) public static Cursor getPredefinedCursor(int?type) 常见光标类型定义:CROSSHAIR_CURSOR、HAND_CURSOR 等等 paint方法与repaint方法 public void paint(Graphics?g) 可以在子类中重写 程序需要显示外观时自动调用 public void repaint() 先调用 public void update(Graphics?g) 清除以前画的内容 再调用paint(Graphics?g)方法重画 建立窗口和菜单 Java 窗口 窗口与屏幕 菜单条、菜单、菜单项 打印 使

文档评论(0)

1亿VIP精品文档

相关文档