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.
JSP technology has facilitated the segregation of the work of a Web designer and a Web developer.
A Web designer can design and formulate the layout for the Web page by using HTML.
On the other hand, a Web developer working independently can use java code and other JSP specific tags to code the business logic.
The simultaneous construction of the static and dynamic content facilitates development of quality applications with increased productivity.
An Activity is an application component that provides a screen with which users can interact in order to do something, such as dial the phone, take a photo, send an email, or view a map.
Each activity is given a window in which to draw its user interface. The window typically fills the screen, but may be smaller than the screen and float on top of other windows.
An application usually consists of multiple activities that are loosely bound to each other. Typically, one activity in an application is specified as the "main" activity, which is presented to the user when launching the application for the first time. Each activity can then start another activity in order to perform different actions.
Each time a new activity starts, the previous activity is stopped, but the system preserves the activity in a stack .
When a new activity starts, it is pushed onto the back stack and takes user focus.
JSP technology has facilitated the segregation of the work of a Web designer and a Web developer.
A Web designer can design and formulate the layout for the Web page by using HTML.
On the other hand, a Web developer working independently can use java code and other JSP specific tags to code the business logic.
The simultaneous construction of the static and dynamic content facilitates development of quality applications with increased productivity.
An Activity is an application component that provides a screen with which users can interact in order to do something, such as dial the phone, take a photo, send an email, or view a map.
Each activity is given a window in which to draw its user interface. The window typically fills the screen, but may be smaller than the screen and float on top of other windows.
An application usually consists of multiple activities that are loosely bound to each other. Typically, one activity in an application is specified as the "main" activity, which is presented to the user when launching the application for the first time. Each activity can then start another activity in order to perform different actions.
Each time a new activity starts, the previous activity is stopped, but the system preserves the activity in a stack .
When a new activity starts, it is pushed onto the back stack and takes user focus.
This slide from Android Application Programming Seminar at a Technical University of Vietnam.
Throughout the slide, audience will have the general knowledge about Android OS, Architecture. The slide also provide the Android Application structure, the choices of framework or language to develop an Android application.
Real Time Audio is an application is written for this seminar.
Everyone can download from Google Play:
https://play.google.com/store/apps/details?id=junoteam.com.realtimerecording
Java Multi Threading Concept
By N.V.Raja Sekhar Reddy
www.technolamp.co.in
Want more...
Like us @ https://www.facebook.com/Technolamp.co.in
subscribe videos @ http://www.youtube.com/user/nvrajasekhar
Oop’s Concept and its Real Life ApplicationsShar_1
In this ppt, I've given real life examples and case studies where the concept of Object Oriented Programming can be applied.
Program examples are also included.
An introduction to software engineering, based on the first chapter of "A (Partial) Introduction to Software Engineering
Practices and Methods" By Laurie Williams
This slide from Android Application Programming Seminar at a Technical University of Vietnam.
Throughout the slide, audience will have the general knowledge about Android OS, Architecture. The slide also provide the Android Application structure, the choices of framework or language to develop an Android application.
Real Time Audio is an application is written for this seminar.
Everyone can download from Google Play:
https://play.google.com/store/apps/details?id=junoteam.com.realtimerecording
Java Multi Threading Concept
By N.V.Raja Sekhar Reddy
www.technolamp.co.in
Want more...
Like us @ https://www.facebook.com/Technolamp.co.in
subscribe videos @ http://www.youtube.com/user/nvrajasekhar
Oop’s Concept and its Real Life ApplicationsShar_1
In this ppt, I've given real life examples and case studies where the concept of Object Oriented Programming can be applied.
Program examples are also included.
An introduction to software engineering, based on the first chapter of "A (Partial) Introduction to Software Engineering
Practices and Methods" By Laurie Williams
Software Engineering is the set of processes and tools to develop software. Software Engineering is the combination of all the tools, techniques, and processes that used in software production. Therefore Software Engineering encompasses all those things that are used in software production like :
Programming Language
Programming Language Design
Software Design Techniques
Tools
Testing
Maintenance
Development etc.
These days object-oriented programming is widely being used. If programming languages will not support object-orientation then it will be very difficult to implement object-oriented design using object-oriented principles. All these efforts made the basis of software engineering.
The importance of software since there is were the motivation for software engineering lies and then and introduction to software engineering mentioning the concept and stages of development and working in teams
Palestine last event orientationfvgnh .pptxRaedMohamed3
An EFL lesson about the current events in Palestine. It is intended to be for intermediate students who wish to increase their listening skills through a short lesson in power point.
Read| The latest issue of The Challenger is here! We are thrilled to announce that our school paper has qualified for the NATIONAL SCHOOLS PRESS CONFERENCE (NSPC) 2024. Thank you for your unwavering support and trust. Dive into the stories that made us stand out!
How to Create Map Views in the Odoo 17 ERPCeline George
The map views are useful for providing a geographical representation of data. They allow users to visualize and analyze the data in a more intuitive manner.
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
Synthetic fiber production is a fascinating and complex field that blends chemistry, engineering, and environmental science. By understanding these aspects, students can gain a comprehensive view of synthetic fiber production, its impact on society and the environment, and the potential for future innovations. Synthetic fibers play a crucial role in modern society, impacting various aspects of daily life, industry, and the environment. ynthetic fibers are integral to modern life, offering a range of benefits from cost-effectiveness and versatility to innovative applications and performance characteristics. While they pose environmental challenges, ongoing research and development aim to create more sustainable and eco-friendly alternatives. Understanding the importance of synthetic fibers helps in appreciating their role in the economy, industry, and daily life, while also emphasizing the need for sustainable practices and innovation.
Ethnobotany and Ethnopharmacology:
Ethnobotany in herbal drug evaluation,
Impact of Ethnobotany in traditional medicine,
New development in herbals,
Bio-prospecting tools for drug discovery,
Role of Ethnopharmacology in drug evaluation,
Reverse Pharmacology.
The Roman Empire A Historical Colossus.pdfkaushalkr1407
The Roman Empire, a vast and enduring power, stands as one of history's most remarkable civilizations, leaving an indelible imprint on the world. It emerged from the Roman Republic, transitioning into an imperial powerhouse under the leadership of Augustus Caesar in 27 BCE. This transformation marked the beginning of an era defined by unprecedented territorial expansion, architectural marvels, and profound cultural influence.
The empire's roots lie in the city of Rome, founded, according to legend, by Romulus in 753 BCE. Over centuries, Rome evolved from a small settlement to a formidable republic, characterized by a complex political system with elected officials and checks on power. However, internal strife, class conflicts, and military ambitions paved the way for the end of the Republic. Julius Caesar’s dictatorship and subsequent assassination in 44 BCE created a power vacuum, leading to a civil war. Octavian, later Augustus, emerged victorious, heralding the Roman Empire’s birth.
Under Augustus, the empire experienced the Pax Romana, a 200-year period of relative peace and stability. Augustus reformed the military, established efficient administrative systems, and initiated grand construction projects. The empire's borders expanded, encompassing territories from Britain to Egypt and from Spain to the Euphrates. Roman legions, renowned for their discipline and engineering prowess, secured and maintained these vast territories, building roads, fortifications, and cities that facilitated control and integration.
The Roman Empire’s society was hierarchical, with a rigid class system. At the top were the patricians, wealthy elites who held significant political power. Below them were the plebeians, free citizens with limited political influence, and the vast numbers of slaves who formed the backbone of the economy. The family unit was central, governed by the paterfamilias, the male head who held absolute authority.
Culturally, the Romans were eclectic, absorbing and adapting elements from the civilizations they encountered, particularly the Greeks. Roman art, literature, and philosophy reflected this synthesis, creating a rich cultural tapestry. Latin, the Roman language, became the lingua franca of the Western world, influencing numerous modern languages.
Roman architecture and engineering achievements were monumental. They perfected the arch, vault, and dome, constructing enduring structures like the Colosseum, Pantheon, and aqueducts. These engineering marvels not only showcased Roman ingenuity but also served practical purposes, from public entertainment to water supply.
Instructions for Submissions thorugh G- Classroom.pptxJheel Barad
This presentation provides a briefing on how to upload submissions and documents in Google Classroom. It was prepared as part of an orientation for new Sainik School in-service teacher trainees. As a training officer, my goal is to ensure that you are comfortable and proficient with this essential tool for managing assignments and fostering student engagement.
2. Objectives
After you have read and studied this chapter, you should
be able to
Define a subclass of JFrame to implement a customized frame
window.
Write event-driven programs using Java's delegation-based event
model
Arrange GUI objects on a window using layout managers and
nested panels
Write GUI application programs using
JButton, JLabel, ImageIcon, JTextField, JTextArea, JCheckBox, JR
adioButton, JComboBox, JList, and JSlider objects from the
javax.swing package
Write GUI application programs with menus
3. Graphical User Interface
In Java, GUI-based programs are
implemented by using classes from the
javax.swing and java.awt packages.
The Swing classes provide greater
compatibility across different operating
systems. They are fully implemented in
Java, and behave the same on different
operating systems.
4. Various Java GUI
Components from the
javax.swing package
Button
Label Text
field
Check
Box
Radio
Button
Combo Box
6. AWT Class Hierarchy (java.awt package)
AWTEvent
Font
FontMetrics
Component
Graphics
Object Color
Canvas
Button
TextComponent
Label
List
CheckBoxGroup
CheckBox
Choice
Container Panel Applet
Frame
Dialog FileDialog
Window
TextField
TextArea
MenuComponent MenuItem
MenuBar
Menu
Scrollbar
LayoutManager
7. Swing Class Hierarchy (javax.swing)
Dimension
Font
FontMetrics
Component
Graphics
Object Color
Container
Panel Applet
Frame
Dialog
Window
JComponent
JApplet
JFrame
JDialog
Swing Components
in the javax.swing package
Lightweight
Classes in the java.awt
package
1
LayoutManager
*
8. Can be classified into three groups
Container classes
Ex: JFrame, JPanel, JApplet
To contain other components
Helper classes
Graphics, Color, Font, etc
Used by components and containers to draw and place objects
Component classes
JButton, JTextField, ETC are subclasses of JComponent
GUI Classes
10. Used to contain other GUI components
Window, Panel, Frame, Dialog and Applet are the container
classes for AWT components
To work with Swing components, use
Component, Container, JFrame, JPanel,JDialog and
JApplet
Container
Used to group components.
A layout manager is used to position and place components in
container
Ex. Frames, panels and applets
Container Classes
11. JFrame
Is a window not contained inside another window. It is the container
that holds other swing UI components
JPanel
An invisible container that holds UI components
Panel can be nested
Can place panels inside a container that includes a panel
JDialog
A pop-up windows or message box to receive additional information
from the user or provide notification that an event has occurred
JApplet – a subclass of Applet. Must extend JApplet to create a
Swing-based applet
Container Classes
12. GUI Helper Classes
Dimension
Font
FontMetrics
Component
Graphics
Object Color
Container
Panel Applet
Frame
Dialog
Window
JComponent
JApplet
JFrame
JDialog
Swing Components
in the javax.swing package
Lightweight
Heavyweight
Classes in the java.awt
package
1
LayoutManager
*
JPanel
The helper classes are not
subclasses of Component.
They are used to describe the
properties of GUI components
such as graphics context,
colors, fonts, and dimension.
13. Component is a superclass of all the UI classes
JComponent is a superclass of all the lightweight Swing
components
JComponent is an abstract class, cannot use new
JComponent to create an instance of JComponent
Use the constructor of subclasses of JComponent to create
JComponent instances.
An instance of a subclass can invoke the accessible
method defined in its superclass
Swing GUI Components
15. Frames
Frame is a window that is not contained inside
another window.
Frame is the basis to contain other user interface
components in Java GUI applications.
The Frame class can be used to create windows. The
Frame class contains rudimentary functionalities to
support features found in any frame window.
For Swing GUI programs, use JFrame class to create
windows.
16. Two Ways to Create a
Window Using JFrame
First approach
Declare & Create object of type JFrame
Use various methods to manipulate window
Second approach
Create class containing application program by extending
definition of class JFrame
Utilizes mechanism of inheritance
17. Creating Frames
1) First approach:
import javax.swing.*;
public class MyFrame
{
public static void main(String[] args)
{
JFrame frame = new JFrame(“MyFrame");
frame.setSize(400, 300);
frame.setVisible(true);
frame.setDefaultCloseOperation(
JFrame.EXIT_ON_CLOSE);
}
}
18. Creating Frames
import javax.swing.*;
public class MyFrame
{
public static void main(String[] args)
{
JFrame frame = new JFrame(“MyFrame");
frame.setSize(400, 300);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
300
400
setVisible() and setSize() –
methods in Component class
setDefaultCloseOperation
(EXIT_ON_CLOSE)
- terminate when the frame is
closed
19. Creating Frames
2) Second approach :
import javax.swing.*;
public class MyFrame extends JFrame
{
public MyFrame()
{
setTitle(“MyFrame");
setSize(400, 300);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String[] args)
{
MyFrame myFrame = new MyFrame();
}
}
20. The Content Pane of a Frame
The content pane is where we put GUI objects
such as buttons, labels, scroll bars, and
others.
We access the content pane by calling the
frame’s getContentPane method.
This gray area is the
content pane of this
frame.
21. Changing the Background Color
Here's how we can change the background
color of a content pane to blue:
Container contentPane = getContentPane();
contentPane.setBackground(Color.BLUE);
22. Placing GUI Objects on a Frame
There are two ways to put GUI objects on the
content pane of a frame:
Use a layout manager
○ FlowLayout
○ BorderLayout
○ GridLayout
○ others
Use absolute positioning
○ null layout manager
23. Placing a Button
A JButton object a GUI component that
represents a pushbutton.
Here's an example of how we place a button
with FlowLayout.
contentPane.setLayout(
new FlowLayout());
JButton okButton
= new JButton("OK");
JButton cancelButton
= new JButton("CANCEL");
contentPane.add(okButton);
contentPane.add(cancelButton);
24. Layout Managers
The layout manager determines how the GUI
components are added to the container (such
as the content pane of a frame)
Layout managers are set in containers using
the setLayout(LayoutManager) method in a
container
25. FlowLayout
In using this layout, GUI components
are placed in left-to-right order.
When the component does not fit on the
same line, left-to-right placement continues
on the next line.
As a default, components on each line
are centered.
When the frame containing the
component is resized, the placement of
components is adjusted accordingly.
27. FlowLayout
The components are arranged in
the container from left to right in
the order in which they were
added.
When one row becomes filled, a
new row is started.
FlowLayout can be aligned in 3
ways:
FlowLayout.LEFT – left aligned
FlowLayout.RIGHT – right aligned
FlowLayout.CENTER – center aligned
28. FlowLayout Constructors
public FlowLayout(int align, int hGap, int vGap)
Constructs a new FlowLayout with a specified alignment, horizontal
gap, and vertical gap. The gaps are the distances in
pixel between components.
public FlowLayout(int alignment)
Constructs a new FlowLayout with a specified alignment and a default gap
of five pixels for both horizontal and vertical.
public FlowLayout()
Constructs a new FlowLayout with a default center alignment and a default
gap of five pixels for both horizontal and vertical.
29. import java.awt.*;
import javax.swing.*;
//import java.awt.event.*;
public class TestFlowLayout extends JFrame
{
public TestFlowLayout()
{
super(“Using flowLayout");
Container cpane = getContentPane();
cpane.setLayout(new FlowLayout(FlowLayout.LEFT,20,10));
for (int i=1; i<7;i++)
cpane.add(new JButton("button "+i));
setSize(300,200);
setVisible(true);
}
public static void main(String[] arg)
{
TestFlowLayout teks = new TestFlowLayout();
teks.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
10
20
30. BorderLayout
This layout manager divides the
container into five regions:
center, north, south, east, and west.
The north and south regions expand or
shrink in width only
The east and west regions expand or
shrink in height only
The center region expands or shrinks on
both height and width.
Not all regions have to be occupied.
32. GridLayout
This layout manager placesGUI
components on equal-size N by M grids.
Components are placed in top-to-
bottom, left-to-right order.
The number of rows and columns
remains the same after the frame is
resized, but the width and height of each
region will change.
34. Using Panels as Containers
Panels act as smaller containers for grouping user interface
components.
It is recommended that you place the user interface components
in panels and place the panels in a frame. You can also place
panels in a panel.
To add a component to JFrame, you actually add it to the content
pane of JFrame. To add a component to a panel, you add it
directly to the panel using the add method.
35. Create a JPanel
example :
Container cpane = getContentPane();
JPanel pan = new JPanel(); // create a panel
pan.add(new JButton(“Click”)); // add a button in
the panel
cpane.add(pan) // add the panel in the container
36. label TextField
Text Area
button button
There are 3 panels :
top panel – has 2 components that are label, textfield
- 2 components are arranged with flowLayout
middle panel – has a component: text area. It is arranged with Gridlayout
bottom panel – has 2 components that are buttons
- 2components are arranged with Flowlayout
All panels are arrranged with borderlayout
top panel –north middle panel –center bottom panel –South
Top
panel
Middle
panel
Bottom
panel
37. import java.awt.*;
import javax.swing.*;
public class UjiPanel extends JFrame
{
public UjiPanel()
{
super("Membuat BorderLayout");
Container bekas = getContentPane();
bekas.setLayout(new BorderLayout());
JPanel panelAtas = new JPanel();
bekas.add(panelAtas,BorderLayout.NORTH);
JLabel label = new JLabel("Nama");
JTextField txtField = new JTextField(10);
panelAtas.setLayout(new FlowLayout());
panelAtas.add(label);
panelAtas.add(txtField);
JPanel panelTengah = new JPanel();
bekas.add(panelTengah,BorderLayout.CENTER);
JTextArea txtArea = new JTextArea();
panelTengah.setLayout(new GridLayout());
panelTengah.add(txtArea);
JPanel panelBawah = new JPanel();
bekas.add(panelBawah,BorderLayout.SOUTH);
JButton btg1 = new JButton("Hantar");
JButton btg2 = new JButton("Batal");
btg2.setMnemonic('B');
panelBawah.setLayout(new FlowLayout());
panelBawah.add(btg1);
panelBawah.add(btg2);
39. Step in Creating Panel
Set a layout manager for a container (frame).
Create a panel
Set a layout for the panel.
Add the panel in the container (frame)
Create a component that to be added in the panel
Add the component in the panel
40. GUI Classes for Handling Text
The Swing GUI classes
JLabel, JTextField, and JTextArea deal
with text.
A JLabel object displays uneditable text (or
image).
A JTextField object allows the user to enter a
single line of text.
A JTextArea object allows the user to enter
multiple lines of text. It can also be used for
displaying multiple lines of uneditable text.
41. JLabel
We use a JLabel object to display a label.
A label can be a text or an image.
When creating an image label, we pass
ImageIcon object instead of a string.
JLabel textLabel = new JLabel("Please enter your name");
contentPane.add(textLabel);
JLabel imgLabel = new JLabel(new ImageIcon("cat.gif"));
contentPane.add(imgLabel);
42. JTextField
We use a JTextField object to accept a single
line to text from a user. An action event is
generated when the user presses the ENTER
key.
The getText method of JTextField is used to
retrieve the text that the user entered.JTextField input = new JTextField( );
contentPane.add(input);
44. JTextArea
We use a JTextArea object to display or allow the user to
enter multiple lines of text.
The setText method assigns the text to a
JTextArea, replacing the current content.
The append method appends the text to the current text.
JTextArea textArea
= new JTextArea( );
. . .
textArea.setText("Hellon");
textArea.append("the lost ");
textArea.append("world");
Hello
the lost world
JTextArea
46. Adding Scroll Bars to
JTextArea
By default a JTextArea does not have
any scroll bars. To add scroll bars, we
place a JTextArea in a JScrollPane
object.
JTextArea textArea = new JTextArea();
. . .
JScrollPane scrollText = new JScrollPane(textArea);
. . .
contentPane.add(scrollText);
49. Menus
The javax.swing package contains three menu-
related classes: JMenuBar, JMenu, and
JMenuItem.
JMenuBar is a bar where the menus are placed.
There is one menu bar per frame.
JMenu (such as File or Edit) is a group of menu
choices. JMenuBar may include many JMenu
objects.
JMenuItem (such as Copy, Cut, or Paste) is an
individual menu choice in a JMenu object.
Only the JMenuItem objects generate events.
51. Sequence for Creating
Menus
1. Create a JMenuBar object and attach it
to a frame.
2. Create a JMenu object.
3. Create JMenuItem objects and add
them to the JMenu object.
4. Attach the JMenu object to the
JMenuBar object.