I have changes a few things but still seem to be hitting a brick wall. I have been told that my note is drawn at the same position each time. Can anyone help with what i can do regarding this. Otherwise can anyone help with getting this thing to work. Much apreciated.

import java.util.StringTokenizer;
import java.awt.*;
import java.util.*;
import javax.swing.*;
import java.awt.Color;


/**
* Write a description of class MusicSheet here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class MusicSheet extends JFrame {
private int placement; // This indicated the postion of the notes in the y co-od.


public MusicSheet(){   //  Builds the frame with a set size and colour and gives a title.
setTitle("This is Ollie's Music Sheet");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(new Dimension(600,400));
this.getContentPane().setBackground(Color.black);
setVisible(true);
}


public void drawStaff(Graphics g) { //draws staff lines.
g.setColor(Color.white);
for (int i=0; i<5; i++)
g.drawLine(100,220+30*1,400,150+30*i);
}


public void paint(Graphics g){ // Screen refresh to draw notes and staff
super.paint(g);
this.drawStaff(getContentPane().getGraphics());
this.drawNote(getContentPane().getGraphics());
}


public void drawNote(Graphics g,int notePosition){
g.setColor(Color.white);
g.setFont(new Font("MS PMincho", Font.PLAIN, 4));
g.drawString("" + '\u2669', 75, 275-10*(this.notePosition));
}


public int notePosition(String input){ // matches user input with charcter and returns value for y co-ord of note.
int a = 30;
int b = 40;
int c = 50;
int d = 60;
int e = 70;
int f = 80;
int g = 90;
int A = 100;
int B = 110;
int C = 120;
int D = 130;
int E = 140;
int F = 150;
int G = 160;
String input;


while (st.hasMoreTokens()){
input=st.nextToken();


if (input.equals("a")) {
return a;


} else if (input.equals("b")) {
return b;


} else if (input.equals("c")) {
return c;


} else if (input.equals("d")) {
return d;


} else if (input.equals("e")) {
return e;


} else if (input.equals("f")) {
return f;


} else if (input.equals("g")) {
return g;


} else if (input.equals("A")) {
return A;


} else if (input.equals("B")) {
return B;


} else if (input.equals("C")) {
return C;


} else if (input.equals("D")) {
return D;


} else if (input.equals("E")) {
return E;


} else if (input.equals("F")) {
return F;


} else if (input.equals("G")) {
return G;
}


return (0);    // indicates a word we couldn't find
}
}



public static void main(String[] args){
MusicSheet mySheet = new MusicSheet();
System.out.println("Enter a sequence of notes: ");
String character = Keyboard.readString();
StringTokenizer st = new StringTokenizer(character);



}
}


Also here is the keyboard class im using.
/** Keyboard.java
*   Special class for simplifying reading of keyboard input
*      Provides methods for reading each of the primitive types from one line of input only
*      Also reads whole line as a String.
*
*
*
*       Additionally, this class provides a helper function replace for replacing a character
*       in a given position in a string with another.
*/


import java.io.*;
import java.lang.NumberFormatException;


public class Keyboard {


/**
*   Read a string from the keyboard
*   @return String the string entered (sans newline)
*/
public static String readString() {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 1);
String str = "";


try {
str = br.readLine();
}
catch (IOException ioe) { System.out.println(ioe); }


return str;
}


/**
*   Read a line from the keyboard an interpret it as an int value
*   @return int the int interpretation of the input string
*/
public static int readInt() { return Integer.parseInt(readString()); }


/**
*   Read a line from the keyboard an interpret it as a byte value
*   @return byte the byte interpretation of the input string
*/
public static byte readByte() { return Byte.parseByte(readString()); }


/**
*   Read a line from the keyboard an interpret it as a short value
*   @return short the short interpretation of the input string
*/
public static short readShort() { return Short.parseShort(readString()); }


/**
*   Read a line from the keyboard an interpret it as a long value
*   @return long the long interpretation of the input string
*/
public static long readLong() { return Long.parseLong(readString()); }


/**
*   Read a line from the keyboard an interpret it as a float value
*   @return float the float interpretation of the input string
*/
public static float readFloat() { return Float.parseFloat(readString()); }


/**
*   Read a line from the keyboard an interpret it as a double value
*   @return double the double interpretation of the input string
*/
public static double readDouble() { return Double.parseDouble(readString()); }


/**
*   Read a line from the keyboard an interpret it as a char value
*   @return char the char interpretation of the input string
*/
public static char readChar() { return readString().charAt(0) ; }


/**
*   Read a line from the keyboard an interpret it as a boolean value
*   @return boolean the boolean interpretation of the input string
*/
public static boolean readBoolean() { return Boolean.valueOf(readString()).booleanValue(); }


// Utitily method replace
// Nothing to do with keyboard input.  Simplifies Assignment 1


/**
*   Generates a new string by replacing the character in the given position of the string with the given character
*
*   @param  s   the string to replace the character in
*   @param  i   the position of the character to replace
*   @param  c   the new character to use
*   @return String  a new string with the character in position i of s replaced by c
*/
public static String replace(String s, int i, char c) {
return ( s.substring(0,i) + c + s.substring(i+1) );
}


/**
* Determine whether or not a given string represents an integer value
*
* @param s the string
* @return boolean is it an integer
*/
public static boolean isInteger(String s) {
try {
Integer.parseInt(s);
return true;
} catch (NumberFormatException e) { return false; }
}
}

Edited 3 Years Ago by happygeek: fixed formatting

This article has been dead for over six months. Start a new discussion instead.