Weekly Update - 3-5-10

0 views
Skip to first unread message

Jason Pawlak

unread,
Mar 2, 2010, 8:36:29 PM3/2/10
to Smart Player Piano
Updates for this week

Due: 3/3/2010 Design Report and Notebook (YIKES!)

Jason Pawlak

unread,
Mar 2, 2010, 8:48:24 PM3/2/10
to Smart Player Piano
Here are some code snippets that are important that I might talk about
in my design report:

Setting up display using SWT
private void setUpDisplay() {
display = new Display();
shell = new Shell(display);
shell.setSize(460, 140);
shell.setText("Smart Player Piano");
}

Updating timer bar (another SWT example)
// Increment timing bar
int percentSongComplete = (int)(100*((float)pos/(float)(los)));
timeBar.setSelection(percentSongComplete);

Interesting part of SWT is that the menu bar is OS specific. On
Windows, the menu is on the application window, but on Mac, the menu
bar is on the top of the screen
private void createMenuBar() {
Menu menu = new Menu(shell, SWT.BAR);
shell.setMenuBar(menu);

MenuItem fileMenuItem = new MenuItem(menu, SWT.CASCADE);
fileMenuItem.setText("File");
Menu subFileMenuItem = new Menu(shell, SWT.DROP_DOWN);
fileMenuItem.setMenu(subFileMenuItem);
MenuItem openFileMenuItem = new MenuItem(subFileMenuItem,
SWT.PUSH);
openFileMenuItem.setText("&Open");
openFileMenuItem.setAccelerator(SWT.COMMAND + 'O');
openFileMenuItem.addListener (SWT.Selection, new Listener () {
public void handleEvent (Event e) {
openFile();
}
});
MenuItem exitFileMenuItem = new MenuItem(subFileMenuItem,
SWT.PUSH);
exitFileMenuItem.setText("E&xit");
exitFileMenuItem.setAccelerator(SWT.COMMAND + 'Q');
exitFileMenuItem.addListener (SWT.Selection, new Listener() {
public void handleEvent (Event e) {
System.exit(0);
}
});

MenuItem helpMenuItem = new MenuItem(menu, SWT.CASCADE);
helpMenuItem.setText("Help");
}

A few quick functions that demonstrate the ease of use that a MIDI
file has in Java
private void stopMIDI() {
activeSequencer.stop();
activeSequencer.setMicrosecondPosition(0);
}

private void pauseMIDI() {
activeSequencer.stop();
}

private void playMIDI() {
activeSequencer.start();

Reply all
Reply to author
Forward
0 new messages