Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2013
    Posts
    7
    Rep Power
    0

    Thumbs up How to show coordinates from a list that gets updated everytime loop.

    I have a list (let's call it tsil). My program goes through one part of the code only once to get the beginning values to be put into list tsil. Then it enters a for loop that can loop zero times or more times and gets more values added to the list tsil. I know how to translate the values in the list tsil to coordinates to where I would want it plotted, but I don't know how to get a program such as the one below (1x1 pixel, a line of length 1) to take the translated values that are now coordinates and plot them. Any help you're willing to offer me is greatly appreciated.
    Java Code:
    package painting;
    
    import javax.swing.SwingUtilities;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.BorderFactory;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Graphics;
    
    public class SwingPaintDemo2 {
       
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI(); 
                }
            });
        }
        private static void createAndShowGUI() {
            System.out.println("Created GUI on EDT? "+
            SwingUtilities.isEventDispatchThread());
            JFrame f = new JFrame("Swing Paint Demo");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
            f.add(new MyPanel());
            f.pack();
            f.setVisible(true);
        }
    }
    class MyPanel extends JPanel {
    
        public MyPanel() {
            setForeground(Color.white);
            setBackground(Color.black);
        }
        public Dimension getPreferredSize() {
            return new Dimension(933, 690);
        }
        public void paintComponent(Graphics g) {
            super.paintComponent(g);   
            g.drawLine((467-23),(350),(467-23),(350));
        }  
    }

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,036
    Rep Power
    6

    Default Re: How to show coordinates from a list that gets updated everytime loop.

    There are several ways to do this:


    1. Iterate thru them all in the paint program and draw lines between them.
    2. Add them to a polygon and draw the polygon. (Note: create the polygon outside of the paint method).


    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    Join Date
    Feb 2013
    Posts
    7
    Rep Power
    0

    Default Re: How to show coordinates from a list that gets updated everytime loop.

    Quote Originally Posted by jim829 View Post
    There are several ways to do this:


    1. Iterate thru them all in the paint program and draw lines between them.
    2. Add them to a polygon and draw the polygon. (Note: create the polygon outside of the paint method).


    Regards,
    Jim
    Sorry that I wasn't clear, I intend on creating 1x1 pixel points located at the coordinates I get from list tsil.

    But I think I can still apply what you've told me to do what I wanted, however I don't know how to iterate through them all in the paint program, if I could be told that would be great (seeing as this project will probably benefit others besides me for free perhaps) but if not I would understand.

    As usual, thanks for the help you offered and any help you're willing to offer later.

Similar Threads

  1. Trying to get a list that goes on to show images
    By ciara in forum CLDC and MIDP
    Replies: 4
    Last Post: 12-05-2012, 07:26 PM
  2. Replies: 3
    Last Post: 04-24-2012, 11:57 PM
  3. Please show an example of a String in a while loop.
    By LoViNgHeArTy in forum New To Java
    Replies: 3
    Last Post: 04-19-2011, 11:21 AM
  4. [SOLVED] An annoying warning everytime I compile
    By Leprechaun in forum New To Java
    Replies: 8
    Last Post: 04-23-2008, 09: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
  •