Page 2 of 2 FirstFirst 12
Results 21 to 33 of 33
Like Tree3Likes

Thread: How can I go about making propper classes for propper java coding?

  1. #21
    AcousticBruce is offline Senior Member
    Join Date
    Dec 2010
    Location
    Indiana
    Posts
    202
    Rep Power
    4

    Default Re: How can I go about making propper classes for propper java coding?

    Yeah sorry about 7#5 .... C7#5. Haha add that Major 3rd and you will be all set.

    I cant wait to check out your code.
    Last edited by AcousticBruce; 08-11-2012 at 07:15 PM.

  2. #22
    AcousticBruce is offline Senior Member
    Join Date
    Dec 2010
    Location
    Indiana
    Posts
    202
    Rep Power
    4

    Default 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.
    Java Code:
    voicing style  :  "4"
    Chord name   :  "EbMaj9"
    Melody note  :   "D"
    I want to be able to turn off melody note and voicing style with a check box or whatever.

    currently I am using a String[]
    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"};
    The array allows no options (at least the way I set it up).


    So lets say I want this.

    Java Code:
    getRandomChord(int chordNumber, boolean voicingVisible, boolean melodyVisible)
    int chordNumber would just select which chord out of the total number currently added.

    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;
    }
    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.


    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.

  3. #23
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: How can I go about making propper classes for propper java coding?

    Quote Originally Posted by AcousticBruce View Post
    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.
    Java Code:
    voicing style  :  "4"
    Chord name   :  "EbMaj9"
    Melody note  :   "D"
    I want to be able to turn off melody note and voicing style with a check box or whatever.
    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.

    currently I am using a String[]
    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"};
    The array allows no options (at least the way I set it up).


    So lets say I want this.

    Java Code:
    getRandomChord(int chordNumber, boolean voicingVisible, boolean melodyVisible)
    int chordNumber would just select which chord out of the total number currently added.

    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;
    }
    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.


    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.
    And you would want to create a class that can read and write Song data too and from a disk.

  4. #24
    AcousticBruce is offline Senior Member
    Join Date
    Dec 2010
    Location
    Indiana
    Posts
    202
    Rep Power
    4

    Default 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

    Java Code:
    Key.Bb.getM7()
    instead is
    Java Code:
    Key.variableString.getM7()
    variableString can equal "Ab" "Bb" or whatever.

    Java Code:
    Key.Ab.getM7()
    output is : "G"
    Java Code:
    variableString = "Ab"
    Key.variableString.getM7()
    output is : "G"


    Is there anything like this? Is this useful or is this just bad practice?

  5. #25
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    Default Re: How can I go about making propper classes for propper java coding?

    Have you gone through the API for java.lang.Enum<E>?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #26
    AcousticBruce is offline Senior Member
    Join Date
    Dec 2010
    Location
    Indiana
    Posts
    202
    Rep Power
    4

    Default 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.

  7. #27
    AcousticBruce is offline Senior Member
    Join Date
    Dec 2010
    Location
    Indiana
    Posts
    202
    Rep Power
    4

    Default 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.

  8. #28
    AcousticBruce is offline Senior Member
    Join Date
    Dec 2010
    Location
    Indiana
    Posts
    202
    Rep Power
    4

    Default 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?

  9. #29
    AcousticBruce is offline Senior Member
    Join Date
    Dec 2010
    Location
    Indiana
    Posts
    202
    Rep Power
    4

    Default 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?

  10. #30
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    3

    Default Re: How can I go about making propper classes for propper java coding?

    Quote Originally Posted by AcousticBruce View Post
    Ok here is an example. I want to check out the values() method in the api.

    this is the correct place right? Well where is the values() method?
    "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

  11. #31
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    Default Re: How can I go about making propper classes for propper java coding?

    More to the point of the question
    Is there a way to use a stringVariable that can be used as hard code?
    I was referring to the valueOf(...) method. Something like
    Java Code:
    Key.valueOf(Key.class, variableString)
    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  12. #32
    AcousticBruce is offline Senior Member
    Join Date
    Dec 2010
    Location
    Indiana
    Posts
    202
    Rep Power
    4

    Default 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

    Java 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;
    	}
    
    }
    Key enum

    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.

  13. #33
    AcousticBruce is offline Senior Member
    Join Date
    Dec 2010
    Location
    Indiana
    Posts
    202
    Rep Power
    4

    Default 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.
    DarrylBurke and Fubarable like this.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 12
    Last Post: 12-12-2010, 06:04 PM
  2. Breaking out of Breakout! making new classes
    By sonny in forum New To Java
    Replies: 21
    Last Post: 05-05-2010, 03:29 AM
  3. Replies: 1
    Last Post: 08-11-2009, 02:00 PM
  4. Making A Set Of Classes "Importable"
    By JDCAce in forum Advanced Java
    Replies: 4
    Last Post: 12-05-2008, 09:11 AM
  5. Need help with Java classes for making a program.
    By TheDarkReverend in forum Advanced Java
    Replies: 2
    Last Post: 11-28-2008, 04:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •