473,324 Members | 2,179 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

array of objects

56
i am trying to add a new object to a normal member inner class named MyLine
here is the inner class:
Expand|Select|Wrap|Line Numbers
  1. class MyLine{
  2.  
  3.         public void add(int xx1, int yy1, int xx2, int yy2){
  4.             x1=xx1;
  5.             x2=xx2;
  6.             y1=yy1;
  7.             y2=yy2;
  8.         }
  9.         public int getX1(){return x1;}
  10.         public int getX2(){return x2;}
  11.         public int getY1(){return y1;}
  12.         public int getY2(){return y2;}
  13.  
  14.     }
when i try to add a new object from a method in the outer class like this:
Expand|Select|Wrap|Line Numbers
  1. public void mouseReleased(MouseEvent e){
  2.             obj[i] = new MyLine();
  3.             obj[i].add(x1,y1,x2,y2);
  4.             i+=1;
  5.                System.out.println(i+""+obj[0].getX1());
  6.  
  7.             repaint();
  8.         }
and then when i print the value of obj[0].getX1(), it seems like it is changed every time the mouse is released

here is the method of paint() that is called when i call the repaint() method
Expand|Select|Wrap|Line Numbers
  1. public void paint(Graphics g){
  2.  
  3.             for(int j=0 ; j<i ; j++){
  4.                 g.setColor(Color.red);
  5.                 g.drawLine(obj[j].getX1(),obj[j].getY1(),obj[j].getX2(),obj[j].getY2());
  6.             }
  7.  
  8.     }
it draws obj[0] each time with a different value and i don't know why
Jan 10 '15 #1
0 1048

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Kutty Banerjee | last post by:
Hi, MyClass *myclass_=new MyClass; and MyClass::MyClass(int) and no default constructor. My object assignment obviously gives an error. So waht is the correct way to do it without using vectors...
38
by: VK | last post by:
Hello, In my object I have getDirectory() method which returns 2-dimentional array (or an imitation of 2-dimentional array using two JavaScript objects with auto-handled length property - please...
2
by: Raphael Iloh | last post by:
Hi all, I'm having problems comparing array objects. Take a look at this: int array1 = new int{1}; int array2 = new int{1}; Console.Writeln(array1.Equals(array2)); One would expect the above...
10
by: Steve | last post by:
this code: private Array m_arrays = new Array; results in an array of 3 null Array objects. What am I missing?
21
by: yeti349 | last post by:
Hi, I'm using the following code to retrieve data from an xml file and populate a javascript array. The data is then displayed in html table form. I would like to then be able to sort by each...
1
by: plau011 | last post by:
Hi all, I thought I understood .Net Framework with value types and referencetypes but apparently not. So I have this code. Excuse me if it's not 100% correct I cut and paste and shortened it a...
2
by: JJA | last post by:
I'm looking at some code I do not understand: var icons = new Array(); icons = new GIcon(); icons.image = "somefilename.png"; I read this as an array of icons is being built. An element of...
4
Ispep
by: Ispep | last post by:
Hi, unfortunately having a bit of difficulty with a question from an Open University course I'm currently doing. If you could help me out in any way I'd be grafeul (though obviously it goes without...
13
by: milk242 | last post by:
I know I'm making a mistake, but I'm wondering if someone could tell me the type of mistake I'm making. I know I can write the whole array to a file, but I want to create separate binary files for...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.