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.
Code Java:
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():
Code Java:
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(:
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)