Programming (Midterms)

Cards (35)

  • Java Swing is a part of Java Foundation Classes (JFC) that is used to create window-based applications. It is built on the top of Abstract Windowing Toolkit (AWT) API (Application Programming Interface) and entirely written in java.
  • JFC is a rich and comprehensive set of GUI components and services that simplify the development and deployment of desktop, client-side, and internet applications. It is a superset that contains AWT. JFC extends AWT by adding many components and services.
  • A key feature of the PLAF is that it enables developers to swap the Look and Feel of the UI which can be directly accessible. It was developed for application developers to provide a common interface
  • Sun Microsystems added a mechanism to the JFC is called Multiplexed UI. It is an extension to the PLAF (Pluggable Look & Feel).
  • Swing sits on a number of the APIs that implement the various parts of AWT, including Java2D, Drag-and-Drop, and the Accessibility API.
  • Java Swing
    Part of Java Foundation Classes (JFC) used to create window-based applications, built on top of AWT (Abstract Windowing Toolkit) API and entirely written in Java
  • Java Swing
    • Provides platform-independent and lightweight components
  • JFC (Java Foundation Classes)
    A rich and comprehensive set of GUI components and services that simplify the development and deployment of desktop, client-side, and internet applications
  • Difference between AWT and Swing
    • AWT components are platform-dependent, Swing components are platform-independent
    • AWT components are heavyweight, Swing components are lightweight
    • AWT doesn't support pluggable look and feel, Swing supports pluggable look and feel
    • AWT provides less components than Swing
    • AWT doesn't follow MVC (Model View Controller), Swing follows MVC
  • Creating a Frame in Swing
    1. By creating the object of Frame class (association)
    2. By extending Frame class (inheritance)
  • JButton
    Used to create a labeled button that has platform independent implementation, results in some action when the button is pushed, inherits the AbstractButton class
  • public void add(Component c)
    add a component on another component
  • public void setSize(int width, int height)
    set size of the component
  • public void setLayout(LayoutManager m)
    sets the layout manager for the component
  • public void setVisible(boolean b)
    sets the visibility of the component. It is by default false.
  • setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    causes the application to exit
  • setBounds(x, y, width, height);
    specify the position and size of a GUI
  • setSize(width, height);
    used to set only the size of the component, leaving its position unchanged.
  • setResizable(false);
    method that prevents the user from resizing the window manually by dragging its edges or corners
  • setLayout(null);
    control the positioning and sizing of components within a container
  • setLocationRelativeTo(null);
    method used to position a window or dialog at the center of the screen rather than at an absolute position on the screen
  • setVisible(true);
    used to make a window or component visible on the screen
  • The JButton class is used to create a labeled button that has platform independent implementation.
  • public class JButton extends AbstractButton implements Accessible
    declaration of javax.swing.JButton class
  • JButton()
    creates a button with no text and icon
  • JButton(String s)
    creates a button with the specific text
  • JButton(Icon i)
    creates a button with the specified icon object
  • setText(String s)
    set specified text on button
  • getText()
    return the text of the button
  • setEnabled(boolean b)
    enable or disable the button
  • setIcon(Icon b)
    set the specifies icon on the button
  • getIcon()
    get the icon of the button
  • setMnemonic(int a)
    set the mnemonic on the button
  • addActionListener(ActionListener a)
    add the action listener to this object
  • Some javax.swing package examples that provides classes for java swing API:
    • JButton()
    • JTextField()
    • JTextArea()
    • JRadioButton()
    • JCheckBox()
    • JMenu()
    • JColorChooser()
    • JFrame()
    • JOptionPanel()
    • JScrollBar()