This document provides an overview of Java Swing components for graphical user interfaces (GUIs). It introduces GUIs and discusses the advantages of Swing components over the older Abstract Window Toolkit (AWT) components. Key Swing components are explained, including JFrame for windows, JPanel for sections of a window, layout managers like FlowLayout and GridLayout, and common widgets like JLabel, JButton, JTextField, JTextArea, JComboBox, JCheckBox, JRadioButton, and JMenu. Event handling in Swing is also summarized.
Swing was introduced in 1997 as part of Java Foundation Classes to address deficiencies in Java's original Abstract Window Toolkit (AWT) GUI subsystem. Swing provides more powerful and flexible GUI components than AWT. Swing components are lightweight, meaning they are written entirely in Java rather than relying on platform-specific peers. This allows Swing to provide a consistent look and feel across platforms and makes the GUI more efficient and flexible. Swing also supports pluggable look and feels, allowing different visual styles to be used.
This document provides an overview of Swing components for creating graphical user interfaces in Java. It discusses top-level containers like JFrame and JDialog, general purpose containers like JPanel and JScrollPane, basic controls for user input like JTextField and JButton, components for displaying information like JLabel and JTable, and various layout managers including FlowLayout, BorderLayout, GridLayout, BoxLayout, and GridBagLayout. It also covers using borders with components and implementing listeners for text fields. The document is intended to teach what is needed to create full-featured GUIs with Swing.
Graphical User Interface (GUI) in Java uses classes from the javax.swing and java.awt packages to implement GUI programs. Swing classes provide greater compatibility across operating systems compared to AWT classes. Common Swing components include JButton, JLabel, JTextField, JTextArea, JCheckBox, JRadioButton, JComboBox, JList, JSlider and more. GUI programs require containers like JFrame and JPanel to hold components. Layout managers determine how components are arranged in containers. Common layouts include FlowLayout, BorderLayout and GridLayout. Menus are implemented using JMenuBar, JMenu and JMenuItem classes.
This document provides information about NetBeans IDE and GUI programming. It discusses the NetBeans interface including components like the menu bar, tool bar, GUI builder palette, inspector window, and code editor window. It also covers concepts like projects, forms, and components in NetBeans. Common controls like buttons, labels, text fields, checkboxes and their properties/methods are explained. Steps for designing an application like creating a project, adding a JFrame form and components are outlined. Examples for different controls like buttons, labels, text fields, radio buttons etc are also included.
The document discusses various GUI components in Java Swing and SWT toolkits. It describes Swing as the official Java GUI toolkit that is written entirely in Java and provides a rich set of widgets. It also discusses SWT as an alternative GUI library that is more lightweight but less powerful than Swing. Basic examples are provided for creating windows, adding buttons, menus, toolbars and other components in a Java Swing application.
The document discusses various Swing components in Java including JButton, JTextField, JTextArea, JRadioButton, JCheckbox, JComboBox and provides examples of how to use them. It explains that Swing provides platform-independent GUI components and covers commonly used Swing classes and methods for creating windows and adding interactive elements like buttons and text fields. Constructors and example code are provided for different Swing components.
Java Swing is a GUI toolkit that is used to create window-based applications. It is built on top of AWT and provides more powerful and lightweight components like tables, lists, scroll panes etc. Swing components are platform-independent and follow the MVC architecture. Common Swing components include JButton, JTextField, JTextArea and common layouts include FlowLayout, BorderLayout, GridLayout etc. Menus in Swing can support keyboard navigation using mnemonics and shortcuts using accelerators.
This document provides an overview of Java Swing components. It defines Swing as a GUI toolkit built on top of AWT that provides platform-independent and lightweight components. It describes common Swing components like JButton, JTextField, JTextArea and their usage. It also compares AWT and Swing, explaining how Swing components are more powerful and support pluggable look and feel while AWT is platform-dependent. Examples are given to demonstrate creating and using Swing components like JButton, JTextField, JTextArea etc.
Swing was introduced in 1997 as part of Java Foundation Classes to address deficiencies in Java's original Abstract Window Toolkit (AWT) GUI subsystem. Swing provides more powerful and flexible GUI components than AWT. Swing components are lightweight, meaning they are written entirely in Java rather than relying on platform-specific peers. This allows Swing to provide a consistent look and feel across platforms and makes the GUI more efficient and flexible. Swing also supports pluggable look and feels, allowing different visual styles to be used.
This document provides an overview of Swing components for creating graphical user interfaces in Java. It discusses top-level containers like JFrame and JDialog, general purpose containers like JPanel and JScrollPane, basic controls for user input like JTextField and JButton, components for displaying information like JLabel and JTable, and various layout managers including FlowLayout, BorderLayout, GridLayout, BoxLayout, and GridBagLayout. It also covers using borders with components and implementing listeners for text fields. The document is intended to teach what is needed to create full-featured GUIs with Swing.
Graphical User Interface (GUI) in Java uses classes from the javax.swing and java.awt packages to implement GUI programs. Swing classes provide greater compatibility across operating systems compared to AWT classes. Common Swing components include JButton, JLabel, JTextField, JTextArea, JCheckBox, JRadioButton, JComboBox, JList, JSlider and more. GUI programs require containers like JFrame and JPanel to hold components. Layout managers determine how components are arranged in containers. Common layouts include FlowLayout, BorderLayout and GridLayout. Menus are implemented using JMenuBar, JMenu and JMenuItem classes.
This document provides information about NetBeans IDE and GUI programming. It discusses the NetBeans interface including components like the menu bar, tool bar, GUI builder palette, inspector window, and code editor window. It also covers concepts like projects, forms, and components in NetBeans. Common controls like buttons, labels, text fields, checkboxes and their properties/methods are explained. Steps for designing an application like creating a project, adding a JFrame form and components are outlined. Examples for different controls like buttons, labels, text fields, radio buttons etc are also included.
The document discusses various GUI components in Java Swing and SWT toolkits. It describes Swing as the official Java GUI toolkit that is written entirely in Java and provides a rich set of widgets. It also discusses SWT as an alternative GUI library that is more lightweight but less powerful than Swing. Basic examples are provided for creating windows, adding buttons, menus, toolbars and other components in a Java Swing application.
The document discusses various Swing components in Java including JButton, JTextField, JTextArea, JRadioButton, JCheckbox, JComboBox and provides examples of how to use them. It explains that Swing provides platform-independent GUI components and covers commonly used Swing classes and methods for creating windows and adding interactive elements like buttons and text fields. Constructors and example code are provided for different Swing components.
Java Swing is a GUI toolkit that is used to create window-based applications. It is built on top of AWT and provides more powerful and lightweight components like tables, lists, scroll panes etc. Swing components are platform-independent and follow the MVC architecture. Common Swing components include JButton, JTextField, JTextArea and common layouts include FlowLayout, BorderLayout, GridLayout etc. Menus in Swing can support keyboard navigation using mnemonics and shortcuts using accelerators.
This document provides an overview of Java Swing components. It defines Swing as a GUI toolkit built on top of AWT that provides platform-independent and lightweight components. It describes common Swing components like JButton, JTextField, JTextArea and their usage. It also compares AWT and Swing, explaining how Swing components are more powerful and support pluggable look and feel while AWT is platform-dependent. Examples are given to demonstrate creating and using Swing components like JButton, JTextField, JTextArea etc.
The document discusses graphical user interface (GUI) components in Java. It covers topics like basic GUI units like frames and panels, common Swing components like JFrame, JButton, JTextField, layout managers, event handling using listeners, and examples of creating simple GUI applications in Java. Key concepts explained include the component hierarchy in Swing, commonly used layouts like FlowLayout, BorderLayout and GridLayout, and how to add listeners for events like button clicks and window closing. Code samples are provided to demonstrate creating frames, adding components, setting layouts and handling events.
The document discusses Swing, the graphical user interface (GUI) toolkit for Java. It introduces Swing as a replacement for the original Abstract Window Toolkit (AWT) that improved on AWT's weaknesses. Key points covered include:
- Swing was introduced in 1997 as part of the Java Foundation Classes to address AWT's limitations. It uses lightweight components instead of relying on native platform components.
- Swing supports pluggable look-and-feel and is based on the model-view-controller architecture. It includes a variety of common GUI components like tables, trees, sliders.
- Layout managers like FlowLayout, GridLayout, BorderLayout, and BoxLayout are used to position and
This document discusses the evolution of graphical user interface (GUI) capabilities in the Java programming language. It describes the Abstract Window Toolkit (AWT) introduced in JDK 1.0, which provided basic cross-platform GUI functionality but had limitations. JDK 1.1 improved on AWT with an event delegation model. JDK 1.2 introduced Swing, a richer GUI library that better integrated with native operating system look and feels. Swing components are lightweight compared to heavyweight AWT components. The document also covers GUI component classes, layout managers, menus, labels and event handling in Java GUI programming.
This document provides an introduction to graphical user interfaces (GUIs) in Java. It discusses GUI components such as buttons, checkboxes, lists, sliders, and menus. It explains how to create simple GUIs using Swing components like JFrames, JLabels, and JButtons. Event handling is demonstrated through examples using interfaces like ItemListener. Different types of buttons are presented, including toggle buttons, radio buttons, and checkboxes. Common GUI elements like text fields, lists, sliders and menus are also introduced through examples. The document provides a high-level overview of creating and working with basic GUI components in Java.
The document discusses various Swing components in Java including labels, buttons, text fields, checkboxes, radio buttons, scroll panes, tabbed panes, and combo boxes. It provides the classes, constructors, and methods used to implement each component as well as examples of code to create and add the components to an applet container.
Java Swing provides graphical user interface (GUI) components for building desktop applications. It includes common widgets like buttons, text fields, labels and dialog boxes. JOptionPane allows building simple dialog boxes for input/output. Swing components are lightweight and platform-independent compared to the older AWT components. Common Swing components discussed include JFrame for windows, JButton for buttons, JLabel for text, JFileChooser for file selection and JCheckBox, JRadioButton for state buttons.
This document discusses Java Database Connectivity (JDBC) which is an API used to connect Java applications to databases. It describes the different types of JDBC drivers including bridge, native, network protocol, and thin drivers. It also outlines the basic steps to connect to a database using JDBC including registering the driver, getting a connection, creating statements, executing queries, and closing the connection. Key interfaces like Connection, Statement, PreparedStatement, and ResultSet are also summarized.
Swing and Graphical User Interface in Javababak danyal
The document provides information about the Swing graphical user interface library in Java. It describes that Swing is the official GUI toolkit for Java, released as part of Java Foundation Classes. It discusses the key components, layout managers like BorderLayout and GridLayout, and event handling in Swing using interfaces, anonymous inner classes, and adapter classes.
This document discusses Java Swing and event handling in Java. It introduces Java Swing as a GUI toolkit used to create window-based applications. It describes some common Swing components like JLabel, JTextField, JRadioButton, JComboBox, JTextArea, and JButton. It also discusses different event listeners in Java Swing - ActionListener, which is notified when a button is clicked, MouseListener, which is notified on mouse events, and MouseMotionListener, which is notified when the mouse is moved or dragged.
This document provides an overview of Java Swing through a series of slides. It introduces Swing as a GUI toolkit for Java that includes 14 packages and over 450 classes. It discusses how Swing components are lightweight and not thread-safe. The document covers key Swing concepts like layout managers, event handling with listeners, look and feels, common containers like JPanel and JSplitPane, controls like JButton and JTextField, and components like images, scroll bars, check boxes and radio buttons. Code examples are provided for many of the concepts discussed.
This document discusses Java's GUI components and how to create basic buttons and labels. It provides details on:
- Java's GUI components include labels, text fields, buttons, and containers like frames and panels
- Buttons can be created and added to frames or panels, and listeners can be assigned to detect button clicks
- Labels are used to display text, text fields allow for single-line text input, and text areas are for multi-line text
GUI Programming in JAVA (Using Netbeans) - A ReviewFernando Torres
The powerpoint provides the user with a review of various concepts of GUI programming in JAVA. It covers various concepts like :
1. What is IDE ?
2. Various Methods and Properties of Components
3. Variable declaration
4. Data types
Etc
The document provides an overview of how to build a graphical user interface (GUI) in Java. It discusses the key classes used to create GUI components like JFrame, JPanel, and JButton. It explains how to set layout managers, add components, set frame size and visibility. It also includes sample code to create a simple calculator GUI with a border layout and grid layout. The document is an introduction to developing GUIs in Java using the Swing toolkit.
This document provides an overview of the Abstract Windowing Toolkit (AWT) and Swing GUI frameworks in Java. It discusses the similarities and differences between AWT and Swing, the fundamental AWT components like frames and panels, graphics drawing, additional AWT components, common layout managers, and how to set up top-level containers and examples using Swing components like JFrames and JOptionPanes. The key topics covered include the fundamentals of building graphical user interfaces in Java.
This document provides an overview of AWT and Swing. It discusses how AWT provides cross-platform functionality through abstract classes and platform-specific peer classes. It also summarizes the evolution of Swing from early versions of AWT that had limitations. Key points covered include:
- AWT uses abstract classes and peer classes to provide cross-platform functionality, with peers implementing platform-specific behavior.
- Early versions of AWT had limitations like a limited number of fonts and inability to access native OS GUI. Swing addressed these.
- Swing provides a richer class library and better integration with native OS look and feel.
- Layout managers, events/listeners, and adapter classes are discussed
The document discusses Java Swing and GUI components in Java. It compares AWT and Swing, introduces common Swing components like JButton and JPanel, and shows how to layout components using layout managers. It also discusses how to create simple applications and applets using Swing components.
Swing is a GUI widget toolkit for Java. It is part of Oracle's Java Foundation Classes (JFC) – an API for providing a graphical user interface (GUI) for Java programs.
The document discusses Java Foundation Classes (JFC) which provide components for building graphical user interfaces in Java. JFC includes Swing components like buttons and menus, pluggable look and feel, accessibility APIs, and drag and drop support. Swing provides standard GUI components and containers to organize components in windows. Top-level containers like JFrame are needed to display components on screen and provide support for painting and events.
Swing is a GUI widget toolkit for Java that is used to build window-based applications. It is built on top of the Abstract Window Toolkit (AWT) and provides a more sophisticated set of GUI components than AWT. Swing components are lightweight since they are written entirely in Java without dependencies on platform-specific implementations. It also supports pluggable look and feels so that applications can have different styles without recompilation.
The document provides an overview of how to build a graphical user interface (GUI) in Java. It discusses the key classes used to create GUI components like JFrame, JPanel, and JButton. It explains how to set layout managers, add components, set frame size and visibility. It also includes sample code to create a simple calculator GUI with a border layout and grid layout. The document is an introduction to developing GUIs in Java using the Swing toolkit.
The document discusses graphical user interface (GUI) components in Java. It covers topics like basic GUI units like frames and panels, common Swing components like JFrame, JButton, JTextField, layout managers, event handling using listeners, and examples of creating simple GUI applications in Java. Key concepts explained include the component hierarchy in Swing, commonly used layouts like FlowLayout, BorderLayout and GridLayout, and how to add listeners for events like button clicks and window closing. Code samples are provided to demonstrate creating frames, adding components, setting layouts and handling events.
The document discusses Swing, the graphical user interface (GUI) toolkit for Java. It introduces Swing as a replacement for the original Abstract Window Toolkit (AWT) that improved on AWT's weaknesses. Key points covered include:
- Swing was introduced in 1997 as part of the Java Foundation Classes to address AWT's limitations. It uses lightweight components instead of relying on native platform components.
- Swing supports pluggable look-and-feel and is based on the model-view-controller architecture. It includes a variety of common GUI components like tables, trees, sliders.
- Layout managers like FlowLayout, GridLayout, BorderLayout, and BoxLayout are used to position and
This document discusses the evolution of graphical user interface (GUI) capabilities in the Java programming language. It describes the Abstract Window Toolkit (AWT) introduced in JDK 1.0, which provided basic cross-platform GUI functionality but had limitations. JDK 1.1 improved on AWT with an event delegation model. JDK 1.2 introduced Swing, a richer GUI library that better integrated with native operating system look and feels. Swing components are lightweight compared to heavyweight AWT components. The document also covers GUI component classes, layout managers, menus, labels and event handling in Java GUI programming.
This document provides an introduction to graphical user interfaces (GUIs) in Java. It discusses GUI components such as buttons, checkboxes, lists, sliders, and menus. It explains how to create simple GUIs using Swing components like JFrames, JLabels, and JButtons. Event handling is demonstrated through examples using interfaces like ItemListener. Different types of buttons are presented, including toggle buttons, radio buttons, and checkboxes. Common GUI elements like text fields, lists, sliders and menus are also introduced through examples. The document provides a high-level overview of creating and working with basic GUI components in Java.
The document discusses various Swing components in Java including labels, buttons, text fields, checkboxes, radio buttons, scroll panes, tabbed panes, and combo boxes. It provides the classes, constructors, and methods used to implement each component as well as examples of code to create and add the components to an applet container.
Java Swing provides graphical user interface (GUI) components for building desktop applications. It includes common widgets like buttons, text fields, labels and dialog boxes. JOptionPane allows building simple dialog boxes for input/output. Swing components are lightweight and platform-independent compared to the older AWT components. Common Swing components discussed include JFrame for windows, JButton for buttons, JLabel for text, JFileChooser for file selection and JCheckBox, JRadioButton for state buttons.
This document discusses Java Database Connectivity (JDBC) which is an API used to connect Java applications to databases. It describes the different types of JDBC drivers including bridge, native, network protocol, and thin drivers. It also outlines the basic steps to connect to a database using JDBC including registering the driver, getting a connection, creating statements, executing queries, and closing the connection. Key interfaces like Connection, Statement, PreparedStatement, and ResultSet are also summarized.
Swing and Graphical User Interface in Javababak danyal
The document provides information about the Swing graphical user interface library in Java. It describes that Swing is the official GUI toolkit for Java, released as part of Java Foundation Classes. It discusses the key components, layout managers like BorderLayout and GridLayout, and event handling in Swing using interfaces, anonymous inner classes, and adapter classes.
This document discusses Java Swing and event handling in Java. It introduces Java Swing as a GUI toolkit used to create window-based applications. It describes some common Swing components like JLabel, JTextField, JRadioButton, JComboBox, JTextArea, and JButton. It also discusses different event listeners in Java Swing - ActionListener, which is notified when a button is clicked, MouseListener, which is notified on mouse events, and MouseMotionListener, which is notified when the mouse is moved or dragged.
This document provides an overview of Java Swing through a series of slides. It introduces Swing as a GUI toolkit for Java that includes 14 packages and over 450 classes. It discusses how Swing components are lightweight and not thread-safe. The document covers key Swing concepts like layout managers, event handling with listeners, look and feels, common containers like JPanel and JSplitPane, controls like JButton and JTextField, and components like images, scroll bars, check boxes and radio buttons. Code examples are provided for many of the concepts discussed.
This document discusses Java's GUI components and how to create basic buttons and labels. It provides details on:
- Java's GUI components include labels, text fields, buttons, and containers like frames and panels
- Buttons can be created and added to frames or panels, and listeners can be assigned to detect button clicks
- Labels are used to display text, text fields allow for single-line text input, and text areas are for multi-line text
GUI Programming in JAVA (Using Netbeans) - A ReviewFernando Torres
The powerpoint provides the user with a review of various concepts of GUI programming in JAVA. It covers various concepts like :
1. What is IDE ?
2. Various Methods and Properties of Components
3. Variable declaration
4. Data types
Etc
The document provides an overview of how to build a graphical user interface (GUI) in Java. It discusses the key classes used to create GUI components like JFrame, JPanel, and JButton. It explains how to set layout managers, add components, set frame size and visibility. It also includes sample code to create a simple calculator GUI with a border layout and grid layout. The document is an introduction to developing GUIs in Java using the Swing toolkit.
This document provides an overview of the Abstract Windowing Toolkit (AWT) and Swing GUI frameworks in Java. It discusses the similarities and differences between AWT and Swing, the fundamental AWT components like frames and panels, graphics drawing, additional AWT components, common layout managers, and how to set up top-level containers and examples using Swing components like JFrames and JOptionPanes. The key topics covered include the fundamentals of building graphical user interfaces in Java.
This document provides an overview of AWT and Swing. It discusses how AWT provides cross-platform functionality through abstract classes and platform-specific peer classes. It also summarizes the evolution of Swing from early versions of AWT that had limitations. Key points covered include:
- AWT uses abstract classes and peer classes to provide cross-platform functionality, with peers implementing platform-specific behavior.
- Early versions of AWT had limitations like a limited number of fonts and inability to access native OS GUI. Swing addressed these.
- Swing provides a richer class library and better integration with native OS look and feel.
- Layout managers, events/listeners, and adapter classes are discussed
The document discusses Java Swing and GUI components in Java. It compares AWT and Swing, introduces common Swing components like JButton and JPanel, and shows how to layout components using layout managers. It also discusses how to create simple applications and applets using Swing components.
Swing is a GUI widget toolkit for Java. It is part of Oracle's Java Foundation Classes (JFC) – an API for providing a graphical user interface (GUI) for Java programs.
The document discusses Java Foundation Classes (JFC) which provide components for building graphical user interfaces in Java. JFC includes Swing components like buttons and menus, pluggable look and feel, accessibility APIs, and drag and drop support. Swing provides standard GUI components and containers to organize components in windows. Top-level containers like JFrame are needed to display components on screen and provide support for painting and events.
Swing is a GUI widget toolkit for Java that is used to build window-based applications. It is built on top of the Abstract Window Toolkit (AWT) and provides a more sophisticated set of GUI components than AWT. Swing components are lightweight since they are written entirely in Java without dependencies on platform-specific implementations. It also supports pluggable look and feels so that applications can have different styles without recompilation.
The document provides an overview of how to build a graphical user interface (GUI) in Java. It discusses the key classes used to create GUI components like JFrame, JPanel, and JButton. It explains how to set layout managers, add components, set frame size and visibility. It also includes sample code to create a simple calculator GUI with a border layout and grid layout. The document is an introduction to developing GUIs in Java using the Swing toolkit.
SWING USING JAVA WITH VARIOUS COMPONENTSbharathiv53
This presentation contains the following topics.,
Introduction to Swing; MVC; Events and Listeners; Adapters; Text
Components; Look and feel; Swing Components; JTextField, JLabel,
JButton, JScrollBar, JSlider, JProgressBar, JList, JComboBox; Containers
and Frames; Layout Managers; Menus and Toolbar; Tables and Trees.
The document discusses Java AWT and Swing GUI programming. It provides details on commonly used AWT and Swing components like Frame, Button, Label, Textfield. It explains the hierarchy and differences between AWT and Swing. Examples are provided to demonstrate creating a simple GUI using various components like Buttons, Labels and adding them to a Frame. The document also covers other Swing components like Checkboxes, Scrollpanes and containers like Frame, Dialog, Panel.
The document provides information about Swing components in Java. It discusses JApplet, JFrame, JPanel, JWindow, JLabel, JTextField, JButton, JCheckBox, JRadioButton, JComboBox, JTabbedPane, and JScrollPane. Key differences between Swing and AWT components are that Swing components are lightweight and platform independent while AWT components are heavyweight and platform dependent. The document also provides code examples to demonstrate the use of several Swing components.
The document provides information about Swing components in Java. It discusses JApplet, JFrame, JPanel, JWindow, JLabel, JTextField, JButton, JCheckBox, JRadioButton, JComboBox, JTabbedPane, and JScrollPane. Key differences between Swing and AWT components are that Swing components are lightweight and platform independent while AWT components are heavyweight and platform dependent. The document also provides code examples to demonstrate the use of several Swing components.
The document discusses Java GUI components from the Abstract Window Toolkit (AWT) and Swing toolkit. It defines AWT as a set of APIs used to create GUI objects like buttons and windows. It describes common AWT containers like Frame, Panel, Dialog and Applet. It then introduces Swing as an enhanced GUI toolkit and lists some common Swing components in packages like javax.swing. The document provides examples of creating and using common Swing components like JFrame, JLabel, JButton, JCheckBox.
The document discusses Java GUI components from the Abstract Window Toolkit (AWT) and Swing toolkit. It defines AWT as a set of APIs used to create GUI objects like buttons and windows. It describes common AWT containers like Frame, Panel, Dialog and Applet. It then introduces Swing as an enhanced GUI toolkit and lists some common Swing components in packages like javax.swing. The document provides examples of creating and using common Swing components like JFrame, JLabel, JButton, JCheckBox.
This document provides an overview of Swing components in Java. It describes common Swing components like labels, text fields, buttons, checkboxes, radio buttons and introduces more advanced components like tabbed panes, scroll panes, trees and tables. It explains key features of Swing like platform independence, pluggable look and feel, tooltips and scrolling. Code examples are provided to demonstrate creating and using basic Swing components like labels, text fields and buttons in a Java applet.
The document provides an introduction and overview of Swing components in Java. It discusses key Swing classes like JApplet, JLabel, JTextField, JButton, JCheckBox, JRadioButton, JComboBox, and JTabbedPane. It explains their functionality, important methods, and gives examples of how to use each component in an applet. The document also compares Swing to the older AWT toolkit and outlines the MVC architecture used in Swing.
The document provides information on Java AWT and JavaFX. It discusses key Java AWT components like Label, TextField, Button, TextArea, Checkbox, List, Canvas, Menu, Popup Menu, Panel, and Dialog. It also covers Java AWT layouts and listeners. For JavaFX, it describes the package, stage, scene, application class lifecycle, and common controls like Label, Button, and ComboBox. It concludes with an overview of event handling in JavaFX.
Java Swing is a GUI widget toolkit for Java that builds upon the Abstract Window Toolkit (AWT) to provide a more sophisticated set of GUI components. It includes common widgets like buttons, text fields, labels and menus. Components in Swing are lightweight objects that can be easily rendered on screen. Containers hold and organize other components in a hierarchy. The most commonly used containers are JFrame, JPanel and JWindow. JFrame is Swing's version of a top-level window with options to close or hide. JTextField allows editing single-line text while JLabel displays read-only text. An example program demonstrates adding components like labels, text fields and buttons to a JFrame and handling button click events
java presentation on Swings chapter java presentation on SwingsMohanYedatkar
This document discusses Swing components in Java. It begins with an introduction to Swing and its advantages over AWT. It then describes several important Swing components - JFrame for windows, JApplet for applets, JLabel for text labels, JTextField for single-line text entry, JTextArea for multi-line text. It also covers icons, text fields, buttons, and the model-view-controller architecture in Swing. Examples are provided for creating basic interfaces with these components.
Java Swing is an extension of AWT that provides a more robust and platform-independent set of widgets for building GUIs in Java. It is written entirely in Java and provides improved functionality over AWT, including new components, expanded component features, drag and drop support, and better event handling. Swing components are rendered the same on all platforms, unlike AWT which is platform-dependent.
This document discusses event-driven programming and graphical user interfaces (GUIs) using Swing/AWT in Java. It provides an overview of key GUI concepts like components, containers, layout managers, and events. It explains how to create basic GUI elements like frames and buttons. It also demonstrates how to write an event listener as a nested class to handle button click events and update the GUI in response.
- Java Swing is a GUI widget toolkit for Java that is used to build window-based applications. It is built on top of AWT and provides platform-independent and lightweight components.
- The javax.swing package provides common GUI components like buttons, text fields, lists, menus etc.
- Swing components follow the MVC pattern and support pluggable look and feel while AWT does not.
Swing is a GUI widget toolkit for Java that improves upon the AWT. It includes powerful and flexible components like JFrame, JPanel, buttons, labels and other widgets. Components in Swing are lightweight and inherit from the JComponent class. Swing uses layout managers to organize components and also includes dialog boxes for user input and messages. The document provides examples of creating simple Swing applications with labels, buttons, and drawing to the screen.
This document provides an overview of GUI programming in Java, including basic concepts, AWT vs Swing frameworks, common control components, layout managers, and event handling. It discusses the key differences between AWT and Swing, describes common control components in both frameworks, explains different types of layout managers like flow, border, and grid layouts, and lists additional references for further reading.
This document provides an overview of Java Swing components and how to use them to build graphical user interfaces. It defines Swing as a GUI toolkit built on top of AWT that provides platform-independent and lightweight components. It describes common Swing components like JButton, JTextField, JTextArea and how to use them. It also explains how to change the title bar icon and provides examples of Swing apps like an online exam, IP finder and calculator.
1) This document introduces graphical user interfaces (GUIs) and Java support for building GUIs. It discusses components, containers, layout managers, and events that make up GUIs.
2) It provides examples of creating windows and adding basic components in Swing and SWT. Layout managers like FlowLayout, BorderLayout, and GridLayout are demonstrated.
3) The document compares AWT, Swing, and SWT GUI toolkits and explains that Swing builds upon AWT to provide more functionality and platform-independent look and feel. Code examples illustrate key concepts of building Java GUIs.
Similar to Z blue introduction to gui (39023299) (20)
This document defines various terms related to AICTE guidelines, including definitions for council, course, programme, level, division, approved intake, total approved intake, supernumerary seats, foreign national, lateral entry, and more. It also outlines various supernumerary seat percentages for things like TFW, PMSSS, FN/OCI/PIO/Gulf, EWS, PwD, and NRI. Finally, it discusses requirements for expert committee visits to evaluate readiness of instructional, administrative, amenities and computer/lab facilities.
This document discusses input/output (I/O) streams in Java. It describes byte streams and character streams for reading and writing files, as well as standard input, output, and error streams. It also covers object serialization and deserialization, which allows objects to be written to and read from files by converting them to and from byte streams. Examples are provided for copying files, reading console input, and serializing/deserializing an Employee object to a file.
This document discusses exceptions in programming. It defines an exception as an event that disrupts normal program flow, and explains that when an exception occurs the runtime system searches the call stack for an exception handler to catch the exception. There are two types of exceptions - checked exceptions which are checked at compile time, and unchecked exceptions which are checked at runtime. Examples of each type are given. Common scenarios where unchecked exceptions like NullPointerException, NumberFormatException, and ArrayIndexOutOfBoundsException can occur are also described.
The document discusses interfaces and packages in Java. It states that interfaces are Java's way of allowing multiple inheritance by allowing a class to implement multiple interfaces. An interface defines a contract that implementing classes must follow by providing method signatures but no implementation. Packages are used to organize classes into namespaces and correspond to directories on the file system. The document provides examples of interface and package syntax and usage.
Exceptions represent errors that occur during program execution. The try-catch block allows exceptions to be handled gracefully. A try block contains code that might throw exceptions, while catch blocks specify how to handle specific exception types if they occur. Checked exceptions must either be caught or specified in a method's throws clause, as they represent conditions outside the programmer's control. Unchecked exceptions like NullPointerException indicate programming errors and do not require catching or specifying.
Inheritance allows subclasses to inherit and extend the functionality of parent classes. The example code shows inheritance being used to create subclasses for different employee types (Engineer, Manager, SalesManager) that inherit from a base Employee class. The subclasses override the printData() method to print employee-specific pay details while reusing common functionality like name printing from the parent class. This avoids duplicating code and allows adding new functionality through inheritance.
This document discusses exceptions in programming. It defines an exception as an event that disrupts normal program flow, and explains that when an exception occurs the runtime system searches the call stack for an exception handler to catch the exception. There are two types of exceptions - checked exceptions which are checked at compile time, and unchecked exceptions which are checked at runtime. Examples of each type are given. Common scenarios where unchecked exceptions like NullPointerException, NumberFormatException, and ArrayIndexOutOfBoundsException can occur are also described.
Applications of artificial Intelligence in Mechanical Engineering.pdfAtif Razi
Historically, mechanical engineering has relied heavily on human expertise and empirical methods to solve complex problems. With the introduction of computer-aided design (CAD) and finite element analysis (FEA), the field took its first steps towards digitization. These tools allowed engineers to simulate and analyze mechanical systems with greater accuracy and efficiency. However, the sheer volume of data generated by modern engineering systems and the increasing complexity of these systems have necessitated more advanced analytical tools, paving the way for AI.
AI offers the capability to process vast amounts of data, identify patterns, and make predictions with a level of speed and accuracy unattainable by traditional methods. This has profound implications for mechanical engineering, enabling more efficient design processes, predictive maintenance strategies, and optimized manufacturing operations. AI-driven tools can learn from historical data, adapt to new information, and continuously improve their performance, making them invaluable in tackling the multifaceted challenges of modern mechanical engineering.
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...IJECEIAES
Medical image analysis has witnessed significant advancements with deep learning techniques. In the domain of brain tumor segmentation, the ability to
precisely delineate tumor boundaries from magnetic resonance imaging (MRI)
scans holds profound implications for diagnosis. This study presents an ensemble convolutional neural network (CNN) with transfer learning, integrating
the state-of-the-art Deeplabv3+ architecture with the ResNet18 backbone. The
model is rigorously trained and evaluated, exhibiting remarkable performance
metrics, including an impressive global accuracy of 99.286%, a high-class accuracy of 82.191%, a mean intersection over union (IoU) of 79.900%, a weighted
IoU of 98.620%, and a Boundary F1 (BF) score of 83.303%. Notably, a detailed comparative analysis with existing methods showcases the superiority of
our proposed model. These findings underscore the model’s competence in precise brain tumor localization, underscoring its potential to revolutionize medical
image analysis and enhance healthcare outcomes. This research paves the way
for future exploration and optimization of advanced CNN models in medical
imaging, emphasizing addressing false positives and resource efficiency.
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...IJECEIAES
Climate change's impact on the planet forced the United Nations and governments to promote green energies and electric transportation. The deployments of photovoltaic (PV) and electric vehicle (EV) systems gained stronger momentum due to their numerous advantages over fossil fuel types. The advantages go beyond sustainability to reach financial support and stability. The work in this paper introduces the hybrid system between PV and EV to support industrial and commercial plants. This paper covers the theoretical framework of the proposed hybrid system including the required equation to complete the cost analysis when PV and EV are present. In addition, the proposed design diagram which sets the priorities and requirements of the system is presented. The proposed approach allows setup to advance their power stability, especially during power outages. The presented information supports researchers and plant owners to complete the necessary analysis while promoting the deployment of clean energy. The result of a case study that represents a dairy milk farmer supports the theoretical works and highlights its advanced benefits to existing plants. The short return on investment of the proposed approach supports the paper's novelty approach for the sustainable electrical system. In addition, the proposed system allows for an isolated power setup without the need for a transmission line which enhances the safety of the electrical network
Comparative analysis between traditional aquaponics and reconstructed aquapon...bijceesjournal
The aquaponic system of planting is a method that does not require soil usage. It is a method that only needs water, fish, lava rocks (a substitute for soil), and plants. Aquaponic systems are sustainable and environmentally friendly. Its use not only helps to plant in small spaces but also helps reduce artificial chemical use and minimizes excess water use, as aquaponics consumes 90% less water than soil-based gardening. The study applied a descriptive and experimental design to assess and compare conventional and reconstructed aquaponic methods for reproducing tomatoes. The researchers created an observation checklist to determine the significant factors of the study. The study aims to determine the significant difference between traditional aquaponics and reconstructed aquaponics systems propagating tomatoes in terms of height, weight, girth, and number of fruits. The reconstructed aquaponics system’s higher growth yield results in a much more nourished crop than the traditional aquaponics system. It is superior in its number of fruits, height, weight, and girth measurement. Moreover, the reconstructed aquaponics system is proven to eliminate all the hindrances present in the traditional aquaponics system, which are overcrowding of fish, algae growth, pest problems, contaminated water, and dead fish.
Advanced control scheme of doubly fed induction generator for wind turbine us...IJECEIAES
This paper describes a speed control device for generating electrical energy on an electricity network based on the doubly fed induction generator (DFIG) used for wind power conversion systems. At first, a double-fed induction generator model was constructed. A control law is formulated to govern the flow of energy between the stator of a DFIG and the energy network using three types of controllers: proportional integral (PI), sliding mode controller (SMC) and second order sliding mode controller (SOSMC). Their different results in terms of power reference tracking, reaction to unexpected speed fluctuations, sensitivity to perturbations, and resilience against machine parameter alterations are compared. MATLAB/Simulink was used to conduct the simulations for the preceding study. Multiple simulations have shown very satisfying results, and the investigations demonstrate the efficacy and power-enhancing capabilities of the suggested control system.
Generative AI Use cases applications solutions and implementation.pdfmahaffeycheryld
Generative AI solutions encompass a range of capabilities from content creation to complex problem-solving across industries. Implementing generative AI involves identifying specific business needs, developing tailored AI models using techniques like GANs and VAEs, and integrating these models into existing workflows. Data quality and continuous model refinement are crucial for effective implementation. Businesses must also consider ethical implications and ensure transparency in AI decision-making. Generative AI's implementation aims to enhance efficiency, creativity, and innovation by leveraging autonomous generation and sophisticated learning algorithms to meet diverse business challenges.
https://www.leewayhertz.com/generative-ai-use-cases-and-applications/
VARIABLE FREQUENCY DRIVE. VFDs are widely used in industrial applications for...PIMR BHOPAL
Variable frequency drive .A Variable Frequency Drive (VFD) is an electronic device used to control the speed and torque of an electric motor by varying the frequency and voltage of its power supply. VFDs are widely used in industrial applications for motor control, providing significant energy savings and precise motor operation.
Software Engineering and Project Management - Introduction, Modeling Concepts...Prakhyath Rai
Introduction, Modeling Concepts and Class Modeling: What is Object orientation? What is OO development? OO Themes; Evidence for usefulness of OO development; OO modeling history. Modeling
as Design technique: Modeling, abstraction, The Three models. Class Modeling: Object and Class Concept, Link and associations concepts, Generalization and Inheritance, A sample class model, Navigation of class models, and UML diagrams
Building the Analysis Models: Requirement Analysis, Analysis Model Approaches, Data modeling Concepts, Object Oriented Analysis, Scenario-Based Modeling, Flow-Oriented Modeling, class Based Modeling, Creating a Behavioral Model.
Digital Twins Computer Networking Paper Presentation.pptxaryanpankaj78
A Digital Twin in computer networking is a virtual representation of a physical network, used to simulate, analyze, and optimize network performance and reliability. It leverages real-time data to enhance network management, predict issues, and improve decision-making processes.
Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...PriyankaKilaniya
Energy efficiency has been important since the latter part of the last century. The main object of this survey is to determine the energy efficiency knowledge among consumers. Two separate districts in Bangladesh are selected to conduct the survey on households and showrooms about the energy and seller also. The survey uses the data to find some regression equations from which it is easy to predict energy efficiency knowledge. The data is analyzed and calculated based on five important criteria. The initial target was to find some factors that help predict a person's energy efficiency knowledge. From the survey, it is found that the energy efficiency awareness among the people of our country is very low. Relationships between household energy use behaviors are estimated using a unique dataset of about 40 households and 20 showrooms in Bangladesh's Chapainawabganj and Bagerhat districts. Knowledge of energy consumption and energy efficiency technology options is found to be associated with household use of energy conservation practices. Household characteristics also influence household energy use behavior. Younger household cohorts are more likely to adopt energy-efficient technologies and energy conservation practices and place primary importance on energy saving for environmental reasons. Education also influences attitudes toward energy conservation in Bangladesh. Low-education households indicate they primarily save electricity for the environment while high-education households indicate they are motivated by environmental concerns.
2. Introduction to GUI
A graphical user interface (GUI) presents a user-friendly
mechanism for interacting with an application.
A GUI (pronounced "goo-ee") gives an application a distinctive
"look" and "feel."
It provides different applications with consistent, intuitive user
interface components allows users to be somewhat familiar with an
application, so that they can learn it more quickly and use it
more productively.
3. Overview Of Swing Components
Most Swing components are pure Java components they are
written, manipulated and displayed completely in Java.
They are part of the Java Foundation Classes (JFC)Java's
libraries for cross-platform GUI development. There are actually two
sets of GUI components in Java. Before Swing was introduced in J2SE
1.2, Java GUIs were built with components from the Abstract
Window Toolkit (AWT) in package java.awt.
4. When a Java application with an AWT GUI executes on
different Java platforms, the application's GUI components display
differently on each platform. i.e. GUI app in Windows differs from
Mac.
Together, the appearance and the way in which the user interacts with
the application are known as that application's look-and-feel.
Swing GUI components allow you to specify a uniform look-
and-feel for your application across all platforms or to use
each platform's custom look-and-feel.
Overview Of Swing Components
5. Overview Of Swing Components
An application can even change the look-and-feel during execution
to enable users to choose their own preferred look-and-feel.
Most Swing components are not tied to actual GUI components
supported by the underlying platform on which an application
executes.
Such GUI components are known as lightweight components. For
this reason, Swing GUI components are generally preferred.
6. Overview Of Swing Components
In Swing, classes that represent GUI components have names
beginning with the letter J.
Some examples are JButton, JLabel, JFrame, JTextField, JCheckBox,
JComboBox, JRadioButton, JMenu, Jslider and so on.
Altogether there are more than 250 new classes and 75 interfaces in
Swing, the figure shown below depicts the Java Swing class hierarchy.
10. Overview Of Swing Components
1. JPanel is swing's version of the AWT class panel and uses the same
default layout, Flowlayout and it is descended directly from JComponent.
2. JFrame is swing's version of frame and is descended directly from that
class. The components added to the frame are referred to as its contents;
these are managed by the contentPane. To add a component to a
JFrame, we must use its contentPane instead.
3. FlowLayout are used to arrange swing components from left to right
until there's no more space available. Then it begins a new row below it
and moves from left to right again. Each component in a FlowLayout gets
as much space as it needs and no more.
11. Overview Of Swing Components
4. GridLayout is a layout manager that lays out a container's components in
a rectangular grid in row by column manner as per provided by the user.
The container is divided into equal-sized rectangles, and one component
is placed in each rectangle.
5. JLabel descended from JComponent, is used to create text labels that
can not be edited live but are capable of modified in order.
6. AbstractButton is an abstract class which extends class JComponent and
provides a foundation for a family of button classes, including JButton.
JButton is a component the user clicks to trigger a specific action.
12. Overview Of Swing Components
7. JTextField allows editing of a single line of text. New features include
the ability to justify the text left, right, or center, and to set the text's
font.
8. JPasswordField (a direct subclass of JTextField ) you can suppress the
display of input. Each character entered can be replaced by echo
character. This allows confidential input for passwords, for example. By
default, the asterisk, *.
9. JTextArea allows editing of multiple lines of text. JTextArea can
be used in conjunction with class JScrollPane to achieve scrolling.
13. Overview Of Swing Components
The underlying JScrollPane can be forced to always or never have
either the vertical or horizontal scrollbar;
10.JRadioButton is similar to JCheckbox, except for the default
icon for each class. A set of radio buttons can be associated
as a group in which only one button at a time can be selected.
11.JCheckBox is not a member of a checkbox group. A checkbox can
be selected and deselected, AND it also displays its current state.
14. Overview Of Swing Components
12. JComboBox is like a drop down box. You can click a drop-down
arrow and select an option from a list. For example, when the
component has focus, pressing a key that corresponds to the first
character in some entry’s name selects that entry. A vertical scrollbar is
used for longer lists.
13. JMenubar can contain several JMenu’s. Each of the JMenu’s can
contain a series of JMenuItem ’s that it can let you select one. Swing
provides support for pull-down and popup menus.
15. Overview Of Swing Components
Java Swing Example:
Below is a java swing code for the traditional Hello World program.
import javax.swing.JFrame;
import javax.swing.JLabel; OUTPUT:
public class HelloWorldFrame extends JFrame {
HelloWorldFrame(){
JLabel jlbHelloWorld = new JLabel("Hello World");
add(jlbHelloWorld);
this.setSize(200, 100);
setVisible(true);
public static void main(String args[]) {
new HelloWorldFrame();
} } }
16. JFrame
JFrame is a Window with border, title and buttons. When JFrame is set
visible, an event dispatching thread is started.
JFrame objects store several objects including a Container object
known as the content pane. To add a component to a JFrame, add it to
the content pane.
JFrame Constructors
JFrame() : Constructs a new frame that is initially invisible.
JFrame(String title) : Creates a new, initially invisible Frame with the
specified title.
17. JFrame Contnd…
Steps to create a JFrame windows are as follows:
Step 1: Construct an object of the JFrame class.
Step 2: Set the size of the JFrame.
Step 3: Set the title of the JFrame to appear in the title bar (title bar will be
blank if no title is set).
Step 4: Set the default close operation. When the user clicks the close
button, the program stops running.
Step 5: Make the JFrame visible.
18. JFlowLayout
It is an AWT component used to arrange
swing components from left to right until
there’s no more space available.
import java.awt.FlowLayout.*;
import javax.swing.*;
public class FlowLayoutDemo extends JFrame{
FlowLayoutDemo() {
super("FlowLayout Source Demo");
JPanel panel = new JPanel();
add(panel);
panel.setLayout(new FlowLayout());
panel.add(new JLabel("JLabel 1"));
panel.add(new JButton("JButton 2"));
panel.add(new JCheckBox("JCheckBox 3"));
panel.add(new JTextField("Long-Named JTextField
4"));
panel.add(new JButton("JButton 5"));
setVisible(true);
setSize(300,350); }
public static void main(String[] args) {
FlowLayoutDemo flowLayout = new FlowLayoutDemo();
flowLayout.setDefaultCloseOperation(JFrame.EXIT_ON_
CLOSE);
}
}
20. GridLayout
It is a layout manager that lays out a container’s components in a
rectangular grid. The container is divided into equal-sized rectangles,
and one component is placed in each rectangle.
GridLayout Constructors
GridLayout() : Creates a grid layout with a default of one column per component,
in a single row.
GridLayout(int rows, int cols) : Creates a grid layout with the specified number of
rows and columns.
21. JFrame Contnd…
Steps to create a JFrame windows with predefined layout are as follows:
Step 1: Construct an object of the JFrame class.
Step 2: Set the size of the JFrame.
Step 3: Set the title of the JFrame to appear in the title bar (title bar will be
blank if no title is set).
Step 4: Set up the content pane and components in a layout FlowLayout,
GridLayout etc.
Step 5: Set the default close operation.
Step 6: Make the JFrame visible.
22. JLabel
JLabel, descended from JComponent, is used to create text labels.
A JLabel object provides text instructions or information on a GUI;
display a single line of read-only text, an image or both text and image.
We use a Swing JLabel when we need a user interface component
that displays a message or an image.
JLabel Constructor
JLabel() : Creates a JLabel instance with no image and with an empty string for the title.
JLabel(Icon image) :Creates a JLabel instance with the specified image.
JLabel(String text) : Creates a JLabel instance with the specified text.
23. Introduction to Event Handling
Normally, a user interacts with an application’s GUI to indicate the tasks that the
application should perform.
For example, when you write an e-mail in an e-mail application, clicking the send button
tells the application to send the e-mail to the specified e-mail addresses.
GUIs are event driven. When the user interacts with a GUI component, the interaction
known as an event drives the program to perform a task.
Some common events (user interactions) that might cause an application to perform a task
include clicking a button, typing in a text field, selecting an item from a menu, closing a
window and moving the mouse.
The code that performs a task in response to an event is called an event handler and the
overall process of responding to events is known as event handling.
24. More on Event Handling
Both AWT and Swing applications uses the AWT event-handling classes (in package java.awt.event).
Swing added a few new event handling classes (in package javax.swing.event), but they are not
frequently used.
AWT GUI Components (such as Button, TextField, ComboBox, CheckBox and Window) can trigger an
AWTEvent upon user’s activation.
25. More on Event Handling
ActionEvent & ActionListener
An ActionEvent is fired, when an action has been performed by the user.
For examples, when the user clicks a button, chooses a menu item, presses enter key in a text field.
The associated ActionListener interface declares only one abstract method, as follows:
ActionListner Method Definition:
public interface ActionListener extends java.util.eventlistener {
public void actionPerformed(ActionEvent evt); // called-back when an action
//has been performed
}
26. More on Event Handling
Example source code:
The example illustrates a source code fragment which clears a text in text field when the clear button pressed.
JPanel panel = new JPanel();
JTextfield1 jTextField1 = new JTextField();
JButton jBtnClear new JButton(“CLEAR”)
panel.setLayout(new GridLayout(1,2));
add(panel, BorderLayout.CENTER);
panel.add(jBtnClear);
panel.add(jTextField1);
jBtnClear.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
jTextfield1.setText("");
}});
27. JTextField
It allows editing/displaying of a single line of text.
When the user types data into them and presses the Enter key, an action
event occurs.
If the program registers an event listener, the listener processes the event
and can use the data in the text field at the time of the event in the program.
JTextField is an input area where the user can type in characters.
28. JTextField Contnd…
If you want to let the user enter multiple lines of text, you cannot use
JTextfield’s unless you create several of them.
The solution is to use JTextArea which enables the user to enter multiple lines
of text.
JTextField Constructor
JTextField() : Constructs a new TextField.
JTextField(String text): Constructs a new TextField initialized with the specified
text.
All search engine applications are of typical examples of JTextFields.
29. JButton
JButton is a component that the user clicks to trigger a specific action.
A Java application can use several types of buttons, including command
buttons, checkboxes, toggle buttons and radio buttons.
JButton Constructors
JButton() : Creates a button with no set text or icon.
JButton(Action a) : Creates a button where properties are taken from the
Action supplied.
JButton(String text) : Creates a button with text.
30. JComboBox
JComboBox is like a drop down box that you can click a drop-down arrow and select
an option from a list.
It generates ItemEvent. For example, when the component has focus, pressing
a key that corresponds to the first character in some entry’s name selects that
entry. A vertical scrollbar is used for longer lists.
JComboBox Constructors
JComboBox() : Creates a JComboBox with a default data model.
JComboBox(Object[] items) :Creates a JComboBox that contains the elements in the
specified array.
JComboBox(Vector items) : Creates a JComboBox that contains the elements in the
specified Vector.
31. JMenus
Swing provides support for pull-down and popup menus.
A JMenubar can contain several JMenus. And each of the JMenus can contain a series
of JMenuItems that you can select.
How Menus are created?
1. First, a JMenubar is created
2. Then, we attach all of the menus to this JMenubar.
3. Then we add JMenuItems to the JMenus.
4. The JMenubar is then added to the frame. By default, each JMenuItem added to a JMenu is
enabled, that is, it can be selected.
32. JMenus
import java.awt.*;
import java.awt.event.*;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JFrame;
public class JMenuDemo extends JFrame implements
ActionListener{
JTextArea jtAreaOutput;
JMenuBar mainMenuBar;
JMenu menu1, menu2, submenu;
JMenuItem New,subMenuItem;
JMenuDemo() {
super("Microsoft Word");
mainMenuBar = new JMenuBar();
menu1 = new JMenu("File");
menu1.setMnemonic(KeyEvent.VK_F);
mainMenuBar.add(menu1);
New = new JMenuItem("New");
New.addActionListener(this);
menu1.add(New);
menu1.addSeparator();
33. JMenus
// Sub Menu follows a seperator
submenu = new JMenu("Send To:");
submenu.setMnemonic(KeyEvent.VK_D);
subMenuItem = new JMenuItem("My Document");
subMenuItem.addActionListener(this);
submenu.add(subMenuItem);
menu1.add(submenu);
// Build second menu in the menu bar.
menu2 = new JMenu("Edit");
menu2.setMnemonic(KeyEvent.VK_E);
mainMenuBar.add(menu2);
// return mainMenuBar;
JPanel jplContentPane = new JPanel();
jplContentPane.setLayout(new FlowLayout());
jtAreaOutput = new JTextArea(5, 30);
jplContentPane.add(jtAreaOutput);
add(jplContentPane);
setSize(400, 300);
setVisible(true);
}
34. JMenus
public void actionPerformed(ActionEvent e) {
JMenuItem source = (JMenuItem) (e.getSource());
String s = "Menu Item source: " + source.getText();
jtAreaOutput.setText(s);
}
public static void main(String[] args) {
JMenuDemo frame= new JMenuDemo();
frame.setJMenuBar(frame.mainMenuBar);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_
CLOSE);
} }
The End