3d Shape

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kid Programmer
    New Member
    • Mar 2008
    • 176

    3d Shape

    Hello guys. How do you draw a 3d shape in a GUI? Here is my code:
    Code:
    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() {
            setBorder(BorderFactory.createLineBorder(Color.black));
        }
    
        public Dimension getPreferredSize() {
            return new Dimension(250,200);
        }
    
        public void paintComponent(Graphics g) {
            super.paintComponent(g);       
    
            // 3d shape code goes here
        }  
    }
  • BigDaddyLH
    Recognized Expert Top Contributor
    • Dec 2007
    • 1216

    #2
    Please define "3D shape". I am a poor programmer who can only afford a flat screen.

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by BigDaddyLH
      Please define "3D shape". I am a poor programmer who can only afford a flat screen.
      :-) I think the OP is talking about eye points, view cones and projections and such.

      kind regards,

      Jos (<--- on a paper tape ;-)

      Comment

      • Kid Programmer
        New Member
        • Mar 2008
        • 176

        #4
        Originally posted by JosAH
        :-) I think the OP is talking about eye points, view cones and projections and such.

        kind regards,

        Jos (<--- on a paper tape ;-)
        You are right JosAH. Cones, cube, pyramids etc.

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by Kid Programmer
          You are right JosAH. Cones, cube, pyramids etc.
          I didn't say that, I mentioned the technology participants in 3D projection math.
          You can either google for it (it is simple 101 geometry) or use the Java3D package
          that does it for you but it also does a whole lot more.

          kind regards,

          Jos

          Comment

          • BigDaddyLH
            Recognized Expert Top Contributor
            • Dec 2007
            • 1216

            #6
            As Woody Allen said, "Students achieving Oneness will move on to Twoness", perhaps you should consider 3D only after you have mastered 2D. Have you mastered 2D?

            This 2d Java tutorial describes 2d graphics, geometry, text APIs, images, printing, advanced 2d topics

            Comment

            • JosAH
              Recognized Expert MVP
              • Mar 2007
              • 11453

              #7
              Is this thread dead now? Did the OP expect boilerplate code? Too bad because
              the subject can be an interesting one.

              kind regards,

              Jos

              Comment

              Working...