Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By Sierra

Thread: Trying to input Draggable boxes

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

    Exclamation Trying to input Draggable boxes

    Hi.
    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 'SynthesizedPanel', 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: SynthBlock. This is the actual block, who calculates his own position etc.

    I programmed quite a lot of it now, but I can't get the draggable SynthBoxes working..
    If someone could take a look at my project, that would be great!
    http://rapidshare.com/files/169532825/simsynth.zip

    Greetings

  2. #2
    Sierra is offline AN21XX
    Join Date
    Mar 2012
    Location
    Munich
    Posts
    297
    Rep Power
    3

    Default Re: Trying to input Draggable boxes

    You probably won't get an answer as your problem decription is too inaccurate and your code is in an external link. Describe your problem and post only the code of the concerned section please.
    DarrylBurke likes this.
    I like likes!

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

    Default Re: Trying to input Draggable boxes

    Quote Originally Posted by Sierra View Post
    You probably won't get an answer as your problem decription is too inaccurate and your code is in an external link. Describe your problem and post only the code of the concerned section please.
    Excuse me, let me explain it: I have a JPanel child where I draw some stuff onto. This custom JPanel has a NULL layout and contains so called 'boxes'; smaller JPanels. The position of these JPanels is automatically calculated by the method updateInfo() in those boxes. Now, I would like to make these boxes draggable. But I can't get it to work tough..

    Java Code:
        @Override
        protected void updateInfo(){ //GetDurationRelation etc are constant values.
            setPanelText(getFrequency() + "MHz", (getDuration() / 1000) + "s"); //Set text
            updateColor();
            setBackground(getColor());   
            setToolTipText(getFrequency() + "Hz, " + getDuration()/1000 + "s"); //onMouseHover
            int yPos = (getChannel().getChannelNumber() + 2) * (getChannel().getChannelHeight()) - (getChannel().getChannelHeight()*2) + 20; //20 offset for headers
            int width = (int) ((getDuration() * getChannel().getDurationRelation() / 1000)); //A little precision loss.
            setBounds((getStart() * getChannel().getDurationRelation()/ 1000) + 1, yPos, width, getChannel().getChannelHeight() ); //Stupid 1 pixel offset. 
        }
    Java Code:
        public void drawSynthGrid(){
            panel.removeAll(); //Remove all blocks.
            
            int height = (channels.size() * getChannelHeight()) + 20; //Calculate the height.
            if (height < TimeLinePanel.minHeight) {
                height = TimeLinePanel.minHeight;      
            }
    
            int width = getMaxDistance();   // Estimate how much space we'll need.
            if (width < TimeLinePanel.minWidth) {
                width = TimeLinePanel.minWidth;
            }
            setDimensions(width, height);
            
            for (Channel channel : channels){
                for (SynthBlock block : channel.getBlocks()){
                    panel.add(block); // Add our Blocks
                }
            }
            
            panel.revalidate();
            panel.repaint();
            System.out.println("Redrawn");
        }

Similar Threads

  1. Replies: 1
    Last Post: 11-14-2011, 02:03 PM
  2. JToolBar make it non-draggable
    By nathic in forum New To Java
    Replies: 1
    Last Post: 03-22-2011, 09:52 AM
  3. Replies: 3
    Last Post: 07-14-2010, 11:34 PM
  4. Duplicate Input Boxes
    By habester in forum New To Java
    Replies: 3
    Last Post: 11-09-2009, 07:13 PM
  5. Canvas with draggable window
    By shravan28 in forum SWT / JFace
    Replies: 1
    Last Post: 03-24-2009, 08:11 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
  •