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

Thread: How to store objects from a class inn an array?

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to store objects from a class inn an array?

    Hey, im working on a program where i need to use the objects wich i get from the class "Borrehull" and store them inn an array.

    import java.io.Serializable;
     
     
    public class Borrehull implements Serializable{
     
    	private int x;
        private int y;
        private int d;
     
    	 public Borrehull (int xkoord,int ykoord,int dim){
    	    x=xkoord;
    	    y=ykoord;
    	    d=dim;
    	  }
     
    	  public int getx() {
    	    return x;
    	  }
     
    	  public int getd() {
    	    return d;
    	  }
     
    	  public int gety() {
    	    return y;
    	  }
    }

    i am using a mouse actionlistener in the "main" program where i get the x and y koordinates when i click on the frame and the dim can i adjust with some grouped radiobuttons, here is the part og the "main" program where i get the x and y koordinates with getX() and getY():

     
    class Tegne extends JPanel {//starts Tegne extends JPanel
     
    public Tegne() {//starts Tegne
     
     
    	//create a mouselistener
    	addMouseListener(new MouseListener(){
     
    		public void mouseClicked(MouseEvent arg0) {
    			if (arg0.getButton()==1)//mouse left button
    			{
     
    			y=arg0.getY();
    		             x=arg0.getX();
     
    			panel();
    			repaint();
    			}
    		}
     
    		public void mouseEntered(MouseEvent arg0){} 
    		public void mouseExited(MouseEvent arg0){} 
    		public void mousePressed(MouseEvent arg0){}	
    		public void mouseReleased(MouseEvent arg0){} 	
     
    	});
     
    }//ends Tegne	
     
    	protected void paintComponent(Graphics g){
     
    		super.paintComponent(g);			                           
    									g.setColor(Color.red);
    			if(x>0|y>0 & diameter>0)g.fillOval(x,y ,diameter*2 ,diameter*2);
    		}
     
    }//ends Tegne extends JPanel


    all help will be much appreciated(:
    Last edited by helloworld922; April 5th, 2011 at 02:18 AM.


  2. #2
    Member
    Join Date
    Mar 2011
    Location
    Earth!
    Posts
    77
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: How to store objects from a class inn an array?

    Not exactly sure what you are asking, but I guess you want to know how to use arrays? This tutorial could maybe help (havent looked that much at it since I am in a hurry).
    Arrays (The Java™ Tutorials > Learning the Java Language > Language Basics)

Similar Threads

  1. Read in file and store in 2D array start of The Game of Life
    By shipwills in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 2nd, 2011, 09:52 AM
  2. Read A File and Store Values into a 2-Dimensional Integer Array?
    By Kimimaru in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 9th, 2011, 09:13 PM
  3. Store Values in 2D array and output to textarea
    By raverz1tildawn in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 7th, 2011, 03:13 PM
  4. How can i store ArrayList objects in Access database
    By frankycool in forum JDBC & Databases
    Replies: 0
    Last Post: November 4th, 2009, 12:44 AM
  5. [SOLVED] Creation of objects of Array in Java
    By sadi_shihab in forum Collections and Generics
    Replies: 4
    Last Post: July 9th, 2009, 01:38 PM