Results 1 to 7 of 7
- 12-21-2009, 10:40 AM #1
Member
- Join Date
- Nov 2009
- Posts
- 26
- Rep Power
- 0
problem with argument list and precedence "(" and ")"
I'm writing a program, and my compiler is acting up...
lines of code with errors...
Java Code:public class MyDownTempoListener implements ActionListener { public void actionPerformed(ActionEvent a); float tempoFactor = sequencer.getTempoFactor(); sequencer.setTempoFactor((float)(tempoFactor* .97)); // were error is at } } public void makeTracks(int[] list) { for(int i = 0; i < 16; i++) { int key = list[i]; if (key != 0) { track.add(makeEvent(144,9,key,100,i)); track.add(makeEvent(128,9,key,100,i+1)); } } } public MidiEvent makeEvent(int comd, int chan, int one, int two, int tick) { MidiEvent event = null; try{ ShortMessage a = new ShortMessage(); a.setMessage(comd,chan, one, two); event = new MidiEvent(a, tick); } catch(Exception e) {e.printStackTrace();} return event; }// were another error is at }
BeatBox.java:172: <identifier> expected
sequencer.setTempoFactor((float)(tempoFactor* .97));
^
BeatBox.java:172: illegal start of type
sequencer.setTempoFactor((float)(tempoFactor* .97));
^
BeatBox.java:172: ')' expected
sequencer.setTempoFactor((float)(tempoFactor* .97));
^
BeatBox.java:172: ';' expected
sequencer.setTempoFactor((float)(tempoFactor* .97));
^
BeatBox.java:172: illegal start of type
sequencer.setTempoFactor((float)(tempoFactor* .97));
^
BeatBox.java:172: ';' expected
sequencer.setTempoFactor((float)(tempoFactor* .97));
^
BeatBox.java:176: class, interface, or enum expected
public void makeTracks(int[] list)
^
BeatBox.java:178: class, interface, or enum expected
for(int i = 0; i < 16; i++)
^
BeatBox.java:178: class, interface, or enum expected
for(int i = 0; i < 16; i++)
^
BeatBox.java:181: class, interface, or enum expected
if (key != 0)
^
BeatBox.java:184: class, interface, or enum expected
track.add(makeEvent(128,9,key,100,i+1));
^
BeatBox.java:185: class, interface, or enum expected
}
^
BeatBox.java:189: class, interface, or enum expected
public MidiEvent makeEvent(int comd, int chan, int one, int two, int tick)
^
BeatBox.java:192: class, interface, or enum expected
try{
^
BeatBox.java:194: class, interface, or enum expected
a.setMessage(comd,chan, one, two);
^
BeatBox.java:195: class, interface, or enum expected
event = new MidiEvent(a, tick);
^
BeatBox.java:196: class, interface, or enum expected
} catch(Exception e)
^
BeatBox.java:197: class, interface, or enum expected
{e.printStackTrace();}
^
BeatBox.java:199: class, interface, or enum expected
}
^
19 errors
whole code
Java Code:import java.awt.*; import javax.swing.*; import javax.sound.midi.*; import java.until.*; import java.awt.event.*; //import files public class BeatBox {//class beatbox made JPanel mainPanel; //instance of mainPanel is made ArrayList<JCheckBox> checkboxList;//array list of type JCheckBox is created called checkboxList Sequencer sequencer;// make sequencer called ./ Sequence sequence;//make sequence called <- Track track;//makes track called <- JFrame theFrame;// makes JFrame called <- String[] instrumentNames = {"Bass Drum", "Closed Hi-Hat", "Open Hi-Hat", "Acoustic Snare", "Crash Cymbal", "Hand Clap", "High Tom", "Hi Bongo", "Maracas", "Whistle", "Low Conga", "Cowbell", "Vibraslap", "Low-mid Tom", "High Agogo", "Open Hi Conga"}; //instrument names in array called instrumentNames of string type int[] instruments = {35,42, 46, 38, 49, 39, 50, 60, 70, 72, 64, 56, 58, 47, 67, 63}; //make //instuments in array that shows numbers that equal the change of instrument public static void main (String[] args) //start of main function.. { BeatBox j = new BeatBox(); j.buildGUI();//creates beatbox2 and calls buildgui } public void buildGUI()//build gui defined { theFrame = new JFrame("Cyber BeatBox"); //theFrame directs itself to a JFrame object theFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //tells the frame to close when pressed exit BorderLayout layout = new BorderLayout();//createst layout that is directed to BorderLayout object JPanel background = new JPanel(layout); //new jpanel that is is directed from background background.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); //sets background border calling borderfactory class with createEmptyBorder emthod //which creates an empty border parameters is how big width is top/left/bottom/right in pixels checkboxList = new ArrayList<JCheckBox>(); //defines checkboxList connects to ArrayList object of type JCheckBox Box buttonBox = new Box(BoxLayout.Y_AXIS); //creates buttonBox points to new Box with y_axis (vertical) JButton start = new JButton("Start"); //creates JButton start.addActionListener(new MyStartListener()); //adds a listener to jbutton named start buttonBox.add(start);//buttonbox adds the start JButton JButton stop = new JButton("Stop");//makes new JButton called stop refering to a JButton stop.addActionListener(new MyStopListener());//stop is listened to with this line buttonBox.add(stop);//add jbutton to buttonBox JButton upTempo = new JButton("Tempo Up");//new jbutton for tempo speeding up upTempo.addActionListener(new MyUpTempoListener());//add listener to it... buttonBox.add(upTempo);//add it to box layout JButton downTempo = new JButton ("Tempo Down");//new jbutton for tempo speeding down downTempo.addActionListener(new MyDownTempoListener());//downtempo jbutton gets listener assigned to it buttonBox.add(downTempo);//add the button to boxlayout Box nameBox = new Box(BoxLayout.Y_AXIS);//creates new box for using box layout manager for(int i = 0; i < 16; i++) //for loop for looping { nameBox.add(new Label(instrumentNames[i]));// adds a new label to the box name box for the instrument names } background.add(BorderLayout.EAST, buttonBox);//adds the buttonbox to the east side of jpanel(layout)'s background background.add(BorderLayout.WEST, nameBox);//adds the namebox(instruments) to the west side of the background of jpanel. theFrame.getContentPane().add(background);//add the background which has all the buttons to the jframe GridLayout grid = new GridLayout(16,16);//creates a grid 16x16 grid.setVgap(1);//creates vgap grid.setHgap(2);//creates hgap mainPanel = new JPanel(grid);//mainPanel is a new Jpanel background.add(BorderLayout.CENTER, mainPanel); //add mainPanel to background in the center for(int i=0; i<256; i++) //loop counter { JCheckBox c = new JCheckBox();//creates a new jcheckbox c.setSelected(false);//sets them to false(unchecked) checkboxList.add(c);//add the jcheckbox(c) mainPanel.add(c);//add the jcheckbox to mainPanel } setUpMidi();//calls the setUpMidi method theFrame.setBounds(50,50,300,300);//theFrame sets bounds theFrame.pack();//makes everything fit... theFrame.setVisible(true);//makes visible } public void setUpMidi()//setUpMidi { try{//try statement sequencer = MidiSystem.getSequencer();//creates sequencer to play the music sequencer.open();//opens the sequencer with .open() method sequence = new Sequence(Sequence.PPQ,4);//creates sequence called sequence with argument track = sequence.createTrack(); //.creates track from sequence made.... sequencer.setTempoInBPM(120);//sets tempo for sequencer }catch(Exception e) {e.printStackTrace();} } public void buildTrackAndStart()//creates a new mthod called buildTrackAndStart { int[] trackList = null;//creates an array that is set up at null sequence.deleteTrack(track);//sequence deletes current track so it can add new one track = sequence.createTrack();// creates new track for the sequence for(int i = 0; i < 16; i++) //creates a loop { trackList = new int[16];// defines the array track list int key = instruments[i];//sets the key/instrument for (int j = 0; J < 16;j++)//nested loop { JCheckBox jc = (JCheckBox) checkboxlist.get(j + (16*i));//create a jcheckbox if (jc.isSelected())//if jc is selected(checked) { trackList[j] = key;//trackList[j] = the key } else { trackList[j] = 0;//set the instrument to zero } } makeTracks(trackList); //makeTracks gets trackList in its argument track.add(makeEvent(176,1,127,0,16));//make the beat } track.add(makeEvent(192,9,1,0,15)); //make an event for 16th one to make sure it loops try {//try statement sequencer.setSequence(sequence);// make sequencer sequencer.setLoopCount(sequencer.LOOP_CONTINUOUSLY);// set loop count to continuously sequencer.start();// starts the sequencer sequencer.setTempoInBPM(120);//sets the tempo } catch(Exception e) {e.printStackTrace();}//catches exceptions from the try block } public class MyStartListener implements ActionLIstener { // makes inner class for listening to events public void actionPerformed(ActionEvent a) //method for catching an event on the listener { buildTrackAndStart();//build trackandStart method called } } public class MyStopListener implements ActionListener { public void actionPerformed(ActionEvent a) { sequencer.stop(); //stops the sequencer when this listener gets an event } } public class MyUpTempoListener implements ActionLIstener { public void actionPerformed(ActionEvent a) { float tempoFactor = sequencer.getTempoFactor(); sequencer.setTempoFactor((float)(tempoFactor* 1.03)); }//increases the tempo } public class MyDownTempoListener implements ActionListener { public void actionPerformed(ActionEvent a); float tempoFactor = sequencer.getTempoFactor(); sequencer.setTempoFactor((float)(tempoFactor * .97)); } } public void makeTracks(int[] list) { for(int i = 0; i < 16; i++) { int key = list[i]; if (key != 0) { track.add(makeEvent(144,9,key,100,i)); track.add(makeEvent(128,9,key,100,i+1)); } } } public MidiEvent makeEvent(int comd, int chan, int one, int two, int tick) { MidiEvent event = null; try{ ShortMessage a = new ShortMessage(); a.setMessage(comd,chan, one, two); event = new MidiEvent(a, tick); } catch(Exception e) {e.printStackTrace();} return event; } }
-
- 12-22-2009, 12:31 AM #3
Member
- Join Date
- Nov 2009
- Posts
- 26
- Rep Power
- 0
ahhh
ok, thanks.
- 12-22-2009, 12:33 AM #4
Member
- Join Date
- Nov 2009
- Posts
- 26
- Rep Power
- 0
when it says enum, interface, or class expected, what does it mean?
-
Sometimes you'll see that if you try go make statements outside of method or constructor blocks.
- 12-22-2009, 10:15 AM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 28
Your compiler isn't acting up; you're feeding it incorrect Java code and your compiler correctly signals the errors; e.g. what is that third line supposed to mean? You can't declare methods like that, you have to make that method an abstract method then and subsequently your entire class has to be abstract. Otherwise define the body of that method.
Please study the basics of the Java syntax first before you attempt to code; otherwise you'll end up like this and incorrectly blame the compiler for it.
kind regards,
Jos
- 12-24-2009, 08:50 AM #7
Similar Threads
-
Java, Military Format using "/" and "%" Operator!!
By sk8rsam77 in forum New To JavaReplies: 11Last Post: 02-26-2010, 04:03 AM -
Runtime error "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
By shantimudigonda in forum New To JavaReplies: 1Last Post: 11-20-2009, 08:58 PM -
how to override "cancel operation" in "progress bar"
By singswt in forum SWT / JFaceReplies: 2Last Post: 10-09-2009, 12:28 AM -
MoneyOut.println("It took you (whats wrong?>",year,"<WW?) years to repay the loan")
By soc86 in forum New To JavaReplies: 2Last Post: 01-24-2009, 07:56 PM -
the dollar sign "$", prints like any other normal char in java like "a" or "*" ?
By lse123 in forum New To JavaReplies: 1Last Post: 10-20-2008, 08:35 AM
Bookmarks