-4

i currently studying oop in java and i read in a book that java swing jframes are good to understand how oop works in creating gui's in a java program,so where are the following mostly implemeted. I have done some research and i found some oop concepts implemeting in java

Inheritance - obviously a class need to inherit javax.swing.jframe to use all the methods.

Encapsulation - after creating buttons,panels e.t.c all of them have private access modifiers

So where are

  • Association &Aggregation
  • Polymorphism
  • Abstraction & Interface

utilised?

user207421
  • 305,947
  • 44
  • 307
  • 483
Franco
  • 53
  • 1
  • 1
  • 6
  • 1
    This question is off topic because it's asking to recommend or find a OOP concepts. Things like these can be found with a [Google search](https://www.google.com.mx/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=java%20association) – Frakcool Dec 19 '15 at 16:42

1 Answers1

2
  1. Aggregation - JFrame has a JPanel

  2. Composition - JFrame has a JButton (composition because JButton cannot exist without a frame)

  3. Polymorphism - Sometimes parameters are passed to methods which are asking in more generic way for example someMethod(Component comp) for comp we can pass a JButton (Because JButton IS-A Component)

  4. Abstraction/Interface sometimes it is needed to implement interfaces and abstract classes, there you have to override all the abstract methods.

Lahiru Jayathilake
  • 601
  • 2
  • 10
  • 28
  • 1
    Not clear on 4th point which component is performing the action of abstraction, i understand interfaces are used by runnable() for creating forms but where is abstraction utilised in swing – Franco Dec 20 '15 at 09:39
  • @Franco To run GUI we normally use java.awt.EventQueue.invokeLater, there we have to pass a Runnable as the parameter . Runnable is an interface that you have to override the abstract run method – Lahiru Jayathilake Dec 21 '15 at 02:00