April 7, 2000

Determining the Top Level Frame

Question: I have developed a custom AWT component that can be placed at any level in a component hierarchy. How can it determine the top level Frame in the hierarchy? Answer: When using components derived from JComponent, it is possible to usegetTopLevelAncestor() to determine the topmost enclosing container inthe component

Enumerating Methods of a Class

Question: How can I enumerate the methods of an object? I know there must be away since JBuilder and other IDEs know how to populate a list ofmethods from a class. Answer: Java possesses a mechanism called reflection, which allows you todynamically discover things about classes. The Object class containsa

Select All Checkboxes

Question: I have several checkboxes and I want one checkbox tocause all of the checkboxes to be selected when it is selected. Howcan I do this? Answer: Even though the combined AWT and Swing packages provide an enormousbreadth of functionality, they do not cover every scenario you willrun into. The

JPasswordField

Question: How do I access the contents of a JPasswordField to see if it matcheswith the correct password? Answer: Before using a class, it helps to examine all of the documentation forits superclasses because certain pieces of functionality may beprovided in inherited methods, rather than ones defined only in thesubclass.

SystemCalls

Question: Is there any method (MFC, Win32) to get the contents of the systemvariable “PATH”? Answer: Sure there is. Use the standard function getenv() for this purpose: #include { char * descr = getenv(“PATH”);} After the getenv() call, the pointer descr will point to the string description of the environment

Mouse Click Coordinate

Question: I know how to detect a mouse click with a MouseListener, but how doI obtain the coordinates associated with the click? Answer: If you already know how to detect a mouse click, you’re just one stepaway from being able to retrieve the coordinates associated with theclick. To detect a

Database Field Types

Question: How do I get a string representation of a database field using JDBCregardless of its type? In other words, I have to use the getInt(),getDate(), getString(), etc., to get a field value depending on thefield type in the database. I just want the string representations soI can print them

RE: Date Arithmatic in Java

Question: I previously asked a question that may not have been worded as clearlyas possible and you answered something slightly different from what Iwas looking for. I want to know how to subtract one date from anotheras in the following pseudo-code: calender1.setTime(databasedate)calender2.setTime(todaysdate)differenceindays = calender2 – calender1 How can I determine

Enumeration Types

Question: Can you make an array of enumeration types?If so, how do you do it? Answer: Yes you can, and it is very simple: enum direction { Up, Down};direction arr[10]; // create arrayarr[0] = Down; // use array

No more posts to show