开发者

Drawing A Piano

I have started working on a software synthesizer (or keyboard). I have decided to use Java because of the available Jfugue API. I am trying to figure out how to go about creating the actual keys (notes) of the keyboard user interface, but I am stuck. I have tried to create an interface by dragging/dropping black and w开发者_JAVA百科hite rectangular buttons onto the panel, but that doesn't seem to work. Could someone point me into the right direction?


Check out reply 9 of this posting for a simple piano keyboard that should get you started. You may want to read the posting from the beginning for ideas on how to handle the note represented by each button.


If you're using Java/swing, your best bet would be to draw an image of a keyboard and map click locations to the individual keyboard keys.


I once had to do something similar... the best solution I found was to draw panels and set their border and background as keys. I then used mouse listeners to determine which panel was clicked and the duration of the click.


I think this is what you want to:

  1. Create a class that extends JPanel
  2. Override the paint() method to draw the piano keys
  3. Implement MouseListener and MouseMotionListener, and know when the user has clicked the mouse over certain keys
  4. Use the StreamingPlayer in JFugue to play notes dynamically

I'm the author of JFugue, and I've also wanted to start a side-effort, JFugueUI, that would provide things like graphical keyboards that people could include in their own applications - so, let me know if you're interested in contributing!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜