NCF参数化建筑论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 15154|回复: 5
打印 上一主题 下一主题

[在线求助] button 問題(急求解答 拜託了禮拜四之前)

[复制链接]
跳转到指定楼层
1m
发表于 2011-3-8 19:58:24 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
如圖,這次我想做個GUI介面的設計。想要在窗口上設定5個按鈕,當滑標靠近時可以按鈕變色,往下按時按鈕也可以變色。 但目前我所遇到的問題是,單一個設計按鈕是沒問題的!!但我嘗試使用 class寫出其他2個按鈕時,鼠標靠近變成沒有反應,是否有站友能幫我解決這問題(這是本次設計作業,拜託了!!!!)一併附上原始檔案 幫助修改。

test_botton.pde

827 Bytes, 下载次数: 2, 下载积分: 照度 -1 lux

test_botton1.pde

1.44 KB, 下载次数: 2, 下载积分: 照度 -1 lux

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享
2m
发表于 2011-3-9 05:26:47 | 只看该作者
改这样就可以了,不知道是不是你想要的效果 botton botton1 = new botton(150,300,20,20); botton botton2 = new botton(300,300,20,20); botton botton3 = new botton(200,300,20,20); void setup() { size(400,400); smooth(); background(255); } void draw() { botton1.drawbotton(); botton1.mousePressed(); botton1.mouseReleased(); botton1.mouseMoved(); botton2.drawbotton(); botton2.mousePressed(); botton2.mouseReleased(); botton2.mouseMoved(); botton3.drawbotton(); botton3.mousePressed(); botton3.mouseReleased(); botton3.mouseMoved(); }
3m
 楼主| 发表于 2011-3-9 13:07:59 | 只看该作者
非常接近了,但是當鼠標按下按鈕時,應該也要變色,但目前也是沒反應。正在研究中...不知道是不是mousePressed,mouseMoved,mouseReleased這幾個bulit-in function的問題
4m
 楼主| 发表于 2011-3-10 02:15:29 | 只看该作者
color currentColor;//按鈕當前顏色 color buttonColor = color(50);//按鈕預設顏色 color highlight = color(255);//滑鼠移過去時的顏色(白) circlebutton button1,button2,button3,button4,button5; boolean locked = false;//預設開關一開始是關閉的 void setup(){ size(400,400); smooth(); ellipseMode(CENTER); buttonColor = color(30); button1 = new circlebutton(30, 200, 20, buttonColor, highlight); buttonColor = color(50); button2 = new circlebutton(60, 200, 20, buttonColor, highlight); buttonColor = color(60); button3 = new circlebutton(90, 200, 20, buttonColor, highlight); buttonColor = color(80); button4 = new circlebutton(120, 200, 20, buttonColor, highlight); buttonColor = color(200); button5 = new circlebutton(150, 200, 20, buttonColor, highlight); } void draw(){ background(currentColor); stroke(255); update(mouseX,mouseY);//注意update 沒有在class裡面 button1.display(); button2.display(); button3.display(); button4.display(); button5.display(); } void update(int x,int y){ if(locked == false){ button1.update(); button2.update(); button3.update(); button4.update(); button5.update(); } else{ locked = false; } if(mousePressed){ if(button1.pressed()){ currentColor = button1.buttonColor; } else if(button2.pressed()){ currentColor = button2.buttonColor; } else if(button3.pressed()){ currentColor = button3.buttonColor; } else if(button4.pressed()){ currentColor = button4.buttonColor; } else if(button5.pressed()){ currentColor = button5.buttonColor; } } } class button{ int x,y; int bsize; color buttonColor; color highlightcolor; color currentcolor; boolean over = false; boolean passed = false; //我是true時就update void update(){ if(over()){ currentcolor = highlightcolor; } else{ currentcolor = buttonColor; } } boolean pressed(){ if(over){ locked = true; return true; } else{ locked = false; return false; } } boolean over(){ return true; } boolean overCircle(int x,int y,int diameter){ float disX = x - mouseX; float disY = y - mouseY; //以disX,disY為中點畫圓r位半徑 if(sqrt(sq(disX)+sq(disY)) < diameter/2){ return true; } else{ return false; } } } class circlebutton extends button{ circlebutton(int x,int y,int bsize,color buttonColor,color highlightcolor){ this.x = x; this.y = y; this.bsize = bsize; this.buttonColor = buttonColor; this.highlightcolor = highlightcolor; } boolean over(){ if(overCircle(x,y,bsize)){ over = true; return true; } else{ over = false; return false; } } void display(){ stroke(0); fill(currentcolor); ellipse(x,y,bsize,bsize); } }
5m
 楼主| 发表于 2011-3-10 02:16:44 | 只看该作者
相信答案就在裡頭,但是目前是背景變色,我想要改成:::背景顏色固定,只有鼠標按下時,按鈕才變色。 請求站友幫忙
6m
发表于 2011-3-10 13:21:17 | 只看该作者
背景颜色固定的话把background(currentcolor)去掉嘛,否则跟着你的currentColor在变。 顺便解释一下,鼠标按下的反映叫“事件 (event)”,PApplet加载包括了鼠标和键盘等若干事件,如果想在自己的class实现事件反馈,百度一下java 里的 event。当然,如楼上利用papplet的事件调用程序也是正解

小黑屋|手机版|NCF参数化建筑论坛 ( 浙ICP备2020044100号-2 )    辽公网安备21021102000973号

GMT+8, 2024-4-26 15:27 , Processed in 0.069763 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表