10.2.17
toolItem[]tool = new toolItem[10];
parent/abstract class (not same definition as obj. cant have obj. of it)
goal is to create multiple child classes
in abstract display can have nothing in it (I'm familiar with this such as
much like Alien and Marine are classes of Parent
Abstract
class labeled with the keyword abstract
can not itself be instantiated
has one or more methods that are labeled abstract and are headers only
acts as super class for many related classes each of which can use all the methods
of the abstract class
top of file has
public abstract class Shape (Shape is class so rename it accordingly)
Abstract is a generic shape class
public void (not empty)
publid void (not empty)
public void (not empy)
public draw ( empy, must be replaced by child )
child has public void draw( Graphics g, Container c )
{
}
the only one that the child has to implement in is the required one because
public class Spot extends Shape -- class defined as a subclass of the abstract shape
so the class spot wont need sets and gets because it parent has them.
if theres an abstract method in in the abstract class then the child class must use that abstract method
publilc class Fly extends Shape
public void draw (replace)
private Shape[] shaes = new Shape[2];
shapes[0] = new Fly();
shapes[1] = new Spot();
shapes[0].draw (fly class)
shapes[1].draw (spot class)
Polymorphism when two or more classes have mmethods of the same name. When the
BaseballPlayer is abstract class
*******PURPOS ((Parent empty so child has to replace)) E********** ((Child has purpose method))
-Position ((written on board))
-Name
-#
-Team
-bat %
-glove side
-batting side
keep the same instance variables (data members)
keep the same get and set methods
write the calcAverage and getAverage methods as abstract and static methods
write displayData method as abstract and static
PositionPlayers as a subclass of BaseballPlayer
Define class Picture as a subclass of BaseballPlayer
public abstract class BaseballPlayer
{
public static void calcAverage(); //static // creates no objects
public static void displayData(); //static //creates no objects
}
create an array of players
public class BaseballTeam
{
BaseballPlayer[] team = new BaseballPlayer[10];
int numPlayer = 0;
if(position == 'P') //.equals?
{
team[numPlayer] = new Pitcher(pass in data); //
numPlayer++;
}
else
{
team[numPlayer] = new PositionPlayer(pass in data);
numPlayer++;
}
//or switch if more than 2
}
Layout manager is a class that controls the positioning and sizing of window objects in a container
FlowLayout
BorderLayout
GridLayout
GridBagLayout
BoxLayout
Cardlayout
Container c = getContentPane();
c.setLayout(new FlowLayout()); - eventually BorderLayout
public class calcarea
{
private JPanel eastPanel, westPanel, centralPanel
setBorderLayout();
//better to set the panels by panels groued together
eastPanel = new JPanel();
//bkrnd color
JLabel promptLbl
eastPanel.add(promptLbl);
//then panel is added to container
c.add(eastPanel, BorderLayout.EAST);
westPanel = new JPanel();
~~
~~~
~~
westPanel.add(circleBtn);
c.add(westPanel, BorderLayout.WEST)
~~~~~~~~~~~~~~~
JOPtionPane.showMessageDialog(centerPanel, -- null is changed to say where
west center east
startX
startY
endX
endY
debug with system.print as usual
dont force abstract class
if i have easy way to do it then ...
---------------------------