Download presentation
Presentation is loading. Please wait.
1
Graphics Programming - Frames
Sampath Kumar S Assistant Professor, SECE
2
Graphics Programming Makes Java more interesting to learn.
1/16/2019 Makes Java more interesting to learn. Java has 2 libraries for graphics programming: Abstract Windowing Toolkit (AWT) - Old Swing – New and has rich libraries Sampath Kumar S, AP
3
Abstract Windowing Toolkit (AWT):
1/16/2019 Abstract Windowing Toolkit (AWT) is used for GUI programming in java. Introduced with Java 1.0 The basic AWT deals with UI elements by delegating their creation and behavior. The java.awt packages consist of java awt classes which must be imported The awt provides the support for drawing graphical shapes, windows, buttons, test boxes, menus and so on. Sampath Kumar S, AP
4
AWT Container Hierarchy:
1/16/2019 AWT Container Hierarchy: Sampath Kumar S, AP
5
1/16/2019 Container: The Container is a component in AWT that can contain another components like buttons, text fields, labels etc. The classes that extends Container class are known as container. Sampath Kumar S, AP
6
1/16/2019 Window: The window is the container that have no borders and menu bars. You must use frame, dialog or another window for creating a window. Sampath Kumar S, AP
7
1/16/2019 Panel: The Panel is the container that doesn't contain title bar and menubars. It can have other components like button, textfield etc. Sampath Kumar S, AP
8
1/16/2019 Frame: The Frame is the container that contain title bar and can have MenuBars. It can have other components like button, textfield etc. Sampath Kumar S, AP
9
Commonly used Methods of Component class:
1/16/2019 Commonly used Methods of Component class: 1) void add(Component c) 2) void setSize(int width,int height) 3) void setLayout(LayoutManager m) 4) void setVisible(boolean visible) Sampath Kumar S, AP
10
Methods of frame class:
1/16/2019 Methods of frame class: 1) void setTitle(String Title) 2) void setResizable(boolean resizeable) 3) void setSize(int width,int height) 4) String getTitle() 5) void setVisible(boolean visible) Sampath Kumar S, AP
11
Creating a Frame: There are two ways to create a frame:
1/16/2019 Creating a Frame: There are two ways to create a frame: By extending Frame class (inheritance) By creating the object of Frame class (association) Sampath Kumar S, AP
12
1/16/2019 AWT by inheritance: Eg 1 import java.awt.*; class FrameDemo extends Frame{ public static void main(String args[]){ FrameDemo f=new FrameDemo(); f.setSize(300,300); //framesize 300width and 300height f.setVisible(true); /* now frame will be visible, by default not visible */ } } Sampath Kumar S, AP
13
AWT by inheritance: Output
1/16/2019 AWT by inheritance: Output Sampath Kumar S, AP
14
1/16/2019 AWT by inheritance: Eg 2 import java.awt.*; class FrameDemo extends Frame{ FrameDemo{ Button b=new Button("click me"); b.setBounds(30,100,80,30);//setting button position add(b);//adding button into frame setSize(300,300);//framesize 300width and 300height setVisible(true); //now frame willbe visible, by default not visible } public static void main(String args[]){ FrameDemo f=new FrameDemo(); } Sampath Kumar S, AP
15
AWT by inheritance: Output
1/16/2019 AWT by inheritance: Output Sampath Kumar S, AP
16
1/16/2019 AWT by association: import java.awt.*; class FrameDemo{ FrameDemo(){ Frame f=new Frame(); \\create instance for frame class Button b=new Button("click me"); b.setBounds(30,50,80,30); f.add(b); f.setSize(300,300); f.setVisible(true); } public static void main(String args[]){ FrameDemo f=new FrameDemo(); Sampath Kumar S, AP
17
AWT by association : Output
1/16/2019 AWT by association : Output Sampath Kumar S, AP
18
1/16/2019 Sampath Kumar S, AP
19
1/16/2019 Thank You Sampath Kumar S, AP
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.