Wads a class Window/window argument?

Posted on 2004-11-11
Last Modified: 2010-03-31
Hi all,
I had came across in a java2 book which i am reading, which covers casting objects. However, I do not quite understand one of its examples.

For example, consider a method that takes two arguments, one of type objects and another of type window. You can pass an instance of any class for the object argument because all java classes are subclasses of object. for the window argument, you can pass in its subclasses, such as Dialog, FileDialog and Frame.

What exactly is a window and on what occations does casting of objects come into hand? Thanks.. =D
Question by:eturfclub
    LVL 86

    Accepted Solution

    >>What exactly is a window

    A Window (not the capital letter) is the base class for all components that represent a window on the platform on which Java is running

    >>on what occations does casting of objects come into hand?

    Your own quote gives a clue to this:

    >>for the window argument, you can pass in its subclasses, such as Dialog, FileDialog and Frame.

    so you could have a method such as the following:

    void handleWindow(Window w) {
          if (w instanceof Frame) {
                Frame f = (Frame)w;
                // do something with 'f'
          else if (w instanceof Dialog) {
                Dialog d = (Dialog)w;
                // do something with 'd'

    Note the casting
    LVL 86

    Expert Comment

    >>not the capital letter

    should be

    note the capital letter

    Author Comment

    meaning that the Window is only used for application which has an interface like MS word and etc instead of the DOS(console based) ?
    LVL 86

    Expert Comment


    Yes, a normal windowed gui, not a console

    Author Comment

    thanks.. =)

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    hash value 2 29
    Jave - Remove carriage return + special characters from text 3 52
    Fibonacci challenge 11 62
    strCopies  challenge 17 60
    Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
    The viewer will learn how to implement Singleton Design Pattern in Java.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now