Welcome to Dream.In.Code
Become a Java Expert!

Join 149,609 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,882 people online right now. Registration is fast and FREE... Join Now!




error on cube program

 
Reply to this topicStart new topic

error on cube program, dont know what is wrong with the code

Mastergeek666
20 Aug, 2007 - 09:20 AM
Post #1

D.I.C Head
Group Icon

Joined: 10 Aug, 2007
Posts: 120


Dream Kudos: 75
My Contributions
CODE

import javax.swing.*;
import java.util.*;  
import java.awt.*;
import java.applet.*;

public class asdfasdfw extends Applet
{
    public class CubePanel extends JPanel
     {
          private double x_verts[] = {-48,48,48,-48}; // Four vertices for a cube
          private double y_verts[] = {48,48,-48,-48};
          private double shape_save[] = {-48,48,48,-48,48,48,-48,-48}; // Original shape before transformation
          private double rotation_pos = 0; // Rotation position
          private double chroma_pos = 64; // Color animation position
          void CubePanel()
          {
               // Does nothing here
          }
          private void drawCube(Graphics page,int xpos,int ypos)
          {
               // Reset to original shape
               for(int index = 0;index < 4;index++)
                    x_verts[index] = shape_save[index]; // Copy X's
               for(int index = 4;index < 8;index++)
                    y_verts[index-4] = shape_save[index]; // Copy Y's
               // Rotate all the points like so...
               double temp_x,temp_y;
               for(int index = 0;index < 4;index++)
               {
                    // Rotate the square normally over the y axis in the xyz plane (I think)
                    temp_x = x_verts[index]*Math.cos(rotation_pos)-y_verts[index]*Math.sin(rotation_pos);
                    temp_y = x_verts[index]*Math.sin(rotation_pos)+y_verts[index]*Math.cos(rotation_pos);
                    x_verts[index] = temp_x;
                    y_verts[index] = temp_y;
                    // And the square rotates to look 3D 2x along the x axis in the xyz plane (I think)
                    y_verts[index] = y_verts[index]*Math.sin(rotation_pos/2);
               }
               // Add a degree of rotation
               rotation_pos += 0.001;
               chroma_pos++;
               if(chroma_pos > 255)
                    chroma_pos = 64; // Reset to flash color
               // Draws the cube in question
               // Selects the color
               Color tempcolor = new Color(0,0,(int)chroma_pos);
               page.setColor(tempcolor);
               for(int index = 0;index < 4;index++)
               {
                    if(index < 3)
                    {
                         page.drawLine((int)x_verts[index]+xpos,(int)y_verts[index]+ypos,(int)x_verts[index+1]+xpos,(int)y_verts[index+1]+ypos);
                    }
                    else
                    {
                         page.drawLine((int)x_verts[index]+xpos,(int)y_verts[index]+ypos,(int)x_verts[0]+xpos,(int)y_verts[0]+ypos);
                    }
               }
          }
          public void paintComponent(Graphics page)
          {
               super.paintComponent(page);
               // Use a black background
               setBackground(Color.black);
               // Draw the cube
               drawCube(page,128,128);
               repaint();
          }
     }
     public void init()
     {
          setSize(256,256);
          getContentPane().add(new CubePanel());
     }

}

~edit: code tags

The problem I'm having is with this line, "getContentPane().add(new CubePanel());" it keeps telling me that it cannot find symbol and puts the ^ under the g in getContentPane. Any help would be appreciated.

This post has been edited by PennyBoki: 22 Aug, 2007 - 04:15 PM
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Error On Cube Program
20 Aug, 2007 - 10:16 AM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,655



Thanked: 313 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
Inherit from JApplet instead of Applet. getContentPane() is a method of a JComponent. Once you change it to JApplet it should work fine. However you don't need to use getContentPane() and could just use add(new CubePanel()); by itself since the add() method assumes the content pane by default.

Nice little applet you have there I might add. Looks neat.

Good luck with it. smile.gif
User is offlineProfile CardPM
+Quote Post

Mastergeek666
RE: Error On Cube Program
20 Aug, 2007 - 01:21 PM
Post #3

D.I.C Head
Group Icon

Joined: 10 Aug, 2007
Posts: 120


Dream Kudos: 75
My Contributions
QUOTE(Martyr2 @ 20 Aug, 2007 - 11:16 AM) *

Inherit from JApplet instead of Applet. getContentPane() is a method of a JComponent. Once you change it to JApplet it should work fine. However you don't need to use getContentPane() and could just use add(new CubePanel()); by itself since the add() method assumes the content pane by default.

Nice little applet you have there I might add. Looks neat.

Good luck with it. smile.gif



Thx for the help!
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 12:06AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month