Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: logical problem with opening a Sliding Window(Custom window) from 'RIGHT' - LEFT

  1. #1
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default logical problem with opening a Sliding Window(Custom window) from 'RIGHT' - LEFT

    for a common approach regarding with Top-Level containers such as JFrame or JDialogs, everything is manipulated from a LEFT-to-RIGHT orientation, i have a custom window, with some animated opening with a an Orientation of Left-to-Right, i was trying to make it a Right-To-Left opening with this basic logic, like decrementing the 'x' position twice than the 'width' of the component (i.e for every single decrement of width by '1' the 'x' will have a twice or 3 times decrement update), but i ended up with a Jaggy animated window and it somehow starts with the middle
    here is a sample working code for the sliding window (LEFT to RIGHT).

    import com.sun.awt.AWTUtilities;
    import java.awt.*;
    import java.util.List;
    import java.util.*;
    import javax.swing.*;
     
     
    public class TransparentSlideDialog1 extends JDialog {
     
        private Panel panel;
        private int widthLimit;
        private int heightLimit;
     
        public TransparentSlideDialog1() {
     
            panel = new Panel();
            getContentPane().add(panel);
        }
     
        public void setDialogSize(int w, int h) {
     
            widthLimit = w;
            heightLimit = h;
            setSize(w, h);
        }
     
        private class Panel extends JPanel implements Runnable {
     
            private Thread runner;
            private boolean stop;
            private int width;
            private int height;
     
            public Panel() {
     
                setLayout(null);
                setOpaque(false);
                width = 0;
                height = 50;
            }
     
            public void paintComponent(Graphics g) {
     
                int arc = 20;
                Paint p = new GradientPaint(0.0f, 0.000f, new Color(0, 0, 0, 240), width - 50, height - 50, new Color(0, 0, 0, 255), true);
                Graphics2D g2 = (Graphics2D) g.create();
                g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
     
                g2.setPaint(p);
                g2.fillRoundRect(getX() + 20, getY() + 35, width - 50, height - 50, arc, arc);
                g2.setStroke(new BasicStroke(2f));
                g2.setColor(new Color(150, 150, 150, 255));
                g2.drawRoundRect(getX() + 20, getY() + 35, width - 50, height - 50, arc, arc);
            }
     
            public void open() {
     
                runner = new Thread(this);
                runner.start();
            }
     
            public void run() {
     
                while (!stop) {
     
                    if (width <= getWidth()) {
     
                        width += 5;
                    }
     
                    if (height <= getHeight() && width >= getWidth()) {
     
                        height += 3;
                    }
                    if (height >= heightLimit && width >= widthLimit) {
     
                        runner.interrupt();
                        stop = true;
                    }
     
                    repaint();
     
                    try {
     
                        Thread.sleep(2);
                    } catch (InterruptedException e) {
     
                        Thread.currentThread().interrupt();
                        e.printStackTrace();
                    }
                }
            }
        }
     
        public synchronized void openSlidePanel() {
     
            panel.open();
        }
     
        public static void main(String[] args) {
     
            final TransparentSlideDialog1 d = new TransparentSlideDialog1();
            d.setDialogSize(1200, 640);
            d.openSlidePanel();
            d.setModal(true);
            d.setLocationRelativeTo(null);
            d.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
            d.setUndecorated(true);
            AWTUtilities.setWindowOpaque(d, false);
            d.setVisible(true);
        }
    }

    i just need some guide on the logical part on how can i accomplish a RIGHT-TO-LEFT opening of this window, or maybe is there any technical concerns i need to consider.
    Last edited by chronoz13; December 17th, 2011 at 03:28 AM.


  2. #2
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default Re: logical problem with opening a Sliding Window(Custom window) from 'RIGHT' - LEFT

    i got an article although not technically relevant(Java code), but the logic implies a major concern
    Top of a web page is zero so any negative value is off the page.

    Left of a web page also zero so any negative value is off the page.

    Right and bottom of a web page are infinite so any positive value is on the page.

    There is no value that will take an object off of the right or bottom of a web page.

    the problem was a Transition regarding with an animated opening window

Similar Threads

  1. window icon
    By luisp88 in forum AWT / Java Swing
    Replies: 6
    Last Post: September 29th, 2011, 01:56 PM
  2. Windows 7 - jar file not opening a window
    By Yaten13 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 10th, 2011, 05:53 PM
  3. Replies: 36
    Last Post: July 25th, 2011, 10:27 AM
  4. Craating non active window ,and inputing to the non active window.
    By java-beginner in forum Java Theory & Questions
    Replies: 0
    Last Post: February 25th, 2011, 10:13 PM
  5. cmd.exe DOS Window
    By Curious in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: March 1st, 2010, 10:30 AM