Results 21 to 33 of 33
- 08-11-2012, 07:10 PM #21
Senior Member
- Join Date
- Dec 2010
- Location
- Indiana
- Posts
- 202
- Rep Power
- 3
- 08-12-2012, 10:18 PM #22
Senior Member
- Join Date
- Dec 2010
- Location
- Indiana
- Posts
- 202
- Rep Power
- 3
Re: How can I go about making propper classes for propper java coding?
Ok so I got my flash card ap working and it does a basic job right now that works for me. Now its time to design the ultimate jazz card program.
Now as far as learning enums I have an idea and question.
Lets say I want to load a chord list for a song the song Misty. The song has lots of chords and melody notes that go with those chords. I want each chord to have 3 options that can load if needed.
The first chord is EbMaj9. It has a particular voicing style and a melody note to go on top.
I want to be able to turn off melody note and voicing style with a check box or whatever.Java Code:voicing style : "4" Chord name : "EbMaj9" Melody note : "D"
currently I am using a String[]
The array allows no options (at least the way I set it up).Java Code:String[] MISTY = {"4: EbMaj9","X: Bb-7","Y: Eb13","4: AbMaj7","X: Ab-9","Y: Db7(#11)", "X: G7(b13)", "Y: C7(#9)", "O: F-7", "4: Bb7(b9)", "X: G7(b13)", "Y: C7(#9)", "4: F-9", "X: Bb13"};
So lets say I want this.
int chordNumber would just select which chord out of the total number currently added.Java Code:getRandomChord(int chordNumber, boolean voicingVisible, boolean melodyVisible)
Would I use an enum to accomplish this?
I could make it work this way, but it just seems wrong. Because the chords will be read from a Misty file that could change at any time, new chords added, in-between voicings... and so on.Java Code:enum Misty { CHORD1("Eb", "Maj9", "4", "D") CHORD2("Bb" ,"m7", "X", "Db"); private String rootNote; private String chordType; private String voicingType; private String melodyNote; }
Does this make sense? Any hints on how I should go about this? Maybe an enum is not the answer and if it is.. the name of each CHORD1 and CHORD2 could be useful but what would those names be for?Last edited by AcousticBruce; 08-12-2012 at 10:26 PM.
-
Re: How can I go about making propper classes for propper java coding?
I would use an enum for the chord as you're doing, and then create a new class, perhaps called ChordVoicing that holds a Chord variable, a melody note variable, and an inversion or voicing variable. I wouldn't worry about check boxes for this class since it will just contain the logic of ChordVoicing. How you display all or parts of the data will be up to the GUI portion of the program.
I can say absolutely and categorically that you would not use an enum here. enums are for constants, things that never change, which will be used by other parts of your program. You don't want to make an enum for every possible song but rather will want to create a flexible Song class that has a String variable for its title, perhaps one for the composer, and perhaps an ArrayList of ChordVoicings for the chords of the song.currently I am using a String[]
The array allows no options (at least the way I set it up).Java Code:String[] MISTY = {"4: EbMaj9","X: Bb-7","Y: Eb13","4: AbMaj7","X: Ab-9","Y: Db7(#11)", "X: G7(b13)", "Y: C7(#9)", "O: F-7", "4: Bb7(b9)", "X: G7(b13)", "Y: C7(#9)", "4: F-9", "X: Bb13"};
So lets say I want this.
int chordNumber would just select which chord out of the total number currently added.Java Code:getRandomChord(int chordNumber, boolean voicingVisible, boolean melodyVisible)
Would I use an enum to accomplish this?
Java Code:enum Misty { CHORD1("Eb", "Maj9", "4", "D") CHORD2("Bb" ,"m7", "X", "Db"); private String rootNote; private String chordType; private String voicingType; private String melodyNote; }
And you would want to create a class that can read and write Song data too and from a disk.I could make it work this way, but it just seems wrong. Because the chords will be read from a Misty file that could change at any time, new chords added, in-between voicings... and so on.
- 08-13-2012, 07:53 PM #24
Senior Member
- Join Date
- Dec 2010
- Location
- Indiana
- Posts
- 202
- Rep Power
- 3
Re: How can I go about making propper classes for propper java coding?
Is there a way to use a stringVariable that can be used as hard code?
Lets say
instead isJava Code:Key.Bb.getM7()
variableString can equal "Ab" "Bb" or whatever.Java Code:Key.variableString.getM7()
output is : "G"Java Code:Key.Ab.getM7()
output is : "G"Java Code:variableString = "Ab" Key.variableString.getM7()
Is there anything like this? Is this useful or is this just bad practice?
- 08-13-2012, 07:58 PM #25
Re: How can I go about making propper classes for propper java coding?
Have you gone through the API for java.lang.Enum<E>?
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 08-13-2012, 08:08 PM #26
Senior Member
- Join Date
- Dec 2010
- Location
- Indiana
- Posts
- 202
- Rep Power
- 3
Re: How can I go about making propper classes for propper java coding?
I glanced over it trying to understand but it confused me because there are too many unfamiliar things on it.
- 08-13-2012, 08:13 PM #27
Senior Member
- Join Date
- Dec 2010
- Location
- Indiana
- Posts
- 202
- Rep Power
- 3
Re: How can I go about making propper classes for propper java coding?
Anytime i want to understand something more I go to leepoint first because it is to-the-point and an easy reference. I really want to use the api more but I just do not understand it and it has WAY too much information. If there is a way to use it without going through a ton of studying then I will not have a problem.
Sometimes I know you can use a method like setText or something like that. But even on the API it says nothing about setText. So I am kinda annoyed at my ignorance of the api.
- 08-13-2012, 08:46 PM #28
Senior Member
- Join Date
- Dec 2010
- Location
- Indiana
- Posts
- 202
- Rep Power
- 3
Re: How can I go about making propper classes for propper java coding?
I have no idea what to look for in the api. Can I get a hint?
- 08-13-2012, 09:03 PM #29
Senior Member
- Join Date
- Dec 2010
- Location
- Indiana
- Posts
- 202
- Rep Power
- 3
Re: How can I go about making propper classes for propper java coding?
Ok here is an example. I want to check out the values() method in the api.
Enum (Java Platform SE 7 )
this is the correct place right? Well where is the values() method?
- 08-13-2012, 09:50 PM #30
Student
- Join Date
- Jul 2012
- Location
- United States
- Posts
- 328
- Rep Power
- 1
Re: How can I go about making propper classes for propper java coding?
"The compiler automatically adds some special methods when it creates an enum. For example, they have a static values method that returns an array containing all of the values of the enum in the order they are declared. This method is commonly used in combination with the for-each construct to iterate over the values of an enum type." - Enum Types (The Java Tutorials)
"Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill
- 08-13-2012, 10:43 PM #31
Re: How can I go about making propper classes for propper java coding?
More to the point of the question
I was referring to the valueOf(...) method. Something likeIs there a way to use a stringVariable that can be used as hard code?dbJava Code:Key.valueOf(Key.class, variableString)
Why do they call it rush hour when nothing moves? - Robin Williams
- 08-16-2012, 04:07 AM #32
Senior Member
- Join Date
- Dec 2010
- Location
- Indiana
- Posts
- 202
- Rep Power
- 3
Re: How can I go about making propper classes for propper java coding?
valueOf worked great :) thank you much!
New question
I have Song Study / ii-V Game / What are the 3's and 7's
for ease lets call
I have these classes JazzCards (class w/ main method), CardGUI (GUI class), Key (enum with all information and get Methods), and the 3 classes that are the game classes called SongStudy class, TheIIVGame class, and The37Game.
The JazzCard class has the main method...
Should this have a JFrame?
What information should the 3 game classes do?
Create JPanel for GUI? Do these just contain game logic?
So here is what I have for TheIIVGame
Key enumJava Code:public class TheIIVGame { private String root; private String[] keyChoices; TheiiVGame() { String[] test = {"C", "Db", "D", "Eb", "E", "F", "G", "Gb", "A", "Ab", "B", "Bb"}; loadIIVGame(test); } public void loadIIVGame(String[] rootsUsed) { keyChoices = rootsUsed; } public String randomRoot() { int i = (int)(Math.random() * keyChoices.length); root = keyChoices[i]; return root; } public void cycleRoot() { } public String getRoot() { return root; } public String getIIV(String i) { String output = (Key.valueOf(i).getM2() + " " + Key.valueOf(i).getP5()); return output; } }
Java Code:/** * @(#)KEY.java * * * @author * @version 1.00 2012/8/10 */ This is basically JazzCards class but I made a new test project to play with some code public class TestGUI { public static void main(String[] args) { TheiiVGame iiVGame = new TheiiVGame(); iiVGame.randomRoot(); String root = iiVGame.getRoot(); System.out.println("The ii-V of"); System.out.println(root); System.out.println("is"); System.out.println(iiVGame.getIIV(root); } } enum Key { //Eventualy add all these. // R b9 9 #9 b3 3 4 #4 b5 #5 b6 6 b7 7 C( "C", "D", "E", "F", "G", "A", "B"), Db("Db","Eb","F", "Gb","Ab","Bb","C"), D( "D", "E", "F#","G", "A", "B", "C#"), Eb("Eb","F", "G", "Ab","Bb","C", "D"), E( "E", "F#","G#","A", "B", "C#","D#"), F( "F", "G", "A", "Bb","C", "D", "E"), Gb("Gb","Ab","Bb","Cb","Db","Eb","F"), G( "G", "A", "B", "C", "D", "E", "F#"), Ab("Ab","Bb","C", "Db","Eb","F", "G"), A( "A", "B", "C#","D", "E", "F#","G#"), Bb("Bb","C", "D", "Eb","F", "G", "A"), B( "B", "C#","D#","E", "F#","G#","A#"); private String R; private String M2; private String M3; private String P4; private String P5; private String M6; private String M7; Key(String a, String b, String c, String d, String e, String f, String g) { R = a; M2 = b; M3 = c; P4 = d; P5 = e; M6 = f; M7 = g; } public String getR() { return R; } public String getM2() { return M2; } public String getM3() { return M3; } public String getP4() { return P4; } public String getP5() { return P5; } public String getM6() { return M6; } public String getM7() { return M7; } }
Basically I just do not know what information to send where. I would love to do an intermediate / advanced swing tutorial that goes through a game or application that uses a dynamic interactive GUI window. This window needs to change depending on options selected. If I can just be directed to a good tutorial or book that will help me understand how to make classes and swing GUI.
- 08-16-2012, 11:41 PM #33
Senior Member
- Join Date
- Dec 2010
- Location
- Indiana
- Posts
- 202
- Rep Power
- 3
Re: How can I go about making propper classes for propper java coding?
I think the reason my questions are such a mouth full is because I do not understand some basic principals that are holding me back.
I spent more time looking at MVC last night and I see that this is what I need to understand. This really not an easy thing to study. I find that there is a wealth of information out there. A lot of tutorials with holes in them and sometimes give bad programming advice. Bucky's tutorials on youtube got me started and I have been filling holes and basic understandings while in the process.
I appreciate you guys with all your patience and support with me. Even though I ask questions sometimes that seem to you that have been answered, sometimes I just do not realize the answer is there because some of this stuff is advanced. I have found some good tutorials on MVC and I just hit a new "ah ha" moment. So it looks as though I am going to finish going over the Head First book OOP Analysis and Design.
I think I will ask simple questions from now on though and post small code samples to better understand things.
Similar Threads
-
Making an array public or any variable to use across classes and Java files?
By Jonatan10 in forum New To JavaReplies: 12Last Post: 12-12-2010, 06:04 PM -
Breaking out of Breakout! making new classes
By sonny in forum New To JavaReplies: 21Last Post: 05-05-2010, 03:29 AM -
an API can return objects without making their classes public
By parthu_lkp in forum Advanced JavaReplies: 1Last Post: 08-11-2009, 02:00 PM -
Making A Set Of Classes "Importable"
By JDCAce in forum Advanced JavaReplies: 4Last Post: 12-05-2008, 09:11 AM -
Need help with Java classes for making a program.
By TheDarkReverend in forum Advanced JavaReplies: 2Last Post: 11-28-2008, 04:50 AM


3Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks