网站大量收购独家精品文档,联系QQ:2885784924

云南大学软件学院JAVA实验九.doc

  1. 1、本文档共13页,可阅读全部内容。
  2. 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
云南大学软件学院JAVA实验九

云南大学软件学院 实 验 报 告 班级:实验目的:Program 1 Create an application ChangeBallColor that displays a panel. ?This panel will contain two buttons (one for red and one for blue). ?It will also display a filled in circle. ?When the user clicks on a button, the circle should change to that color. ?So, if a user clicks the blue button, the circle will change to blue. ?Similarly, if a user clicks the red button, the circle will turn to red. Program 2 Create an application AddCircles that displays a panel. ?This panel will contain two buttons (one for red and one for blue). ?When the user clicks on a button, change a variable called currentColor to that particular color. Now when the user clicks on a space in the panel (outside a button), draw a circle with the current color. ?Have your application just add new circles when the user clicks the mouse. ?Do not erase previous circles. 实验内容: Program 1: Balls.java代码部分 package Lab9; class Balls { //定义圆的颜色type,1表示蓝色,2表示红色 int color=0; //定义圆的位置 int locate=50; public int getColor() { return color; } public void setColor(int color) { this.color = color; } public int getLocate() { return locate; } public void setLocate(int locate) { this.locate = locate; } //构造函数 public Balls(int color, int locate) { this.color=color; this.locate=locate; } } ChangeBallColor.java代码部分 package Lab9; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class ChangeBallColor extends JFrame { //定义组件 JPanel jp; JButton jb1,jb2; Panel mp=null; public static void main(String[] args) { // TODO Auto-generated method stub ChangeBallColor main=new ChangeBallColor(); } //构造函数 public ChangeBallColor() { mp=new Panel(); jp=new JPanel(); jb1=new JButton(蓝色); jb2=new JButton(红色); jp.add(jb1); jp.add(jb2); //注册监听 jb1.addActionListener(mp); jb1.setActionCommand(蓝色); jb2.addActionListener(mp); jb2.setActionCommand(红色); this.add(jp,BorderLayout.NORTH); this.add(mp); this.se

文档评论(0)

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

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

版权声明书
用户编号:8130065136000003

1亿VIP精品文档

相关文档