| | |
Completely Lost : ( Can anyone help
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2005
Posts: 5
Reputation:
Solved Threads: 0
Hi everyone, Just thought i would post my program im doing at the moment as im completely stuck. Basically the program takes a user input as a string, uses the tokenizer to break down. The individual strings which will be single characters will be used to draw notes on a music staff using unicode. Can anyone help with this code as im really getting annoyed now. Thanks
import java.awt.*; import javax.swing.*;import java.util.StringTokenizer;
/**
* A program that uses a frame for drawing musical notes on a staff
*
* @author PAS
* @version (18/10/05)
*/
public class FrameSkeleton extends JFrame {
private int howMany; // this is a class instance variable that affects the picture that is drawn
private int notePosition;
public FrameSkeleton() {
setTitle("Musical Staff");
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
setSize(new Dimension(600,400));
this.getContentPane().setBackground(Color.black);
setVisible(true);
}
public void paint(Graphics g) {
super.paint(g);
this.drawStaff(getContentPane().getGraphics());
}
// This draws the a note using position vertical to guide placement
public void drawNote(Graphics g) {
g.setColor(Color.black);
g.setFont( new Font("MS PMincho", Font.PLAIN, 48) );
g.drawString("" + '\u2669', 75, 275-10*notePosition);
}
public void drawStaff(Graphics g) {
g.setColor(Color.white);
for (int i = 0; i < this.howMany; i++)
g.drawLine(25,125+30*i,570,125+30*i);
}
public void userInput (){
System.out.println("Enter a sequence of notes: ");
String sent = Keyboard.readString();
StringTokenizer st = new StringTokenizer(sent);
String word;
while (st.hasMoreTokens()){
word = st.nextToken();
}
}
int notePosition(){
this.userInput();
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;
for (int i=0; i<=sent.length();i++) {
if (word.equals("a")){
word = st.nextToken();
return a;
}else if (word.equals("b")){
word = st.nextToken();
return b;
}else if (word.equals("c")){
word = st.nextToken();
return c;
}else if (word.equals("d")){
word = st.nextToken();
return d;
}else if (word.equals("e")){
word = st.nextToken();
return e;
}else if (word.equals("f")){
word = st.nextToken();
return f ;
}else if (word.equals("g")){
word = st.nextToken();
return g;
}else if (word.equals("A")){
word = st.nextToken();
return A;
}else if (word.equals("B")){
word = st.nextToken();
return B;
}else if (word.equals("C")){
word = st.nextToken();
return C;
}else if (word.equals("D")){
word = st.nextToken();
return D;
}else if (word.equals("E")){
word = st.nextToken();
return E;
}else if (word.equals("F")){
word = st.nextToken();
return F;
}else if (word.equals("G")){
word = st.nextToken();
return G;
}
}
:eek:
// This refreshes the screen and draws the staff and note
public void paint(Graphics g) {
super.paint(g);
this.drawStaff(getContentPane().getGraphics());
this.drawNote(getContentPane().getGraphics());
}
/* Example update method below */
//public void setHowMany(int h) {
// this.howMany = h;
// this.repaint();
//}
public static void main(String [] args) {
FrameSkeleton myFrame = new FrameSkeleton();
myFrame.setHowMany(5);
System.out.println("Enter a sequence of notes: ");
String sent = Keyboard.readString();
FrameSkeleton input = new FrameSkeleton();
input.notePosition();
FrameSkeleton create = new FrameSkeleton();
create.drawNote();
}
}
:eek: :eek: :eek: :eek:
import java.awt.*; import javax.swing.*;import java.util.StringTokenizer;
/**
* A program that uses a frame for drawing musical notes on a staff
*
* @author PAS
* @version (18/10/05)
*/
public class FrameSkeleton extends JFrame {
private int howMany; // this is a class instance variable that affects the picture that is drawn
private int notePosition;
public FrameSkeleton() {
setTitle("Musical Staff");
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
setSize(new Dimension(600,400));
this.getContentPane().setBackground(Color.black);
setVisible(true);
}
public void paint(Graphics g) {
super.paint(g);
this.drawStaff(getContentPane().getGraphics());
}
// This draws the a note using position vertical to guide placement
public void drawNote(Graphics g) {
g.setColor(Color.black);
g.setFont( new Font("MS PMincho", Font.PLAIN, 48) );
g.drawString("" + '\u2669', 75, 275-10*notePosition);
}
public void drawStaff(Graphics g) {
g.setColor(Color.white);
for (int i = 0; i < this.howMany; i++)
g.drawLine(25,125+30*i,570,125+30*i);
}
public void userInput (){
System.out.println("Enter a sequence of notes: ");
String sent = Keyboard.readString();
StringTokenizer st = new StringTokenizer(sent);
String word;
while (st.hasMoreTokens()){
word = st.nextToken();
}
}
int notePosition(){
this.userInput();
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;
for (int i=0; i<=sent.length();i++) {
if (word.equals("a")){
word = st.nextToken();
return a;
}else if (word.equals("b")){
word = st.nextToken();
return b;
}else if (word.equals("c")){
word = st.nextToken();
return c;
}else if (word.equals("d")){
word = st.nextToken();
return d;
}else if (word.equals("e")){
word = st.nextToken();
return e;
}else if (word.equals("f")){
word = st.nextToken();
return f ;
}else if (word.equals("g")){
word = st.nextToken();
return g;
}else if (word.equals("A")){
word = st.nextToken();
return A;
}else if (word.equals("B")){
word = st.nextToken();
return B;
}else if (word.equals("C")){
word = st.nextToken();
return C;
}else if (word.equals("D")){
word = st.nextToken();
return D;
}else if (word.equals("E")){
word = st.nextToken();
return E;
}else if (word.equals("F")){
word = st.nextToken();
return F;
}else if (word.equals("G")){
word = st.nextToken();
return G;
}
}
:eek:
// This refreshes the screen and draws the staff and note
public void paint(Graphics g) {
super.paint(g);
this.drawStaff(getContentPane().getGraphics());
this.drawNote(getContentPane().getGraphics());
}
/* Example update method below */
//public void setHowMany(int h) {
// this.howMany = h;
// this.repaint();
//}
public static void main(String [] args) {
FrameSkeleton myFrame = new FrameSkeleton();
myFrame.setHowMany(5);
System.out.println("Enter a sequence of notes: ");
String sent = Keyboard.readString();
FrameSkeleton input = new FrameSkeleton();
input.notePosition();
FrameSkeleton create = new FrameSkeleton();
create.drawNote();
}
}
:eek: :eek: :eek: :eek:
•
•
Join Date: May 2005
Posts: 55
Reputation:
Solved Threads: 1
OllieFalle,
Here are a few things that seem incorrect to me (correct me if I am wrong):
1. Your method called userInput shown below has problems
Notice that it reads through the tokens and stores each in the variable word. Therefore, at the end, word holds the last token. All the other tokens were discarded.
What you should do is tokenize and store the results in an ArrayList.
2. Your drawNote method always draws the same character at the same x position. Is this what you want?
3. Your notePosition method seems to have a compile error. I don't see a StringTokenizer declared in that method or a instance variable. The only place it is created is in the userInput method but you can't access it from the notePosition method.
What do you want this method to do?
For more help, removed link to homework pay site
Here are a few things that seem incorrect to me (correct me if I am wrong):
1. Your method called userInput shown below has problems
Java Syntax (Toggle Plain Text)
public void userInput () { System.out.println("Enter a sequence of notes: "); String sent = Keyboard.readString(); StringTokenizer st = new StringTokenizer(sent); String word; while (st.hasMoreTokens()) { word = st.nextToken(); } }
What you should do is tokenize and store the results in an ArrayList.
2. Your drawNote method always draws the same character at the same x position. Is this what you want?
Java Syntax (Toggle Plain Text)
public void drawNote(Graphics g) { g.setColor(Color.black); g.setFont( new Font("MS PMincho", Font.PLAIN, 48) ); g.drawString("" + '\u2669', 75, 275-10*notePosition); }
What do you want this method to do?
For more help, removed link to homework pay site Last edited by alc6379; Jan 13th, 2006 at 12:03 am.
![]() |
Similar Threads
- Help!!!So lost (C++)
- Lost MSN Explorer (Windows Software)
- Completely confused (C)
- vBulletin technical assistance (Existing Scripts)
- Red Hat 9 on VMWare 4 (*nix Software)
- Windows rubicks cube - BSOD (Windows NT / 2000 / XP)
- I'm clicking and IE won't open but I can open it via windows explorer (Web Browsers)
- ALICE Sucks (DaniWeb Community Feedback)
Other Threads in the Java Forum
- Previous Thread: quick question
- Next Thread: String... max_length and println
| Thread Tools | Search this Thread |
-xlint add android api applet application array arrays automation bi binary blackberry bluetooth chat class classes client code compile compiler component converter database digit draw eclipse equation error event exception fractal freeze functiontesting game gameprogramming givemetehcodez graphics gui health html hyper ide idea image input int integer j2me java javame javaprojects jetbrains jni jpanel jtable julia learningresources linux list login loop main map method methods mobile myregfun netbeans newbie nonstatic notdisplaying oracle page pearl print problem program programming project qt recursion scanner screen server set size sms sort spamblocker sql string swing system thread threads time tree variablebinding windows xor





