participate


Java Programming - Linked List
This question is not answered.

<<   Back to Forum  |   Give us Feedback
6 Duke Stars available
This topic has 18 replies on 2 pages.    1 | 2 | Next »
nikiben
Posts:12
Registered: 11/7/07
Linked List   
Nov 7, 2007 10:36 AM
 
 
Please im having troubles getting how to make a linked list of circle shapes. That is creat a multiple shape circle and adding them to linked list. Please how do i go about this? Thanks any help, would be nice.
 
redfalconf35
Posts:317
Registered: 8/27/07
Re: Linked List   
Nov 7, 2007 11:16 AM (reply 1 of 18)  (In reply to original post )
Helpful
 
Circle circle;
List linked = new LinkedList();
linked.add(circle);


is this not what you're trying to do?? This is as close as i can get w/o more information... If you were to ask a doctor how to operate, you wouldn't ask "How do i fix blood?", you would ask something like "How do i insert an angioplasty balloon?"

Edited by: redfalconf35 on Nov 7, 2007 2:14 PM
 
endasil
Posts:2,745
Registered: 10/12/07
Re: Linked List   
Nov 7, 2007 11:41 AM (reply 2 of 18)  (In reply to #1 )
 
 
redfalconf35 wrote:
you would ask something like "How do i insert an angioplasty balloon?"

If you have to ask your doctor that, you're ****ed anyway.
 
nikiben
Posts:12
Registered: 11/7/07
Re: Linked List   
Nov 7, 2007 12:41 PM (reply 3 of 18)  (In reply to #1 )
 
 
yea, im talking about something like that, then does this mean i have to througth and make the LinkedList Class?
 
redfalconf35
Posts:317
Registered: 8/27/07
Re: Linked List   
Nov 7, 2007 12:47 PM (reply 4 of 18)  (In reply to #3 )
 
 
make the LinkedList class? I'm not sure i understand... beyond the code that i posted, you'd have to include a skeleton program, an import statement or 2, and definitions for your circles to get working code. You don't need to override the LinkedList class already provided.
 
jwenting
Posts:9,582
Registered: 4/17/98
Re: Linked List   
Nov 7, 2007 12:50 PM (reply 5 of 18)  (In reply to #4 )
 
 
guess the kid doesn't know about the existence of LinkedList and/or has a homework assignment (you're late kid, that was 2 weeks ago) to make his own LinkedList class.
 
jToohey
Posts:1,067
Registered: 7/16/04
Re: Linked List   
Nov 7, 2007 1:26 PM (reply 6 of 18)  (In reply to #5 )
 
 
Link? Perhaps you mean this:

http://en.wikipedia.org/wiki/Lancelot_Link,_Secret_Chimp
 
nikiben
Posts:12
Registered: 11/7/07
Re: Linked List   
Nov 7, 2007 2:29 PM (reply 7 of 18)  (In reply to #1 )
 
 
sry guys maybe i did not make myself clear the first time. I want to practise using LinkedList. My task is to creat multiple circle using linkedlist instead of using arrays. here is my sample code. but im confused on how to go about the linked list of shapes?

MyProject2007.java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import javax.swing.JFrame;
 
public class project2007 extends JFrame {
 
	public project2007(){
		DrawShapes ball = new DrawShapes();
		JFrame content = new JFrame();
		content.add(ball);
		content.setSize(800, 800);
		content.setVisible(true);
		content.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);	
	}/* end of public constructor for project 2007 */
 
	/** set size, visible, and exit properly when frame is closed */
	public static void main(String args[])
	{
		project2007 project = new project2007();
 
	} /* END OF MAIN */
 
 
 
}/* END OF CLASS PROJECT 2007 */


DrawShapes.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
 
 
public class DrawShapes extends JPanel implements MouseListener, MouseMotionListener, KeyListener
{
	
	public DrawShapes(){
		this.addKeyListener(this);
		this.addMouseListener(this);
		this.addMouseMotionListener(this);
		
	}/* end drawshapes constructor */
	
	/** Mouse event method begins */
	public void mouseExited(MouseEvent e){}
	public void mousePressed(MouseEvent e){this.repaint();}
	public void mouseDragged(MouseEvent e){}			
	public void mouseMoved(MouseEvent e){}
	public void mouseEntered(MouseEvent e){}
	public void mouseClicked(MouseEvent e){}
	public void mouseReleased(MouseEvent e){}
    
    	/** Keyboard event method begins */
	public void keyPressed(KeyEvent e){}
	public void keyReleased(KeyEvent e){}	        
	public void keyTyped(KeyEvent e){}	
	
}/* end Draw shape class */


Shape.java
abstract class Shape {
 
      // A class representing shapes that can be displayed on a ShapeCanvas.
      // The subclasses of this class represent particular types of shapes.
      // When a shape is first constucted, it has height and width zero
      // and a default color of white.
 
   int left, top;      // Position of top left corner of rectangle that bounds this shape.
   int width, height;  // Size of the bounding rectangle.
   Color color = Color.white;  // Color of this shape.
   
   void reshape(int left, int top, int width, int height) {
         // Set the position and size of this shape.
      this.left = left;
      this.top = top;
      this.width = width;
      this.height = height;
   }
   
   void moveBy(int dx, int dy) {
          // Move the shape by dx pixels horizontally and dy pixels veritcally
          // (by changing the position of the top-left corner of the shape).
      left += dx;
      top += dy;
   }
   
   void setColor(Color color) {
          // Set the color of this shape
      this.color = color;
   }
 
   boolean containsPoint(int x, int y) {
         // Check whether the shape contains the point (x,y).
         // By default, this just checks whether (x,y) is inside the
         // rectangle that bounds the shape.  This method should be
         // overridden by a subclass if the default behaviour is not
         // appropriate for the subclass.
      if (x >= left && x < left+width && y >= top && y < top+height)
         return true;
      else
         return false;
   }
 
   abstract void draw(Graphics g);  
         // Draw the shape in the graphics context g.
         // This must be overriden in any concrete subclass.
 
}  // end of class Shape
 
 
 
class RectShape extends Shape {
      // This class represents rectangle shapes.
   void draw(Graphics g) {
      g.setColor(color);
      g.fillRect(left,top,width,height);
      g.setColor(Color.black);
      g.drawRect(left,top,width,height);
   }
}
 
 
class OvalShape extends Shape {
       // This class represents oval shapes.
   void draw(Graphics g) {
      g.setColor(color);
      g.fillOval(left,top,width,height);
      g.setColor(Color.black);
      g.drawOval(left,top,width,height);
   }
   boolean containsPoint(int x, int y) {
         // Check whether (x,y) is inside this oval, using the
         // mathematical equation of an ellipse.
      double rx = width/2.0;   // horizontal radius of ellipse
      double ry = height/2.0;  // vertical radius of ellipse 
      double cx = left + rx;   // x-coord of center of ellipse
      double cy = top + ry;    // y-coord of center of ellipse
      if ( (ry*(x-cx))*(ry*(x-cx)) + (rx*(y-cy))*(rx*(y-cy)) <= rx*rx*ry*ry )
         return true;
      else
        return false;
   }
}
 
nikiben
Posts:12
Registered: 11/7/07
Re: Linked List   
Nov 7, 2007 5:15 PM (reply 8 of 18)  (In reply to #7 )
 
 
yea like that..any help would be nice
 
flounder
Posts:14,625
Registered: 3/2/05
Re: Linked List   
Nov 7, 2007 6:05 PM (reply 9 of 18)  (In reply to #6 )
 
 
jToohey wrote:
Link? Perhaps you mean this:

http://en.wikipedia.org/wiki/Lancelot_Link,_Secret_Chimp

WOW! I'm gunna have to see if I can get that on DVD.
 
jToohey
Posts:1,067
Registered: 7/16/04
Re: Linked List   
Nov 7, 2007 8:38 PM (reply 10 of 18)  (In reply to #9 )
 
 
flounder wrote:
jToohey wrote:
Link? Perhaps you mean this:

http://en.wikipedia.org/wiki/Lancelot_Link,_Secret_Chimp

WOW! I'm gunna have to see if I can get that on DVD.

It was truly a television milestone.
 
nikiben
Posts:12
Registered: 11/7/07
Re: Linked List   
Nov 7, 2007 8:51 PM (reply 11 of 18)  (In reply to #10 )
 
 
please stop spamming the forum. and let the real prof anser the question.!!
 
flounder
Posts:14,625
Registered: 3/2/05
Re: Linked List   
Nov 7, 2007 9:05 PM (reply 12 of 18)  (In reply to #11 )
 
 
nikiben wrote:
please stop spamming the forum. and let the real prof anser the question.!!
Sod off! You have no control over who posts or what they post.
 
Stevew1805
Posts:157
Registered: 28.05.07
Re: Linked List   
Nov 7, 2007 9:32 PM (reply 13 of 18)  (In reply to #12 )
 
 
I like strawberry jam.
 
jwenting
Posts:9,582
Registered: 4/17/98
Re: Linked List   
Nov 7, 2007 10:24 PM (reply 14 of 18)  (In reply to #11 )
 
 
nikiben wrote:
please stop spamming the forum. and let the real prof anser the question.!!

flounder IS a real prof :)
 
This topic has 18 replies on 2 pages.    1 | 2 | Next »
Back to Forum
 
Read the Developer Forums Code of Conduct

Click to email this message Email this Topic

Edit this Topic
  
 
 
Forums Statistics
    Users Online : 26
  • Guests : 122

About Sun forums
  • Sun Forums is a large collection of user generated discussions. It is here to help you ask questions, find answers, and participate in discussions.

    Check out our guide on Getting started with Sun Forums for a full walkthrough of how to best leverage the benefits of this community.

Powered by Jive Forums