Results 1 to 10 of 10
Like Tree1Likes
  • 1 Post By quad64bit

Thread: Representing classes visually on a 'timeline'

  1. #1
    Nindustries is offline Member
    Join Date
    Nov 2012
    Posts
    8
    Rep Power
    0

    Question Representing classes visually on a 'timeline'

    Good day.

    My first post, yay!
    I'm working on a project for school, the requirements are that we must have at least 10 classes and implement the usual stuff like inheritence, overriding, ...
    I wanted to do something special, so I'm working on a visual drag'n drop program for sounds. So you can specify the frequency and duration of a tone, and add the specific block to a channel. A channel is something I created so blocks don't have to overlap. A channel is actually just an additional of blocks beneath the other one. The amount of channels is unlimited, so is the length of a Channel. Channels will be played simultaneously. Now comes the problem..

    I have a class named 'SynthBlock', which contains the starting time, duration and frequency of this tone. It is a part of my Channel class. (= arraylist)
    I wanted to represent a synthblock visually, so I made another class: ToneBox. This must be a child-class from JComponent and override the paintComponent method.

    I wanted to ask... is it wise to inherit from the JComponent class? And how would I best calculate the coordinates needed for my drawRectangle?
    Project is included if needed. I am certainly not trying to give my schoolwork away to someone else, I just want to find out the best way.

    EDIT: It seems the 'manage attachments' window does not show properly under Firefox/Win7 ?
    So I uploaded it here: https://rapidshare.com/files/1086823385/project.zip

    A visual sample:
    Representing classes visually on a 'timeline'-prog_sample.jpg

    Greetings,
    Nindustries
    Last edited by Nindustries; 11-14-2012 at 12:34 PM.

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: Representing classes visually on a 'timeline'

    is it wise to inherit from the JComponent class?
    Depends on your needs! It can be totally fine if it does something you need to do. I subclass JPanel all the time for screen drawing.

    And how would I best calculate the coordinates needed for my drawRectangle?
    How do you mean? Are they placed based on a user click? If so, you can just get the mouse coordinates and go from there.

  3. #3
    Nindustries is offline Member
    Join Date
    Nov 2012
    Posts
    8
    Rep Power
    0

    Question Re: Representing classes visually on a 'timeline'

    Quote Originally Posted by quad64bit View Post
    I subclass JPanel all the time for screen drawing.
    So it would be best for me to use a JPanel? And why? I mean, why not JComponent?

    Quote Originally Posted by quad64bit View Post
    How do you mean? Are they placed based on a user click? If so, you can just get the mouse coordinates and go from there.
    Yeah that would be the best thing to do I think. I think i'll program it like this: when a user clicks the Add button, they can drag a box in the timeline.

    Greetings

  4. #4
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: Representing classes visually on a 'timeline'

    So it would be best for me to use a JPanel? And why? I mean, why not JComponent?
    JPanel does subclass JComponent but provides some other things as well. There is no reason you can't make your own components though - if you have special requirements that none of the JComponent subclasses meet, then sure, write your own. Code reuse is the holy grail though, don't reinvent the wheel. If an existing component does 90% of what you need and you just have to add or change a couple things, do that!

    Yeah that would be the best thing to do I think. I think i'll program it like this: when a user clicks the Add button, they can drag a box in the timeline.
    Sure, that works. I've done similar things. I did this for a chess game, where moving the piece did several things:
    1. Clicking and dragging on a piece would leave the real piece in place, but would spawn a ghosted image of the piece that would follow the cursor. When the user let go of the button, if the mouse was over a valid destination, then the ghost would disappear, I'd remove the original piece for it's original location, and I would insert it into the new spot. The visual effect was that you grabbed a piece and dropped it. You could do something similar!
    Nindustries likes this.

  5. #5
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default Re: Representing classes visually on a 'timeline'


  6. #6
    Nindustries is offline Member
    Join Date
    Nov 2012
    Posts
    8
    Rep Power
    0

    Question Re: Representing classes visually on a 'timeline'

    Quote Originally Posted by doWhile View Post
    Sorry, I tried putting that in my first post but I cant edit it anymore?

    Greetings
    Last edited by Nindustries; 11-16-2012 at 11:23 AM.

  7. #7
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Representing classes visually on a 'timeline'

    That's OK - the main thing is that everybody knows the location of the rest of the discussion. Make sure you post some sort of "conclusion" if - you reach one - in both threads.

    And since I'm posting... One thing I've noticed is that people sometimes dive right in to the visual layout stuff too quickly, in my opinion. If I were you I would start with classes for the Tone, the Channel an whatever it is a collection of channels make. That is I would determine the behaviour (methods) of these classes, write code to implement that and test it first. The important thing is that these classes would involve no graphical user interface code. Having robust "model" (the name given to the abstract thing that stands behind a gui - the thing that the gui allows the user to see and change) makes writing the gui code more straightforward.

  8. #8
    Nindustries is offline Member
    Join Date
    Nov 2012
    Posts
    8
    Rep Power
    0

    Default Re: Representing classes visually on a 'timeline'

    I already coded the 'basic' stuff like the forms, Channel classes and SynthBlock classes. :-) (included in my upload project)

    Okay guys, so I figured:
    I will be using a Component-child class from JPanel(or JButton) where I use the GridBayLayout. I will use the dynamic aspect of the constraints of this LayoutManager.
    I will then implement drag-and-drop onto this JPanel, if it is dropped out of the constraints, the Panel will generate new and bigger constraints.
    After being dragged and dropped, the panel will paint lines to visualise the columns and rows. (Or the constraints as you can call it.)

    So first things first, how can I determine the user dropped it onto an existing 'constraint'/cell or not?

    Greetings

  9. #9
    Nindustries is offline Member
    Join Date
    Nov 2012
    Posts
    8
    Rep Power
    0

    Default Re: Representing classes visually on a 'timeline'

    To thank you for all your good support, I hereby upload my finished project.
    It's not a masterpiece, but it does the job.
    Note: It's a NetBeans project.

    Download link: http://rapidshare.com/files/817242814/VGO.zip

  10. #10
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: Representing classes visually on a 'timeline'

    Grats! One step at a time!

Similar Threads

  1. representing trees within parentheses
    By Googol in forum New To Java
    Replies: 0
    Last Post: 10-20-2012, 01:12 AM
  2. need help with memory game for visually handicapped
    By Niketan in forum Forum Lobby
    Replies: 1
    Last Post: 01-16-2011, 10:25 AM
  3. Representing ERD with symbols
    By vivvy in forum JDBC
    Replies: 1
    Last Post: 02-17-2010, 05:17 PM
  4. Replies: 1
    Last Post: 04-01-2009, 02:00 AM
  5. Java classes representing DB tables
    By aa74 in forum Advanced Java
    Replies: 1
    Last Post: 06-20-2008, 09:06 PM

Tags for this Thread

Posting Permissions

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