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 5 of 5

Thread: Creating a cube applet

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    26
    My Mood
    Inspired
    Thanks
    14
    Thanked 0 Times in 0 Posts

    Default Creating a cube applet

    package assignment7;
     
    import java.awt.*;
     
    public class Exercise5 
    {
        public void paint(Graphics g)
        {
            g.drawRect(30, 50, 50, 50); 
            g.drawLine(30,50,40,40); 
            g.drawLine(80,50,90,40); 
            g.drawLine(40,40,90,40); 
            g.drawLine(80,100,90,90); 
            g.drawLine(90,40,90,90);
        }
        public static void main(String args[])
        {
     
        }
    }
    i got how to create the cube, but how do i loop the drawline?
    i am supposed to only have one ?


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,847
    My Mood
    Mellow
    Thanks
    178
    Thanked 631 Times in 618 Posts

    Default Re: Creating a cube applet

    What this code is supposed to do and your question are not clear. Can you post code that can be compiled and run to demonstrate what you're trying to do and then ask a specific question about that code or the result?

    If this is meant to be a Swing GUI, there are many elements missing (like the Swing and the GUI), but even the little bit you've shown is not how painting in a Swing app is correctly done. The Custom Painting Lesson may answer some of your questions.

  3. #3
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: Creating a cube applet

    Quote Originally Posted by ATB View Post
    i got how to create the cube, but how do i loop the drawline?
    i am supposed to only have one ?
    As GregBrannon correctly pointed out, your are missing many things. Your code is not a standalone GUI application and not even an "applet". You need to write several things to create a minimal but valid infrastructure for a GUI (AWT or Swing) application or applet.
    There are tons of examples on the web, in the official tutorial, in articles/blogs and even I have some nice examples.
    Andrea, www.andbin.net SCJP 5 (91%) SCWCD 5 (94%)

    Useful links for Java beginners My new project Java Examples on Google Code

  4. #4
    Junior Member
    Join Date
    Mar 2014
    Location
    Denmark, Albertslund
    Posts
    15
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: Creating a cube applet

    You need to create a swing or awt to you project. Example code:
    import java.awt.*;

    import javax.swing.*;

    public class SwingVindue extends JFrame
    {
    public void paint(Graphics g) {

    //L�ngde 1
    g.drawLine(600, 50, 50, 50);
    //L�ngde 2
    g.drawLine(600, 500, 70, 500);
    //H�jde 1
    g.drawLine(50,50,50,80);
    //h�jde 2
    g.drawLine(600,500,600,70);}

    public static void main(String[] arg)
    {
    SwingVindue vindue = new SwingVindue();
    vindue.setSize(1280,800);
    vindue.setVisible(true);
    }
    }

    --- Update ---

    My own example

    --- Update ---

    I don't try to create a cube but is wiew you how you can set you draw lines in to a window

  5. The Following User Says Thank You to magnus110498 For This Useful Post:

    ATB (April 6th, 2014)

  6. #5
    Junior Member
    Join Date
    Mar 2014
    Posts
    26
    My Mood
    Inspired
    Thanks
    14
    Thanked 0 Times in 0 Posts

    Default Re: Creating a cube applet

    thanks!

Similar Threads

  1. Cube array help
    By JAVAHELPP in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 13th, 2013, 11:52 AM
  2. creating Frame objects in an Applet
    By vk2goh in forum AWT / Java Swing
    Replies: 1
    Last Post: May 30th, 2012, 07:04 AM
  3. Creating an Applet program using JTextFields, JLabel, Jbutton.
    By Maxly in forum Java Theory & Questions
    Replies: 1
    Last Post: March 9th, 2012, 01:39 PM
  4. Inheritance - Testing Point, Square, and Cube Classes
    By natefactor07 in forum Object Oriented Programming
    Replies: 1
    Last Post: January 30th, 2011, 07:56 PM
  5. Creating a threaded applet
    By mjpam in forum Java Applets
    Replies: 22
    Last Post: August 11th, 2010, 06:37 PM

Tags for this Thread