View RSS Feed

All Blog Entries

  1. How to Write a Change Listener

    by , 04-26-2012 at 08:24 PM
    Property change listener and a change listener are similar. On an object, change listener gets register, typically at component. However, it may be some other object and when object is changed notification is sent to the listener. In case of change listener, notification of any sort of change is not sent to the listener but changing of the source object is notified. Hence, change listeners are considered as more useful only when it becomes necessary to be aware that when object gets changed. ...
    Categories
    Actions
  2. How to Write a Caret Listener

    by , 04-26-2012 at 08:23 PM
    In text component when selection gets changed or moved by the caret (i.e the cursor which show insertion point), caret events take place. Document of the text component may be initiating the caret event when text is inserted or removed. Caret listener may be attached to any subclass of the JTextComponent instance with method addCaretListener.
    Categories
    Actions
  3. How to Write an Action Listener

    by , 04-26-2012 at 08:22 PM
    Action Listeners are the most common and easiest event handlers for implementation. An action listener is implemented to detail that what could be possibly done when cetain operations are performed by user.

    When a user performs an action, an action event takes place. For example, when a button is clicked by a user, menu item is choosen and in text field ENTER is pressed. An actionPerformed message would be sent to all of the action listeners , which on a relevant component are registered. ...
    Categories
    Actions
  4. Sending a Description of an Action to a Status Bar

    by , 04-26-2012 at 08:22 PM
    Requested feature that is more common is that architecture which supports the content messages sending to status bar, when mouse is present at toolbar buttons or menu items. Support will be provided by the architecture of current action which behaves elegantly.
    When and addition of action is done to a container like JMenu or JToolBar, component which got added to container, is returned. MouseAdapter’s shared instance is added, to returned components. When at component the mouse is moved, ...
    Tags: status bar Add / Edit Tags
    Categories
    Actions
  5. Enabling and Disabling of Components Which Share an Action

    by , 04-26-2012 at 07:50 PM
    When “enabled”, the bound property of Action is enabled/disabled, property change event is sent to property change listeners. The AbstractButton consist of “inner-class property change listener” that disables/enables the correspondent component.

    In case of ActionDemo applications, actions get initialized in initActions() method. Similar Actions set is shared among popup menu, toolbar, menu and also are used for construction of the UI controls in createPopupMenu(),createToolBar() and ...
    Categories
    Actions
  6. Interface Action

    by , 04-26-2012 at 07:49 PM
    A useful extension is provided by the Action interface to the Action Listener interface where multiple controls may access similar functionality.
    ActionPerformed method that has been defined by the help of ActionListener interface, this interface would be allowing application to define:

    • One or more than one text strings that provide details regarding the function. Strings could be used for display of the button;s flyover text or setting up of the text, in menu item.
    • One
    ...
    Categories
    Actions
  7. How to Use Actions

    by , 04-26-2012 at 07:48 PM
    For separation of the state and functionality from component, an action is used. For instance, if there are 2 or more than 2 components which perform similar kind of functions, an Action object shall be considered for implementation of the function. An action object act as action listener which assist action event handling as well as centralized handling for component of action event firing state. For example, text fields, common buttons, menu items and tool bar buttons. The state which can be handled ...
    Categories
    Actions
  8. Designing a Swing GUI

    by , 04-26-2012 at 07:47 PM
    For simpler GUI designs, discussed above MVC widget internals could be ignored. Widget placement can be approached in GUI along with Swing similarly as AWT: by widget’s instantiation and their addition to the containers. In addition to this, MVC is used by two techniques for designing powerful and flexible GUIs.

    1. Simpler GUI Design: Widgets are instantiated and added to container. Then selection of Look & Feel is done for whole GUI.
    2. Complex GUI Design: Though Swing directly
    ...
  9. Component Architecture and MVC

    by , 04-26-2012 at 07:46 PM
    MVC’s common variation is used to present components by Swing where controller and view get combined to form an object known as delegate. Delegates present model and also translates the input of user into model, just like it is done by a controller. Communication that takes place b/w controller and view is found to be very complex. Two simplifies are combined, for the component design.

    For example, checkbox widget shall be considered. It consists of a state which could be true or ...
  10. Stateless vs. stateful delegates

    by , 04-26-2012 at 07:45 PM
    Methods which are present at ComponentUI use JComponent object, as a parameter. UI delegate’s stateless implementation is enabled by this convention. Implementation of stateless UI delegate permits one instance of UI delegate, to get used for component class’s instances. This would be reducing no. of objects that get instantiated.
    Suck kind of approach is for various simple GUI components. However, in case of more complexed components, it is not considered as “win” as inefficiency is created ...
  11. Distinguishing between UI-set and app-set properties

    by , 04-26-2012 at 07:44 PM
    Swing. Therefore this would be a critical thing to ensure that values don’t clobber when component’s default properties are set up by Look and Feel, for the component.
    This issue doesn’t arise when UI delegate first time is installed, at the component as properties are uninitialized and ultimately would be settled legally by Look&Feel. When individual properties are set after construction of component & subsequently new setup of Look and Feel takes place, such problem arises. Hence, ...
  12. The look-and-feel packages

    by , 04-26-2012 at 07:43 PM
    Swing.plaf, ScrollBarUI, ButtonUI etc which are present in UI delegates defines the accurate API which can be used by a component for interaction with instance of UI delegate. It shall be noted that originally interfaces were used here but got replaced by abstract classes as it was being felt that API was immature to with-stand interface’s concrete casting. Implementation of look and feel’s root is plaf APIs.

    Every implementation of look and feel gives abstract plaf classes’s concrete ...
  13. Managing look-and-feel data

    by , 04-26-2012 at 07:42 PM
    A static class known as UIManager.LookAndFeelInfo is defined by UIManager to store high leveled names, like Metal, and specified classname like "com.sun.java.swing.plaf.MetalLookAndFeel", for LookAndFeel.Internally these classes are used for management of the LookAndFeel objects which are known. UIManager could access this information through these given static methods:
    Java Code:
       public static LookAndFeelInfo[]
          getInstalledLookAndFeels()
    
       public static
    ...
  14. Dynamically Changing the Default Look-and-Feel

    by , 04-26-2012 at 07:41 PM
    When look and feel is being set programmatically by the Swing application as it has been discussed above, the ideal place considered is before instantiation of the Swing components. This happens as the particular LookAndFeel is made current default by UIManager.setLookAndFeel() method, by initializing or loading the LookAndFeel instance, however components are not automatically caused to make their look & feel changed.


    It shall be noticed that UI delegates are initialized ...
  15. The 'default' look and feel

    by , 04-26-2012 at 07:41 PM
    Methods are provided by UIManager to set or get the current, default Look & feel.
    Java Code:
       
    public static LookAndFeel 
          getLookAndFeel()
    
       public static void
          setLookAndFeel(LookAndFeel newLookAndFeel)
          
       public static void 
          setLookAndFeel(String className)
    Being default look & feel, cross platformed look and feel of Java which is called “Metal” is initialized by the Swing. But if default look ...
  16. Look-and-feel management

    by , 04-26-2012 at 07:40 PM
    An abstract look and feel class is defined by Swing which present all central information to the implementation of look and feel, like description, name, whether look and feel is native or not, a hash table to store default values for different attributes of look and feel, like fonts and colors.

    Every implementation of look and feel defines the LookAndFeel subclass. For instance, swing.plaf.motif.MotifLookAndFeel provides Swing along with important details for management of look & ...
  17. The component hooks

    by , 04-26-2012 at 07:39 PM
    Look and feel behavior of every swing component defines swing.plaf package’s abstract class for representation of UI delegate. These classes naming convention is taking class name for sake of component, append UI and remove prefix

    In constructor of component, UI delegate is made, of which access is given as “JavaBeans” bound property, at the component. For instance, following methods are provided by JScrollBar for access of UI delegate.

    Java Code:
       public ScrollBarUI
    ...
  18. Pluggable look-and-feel architecture

    by , 04-26-2012 at 07:38 PM
    Look and feel, plugable architecture of swing provides one component API, with no dictation of look and feel. A default look and feel set is provided by the swing toolkit. API is considered as “open”, a design which allows additionally developers to make new implementations of look and feel, either by extension of present look and feel or by creating a new one. Pluggable look and feel is although extensible but it was designed intentionally at that level lower than basic component API. This is done ...
  19. Model change notification

    by , 04-26-2012 at 07:37 PM
    Any interested parties shall be notified by the modes when value or data gets changed. JavaBeans Event model is used by the Swing models for notification implementation. Two approaches used in Swing for this notification:

    • A lightweighted notification shall be sent which has been changed by the state and listener is required to rsend back the query to model for determining what has changed. This approach has an advantage that one event instance might be used from a particular model
    ...
  20. Application-data models

    by , 04-26-2012 at 07:36 PM
    Application data models are those interfaces which represent certain data that is quantifiable and it has meaning in application’s context like a cell present in table or items that have been displayed in some list. Such data models give quite powerful paradigm of programming for the swing programs, which require clear separation b/w GUI and application logic/data. For Swing components which are truly data centric like JTable and JTree, interaction is strongly recommended with data model. Application ...
  21. GUI-state models

    by , 04-26-2012 at 07:36 PM
    GUI state models are considered as those interfaces that are involved in defining the GUI control’s visual status. Like a button is armed or pressed, or which items in a list shall be chosen. Typically, GUI state models are just relevant in GUI context. It is also useful for development of programs by using separation of GUI state mode, specially when multiple controls of GUI have been associated with one common state. Or, when one control’s manipulation will be changing the another’s value automatically. ...
    Categories
    Architecture
  22. Java Swing Roots in MVC

    by , 04-26-2012 at 07:35 PM
    In MVC i.e. Model view controller design, swing architecture has been rooted which dates back, to SmallTalk. MVC calls visual applications to be separately broken into 3 parts:
    • A Model- to present data, for application.
    • The view which is data’s the representation.
    • A controller – to take user input & translates them into changes present in model.

    MVC was considered as a logical choice earlier for Swing as bas was provided to meet up 1st three design goals, by staying ...
    Categories
    Architecture
  23. Java Swing Design Goals

    by , 04-26-2012 at 07:34 PM
    Swing project has following goal:

    To build a set of extensible GUI components to enable developers to more rapidly develop powerful Java front ends for commercial applications.

    Design goals were established by the Swing team earlier in project, which resulted into architecture. Guidelines are:
    1. In java, easy maintenance and class platform consistency could be promoted by being implemented.
    2. Single API shall be provided which is able to support various look
    ...
    Categories
    Architecture
  24. Java String comparison with the compareTo method

    by , 04-26-2012 at 07:02 PM
    Also a less common 3rd way for comparison of the Java Strings is present. That method is CompareTo method, with string class. In case of two similar Java Strings, this method will be returning a zero value. String Comparison approach shall look like this given example:

    Java Code:
    String string1 = "foo bar";
    String string2 = "foo bar";
    
    // java string compare example
    if (string1.compareTo(string2) == 0)
    {
      // this line WILL
    ...
    Categories
    Compare
  25. equalsIgnoreCase method

    by , 04-26-2012 at 07:01 PM
    It shall be ignore in Java string comparison tests that whether strings are uppercase of lowercase. Use EqualsIgnoreCase mthods for equality so that to test the strings .
    Java Code:
    String string1 = "foo";
    String string2 = "FOO";
    
    // java string compare while ignoring case
    if (string1.equalsIgnoreCase(string2))
    {
      // this line WILL print
      System.out.println("Ignoring case, the two strings are the same.")
    ...
    Categories
    Compare
  26. Java String comparison with the equals method

    by , 04-26-2012 at 07:00 PM
    About 95% of time, I prefer comparing strings by using Java String class’ equal methods. It is shown below:
    Java Code:
    if (string1.equals(string2))
    String equal method observes if exactly similar string of characters are present in Java strings, they would be considered as equal.
    Quick String comparison could be observed, with equal method, 2 strings wouldn’t be equal as same characters are not present.
    Java Code:
    String string1 = "foo";
    String string2
    ...
    Categories
    Compare
  27. Java String compare to determine Equality

    by , 04-26-2012 at 06:59 PM
    Comparison of the java string could be done in various ways, as given below. It is dependent upon javastringcompare type that which of them will be used.
    * == Operator
    * equals method
    * compareTo method
    Comparing, by using the “== Operator”
    When String object references are compared, ==operator is used. If 2 variables of String are pointed towards similar object present in memory, then comparison will be returned true. In other case it will return false. It shall ...
    Categories
    Compare
  28. Compare strings

    by , 04-26-2012 at 06:58 PM
    Two strings comparison will be learnt in this section. Java lang package gives methods for comparison of 2 with either lower or upper case. Facility is being provided by the equals() method to compare 2 strings. Equal() methods are used by the given program to help you for comparing 2 strings. In case when both of the strings present are equal then a message “Given strings equal” would be displayed. Otherwise, “given strings unequal” would be shown.
    Description of code:
    equals(): ...
    Categories
    Compare
  29. Convert String to Number

    by , 04-26-2012 at 06:57 PM
    This section shows how Number is converted into String. Functionaliy is provided by this program for conversion of String into Number,
    Code Description:
    In this program, String os Boolean, int, byte, double is being taken as it is given below. Also, MIN_VALUE and MIN_VALUE methods are used which are different wrapper classes so that all values on double, short and int could be printed.
    Here is the code used:
    Java Code:
    public class StrToNum{
      public static void main
    ...
  30. Convert Number to String

    by , 04-26-2012 at 06:56 PM
    This sections shows how numbers can be converted into String. Given program gives the functionality for conversion of numbers to String.

    Code Description:
    Different kind of numbers have been declared, for example, long, int and float etc given below. valueOf() method is used which is basically Stringclass’s method. For numeric conversions String.valueOf() is used & numeric classes are converted into String by using toString() method, as given below:
    Program’s code ...
Page 9 of 48 FirstFirst ... 789101119 ... LastLast