07ChapterJava基础课件第七篇.ppt

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
7.5.1颜色与字体 Color类 16种常用颜色:Color.RED, Color.GREEN, Color.BLUE 自定义颜色:new Color(int red, int green, int blue) 设置颜色 Component类的setBackground()和setForeground()方法 Graphics类的setColor()方法 7.5.1颜色与字体 Font类 new Font(String name, int style, int size) 设置字体 Component类的setFont()方法 Graphics类的setFont()方法 7.5.2绘图类 Graphics类 setColor(Color c) setFont(Font f) drawString(String s, int x, int y) drawLine(int x1, int y1, int x2, int y2) drawRect(int x, int y, int width, int height) drawOval(int x, int y, int width, int height) 7.5.2绘图类 Graphics类 fillRect(int x, int y, int width, int height) fillOval(int x, int y, int width, int height) 7.5.2绘图类 Graphics2D类 draw(Shape s) setStroke(Stroke s) BasicStroke(float w) 7.5.2绘图类 Shape接口的实现类 Line2D.Double(double x1, double y1, double x2, double y2) Rectangle2D.Double(double x1, double y1, double width, double height) Ellipse2D.Double(double x1, double y1, double width, double height) 绘图类对象的获取 重写JComponent类的paintComponent()方法 public void paintComponent(Graphics g) Graphics2D g2 = (Graphics2D)g; 界面刷新 JComponent类的repaint()方法 绘图应用示例 例题7-12:编写一个程序。在窗口四角绘制4个50×50的蓝色矩形,在窗口正中绘制1个100×50的红色椭圆形。4个矩形之间用橙色粗实线连接。如下图所示: 本章小结 本章首先介绍Java图形应用程序的事件处理机制;然后详细介绍常用Swing组件类的使用方法和用户界面布局设计;最后介绍了Java的常用绘图方法。 JList类的主要事件 ListSelectionEvent 单击选项时触发 ListSelectionListener valueChanged(ListSelectionEvent e) e.getSource() addListSelectionListener(ListSelectionListener e) JComboBox类的主要成员 构造方法 JComboBox () JComboBox (Object[] items) 常用方法 getSelectedIndex() getSelectedItem() getItemCount() setEditable(boolean b) JComboBox类的主要事件 ActionEvent 用户输入新选项后按回车键时触发 ActionListener actionPerformed(ActionEvent e) e.getSource() addActionListener(ActionListener e) JComboBox类的主要事件 ItemEvent 用户选中某个选项时触发 ItemListener itemStateChanged(ItemEvent e) e.getSource() addItemListener(ItemListener e) JList和JComboBox应用示例 例题7-4:设计如下图所示界面。左侧列表框允许多项选择运动项目,右侧组合框允许从列表中选择教师或自行输入教师姓名。选择的结果显示下方的文本框中。 7.3.5 滚动条 滚动条(JScrollBar)通过移动滑块可以在一个范围内选值。 JScrollBar类的主要成员 构造方法 JScrollBar (int dir, int init, int width, int l

文档评论(0)

wx171113 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档