336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

public void onClick(View v) {

if (alButtonBool.get(buttonNum) == false) {

alButtonBool.set(buttonNum, true);


if (media_player_red_filePath.get(index) == "") {

media_player_red[index] = MediaPlayer.create(

mContext, raw);

} else {

media_player_red[index] = new MediaPlayer();

try {

media_player_red[index]

.setDataSource(media_player_red_filePath

.get(index));

} catch (Exception e) {

e.printStackTrace();

}

}

media_player_red[index]

.setOnPreparedListener(mPreparedListener);

media_player_red[index].setVolume(media_player_red_Volume,

media_player_red_Volume);

try {

media_player_red[index].prepare();


} catch (IllegalStateException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

} else {

media_player_red[index].release();

media_player_red[index] = null;

alButtonBool.set(buttonNum, false);

}

}

336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

public boolean onTouch(View v, MotionEvent event) {

switch (event.getAction()) {

case MotionEvent.ACTION_DOWN:

if (media_player_ye_state.get(index) == false) {

media_player_ye_state.set(index, true);


if (media_player_ye_filePath.get(index) == "") {

media_player_ye[index] = MediaPlayer.create(

mContext, raw);

} else {

media_player_ye[index] = new MediaPlayer();

try {

media_player_ye[index]

.setDataSource(media_player_ye_filePath

.get(index));

} catch (Exception e) {

e.printStackTrace();

}

}

media_player_ye[index]

.setOnPreparedListener(mPreparedListener);

media_player_ye[index].setVolume(

media_player_ye_Volume, media_player_ye_Volume);

media_player_ye[index].setLooping(true); // 반복재생

alButton.get(buttonNum).setPressed(true);

try {

media_player_ye[index].prepare();

} catch (Exception e) {

e.printStackTrace();

}

}

return true;

case MotionEvent.ACTION_UP:

alButton.get(buttonNum).setPressed(false);

media_player_ye_state.set(index, false);

try {

media_player_ye[index].release();

} catch (Exception e) {

media_player_ye[index] = null;

e.printStackTrace();

}

return true;

}

return false;

}

336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

 

class DraggableComponent extends JComponent

{

 

    /** If sets <b>TRUE</b> this component is draggable */

    private boolean draggable = true;

    /**

     * 2D Point representing the coordinate where mouse is, relative parent

     * container

     */

    protected Point anchorPoint;

    /** Default mouse cursor for dragging action */

    protected Cursor draggingCursor = Cursor

           .getPredefinedCursor(Cursor.HAND_CURSOR);

    /**

     * If sets <b>TRUE</b> when dragging component, it will be painted over each

     * other (z-Buffer change)

     */

    protected boolean overbearing = false;

 

    public DraggableComponent()

    {

        addDragListeners();

        setOpaque(true);

        setBackground(new Color(240, 240, 240));

    }

 

    /**

     * Add Mouse Motion Listener with drag function

     */

    private void addDragListeners()

    {

        /**

         * This handle is a reference to THIS because in next Mouse Adapter

         * "this" is not allowed

         */

        final DraggableComponent handle = this;

        addMouseMotionListener(new MouseAdapter()

        {

 

           @Override

           public void mouseMoved(MouseEvent e)

           {

               anchorPoint = e.getPoint();

           setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

           }

 

           @Override

           public void mouseDragged(MouseEvent e)

           {

               int anchorX = anchorPoint.x;

               int anchorY = anchorPoint.y;

 

               Point parentOnScreen = getParent().getLocationOnScreen();

               Point mouseOnScreen = e.getLocationOnScreen();

               Point position = new Point(mouseOnScreen.x - parentOnScreen.x

                       - anchorX, mouseOnScreen.y - parentOnScreen.y - anchorY);

               setLocation(position);

 

               // Change Z-Buffer if it is "overbearing"

               if (overbearing)

               {

                   getParent().setComponentZOrder(handle, 0);

                   repaint();

               }

           }

        });

    }

 

    @Override

    protected void paintComponent(Graphics g)

    {

        super.paintComponent(g);

        if (isOpaque())

        {

           g.setColor(getBackground());

           g.fillRect(0, 0, getWidth(), getHeight());

        }

    }

 

    private void removeDragListeners()

    {

        for (MouseMotionListener listener : this.getMouseMotionListeners())

        {

           removeMouseMotionListener(listener);

        }

        setCursor(Cursor.getDefaultCursor());

    }

}


http://www.codeproject.com/Articles/116088/Draggable-Components-in-Java-Swing

'Programming > JAVA,JSP' 카테고리의 다른 글

JAVA Console Token 구현  (0) 2013.08.07
JAVA 제네릭을 사용한 Store Class  (0) 2013.08.07
JAVA Swing 두개의 판넬을 겹치기  (0) 2013.08.03
JAVA JNI  (0) 2013.05.01
Eclipse Tips  (0) 2013.04.30