Creating Your Own Component
An advantage of OOP is the capability to reuse classes in different projects. For the next project, you create a special panel component that you can reuse in other Java programs. The component, ClockPanel
, displays the current date and time in a manner similar to the ClockTalk
project from Hour 7, “Using Conditional Tests to Make Decisions.”
The first step in creating your own user interface component is to decide the existing component from which to inherit. The ClockPanel
component is a subclass of JPanel
.
The ClockPanel
class is defined in Listing 13.3. This class represents panel components that include a label displaying the current date and time. Enter the text from Listing 13.3 into a new empty Java file and ...
Get Sams Teach Yourself Java™ in 24 Hours, Sixth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.