Java AWT – Advanced Concepts
Dialogs, Graphics, Images, Clipboard
(Slides 37–44)
Dialogs
• • Popup windows used for interaction
• • Types:
• - Modal → blocks parent window
• - Modeless → does not block
• Example:
• Dialog d = new Dialog(f, "Dialog", true);
• [Link](200,100);
• [Link](true);
FileDialog
• • Used to open or save files
• Example:
• FileDialog fd = new FileDialog(f, "Open File",
[Link]);
• [Link](true);
• String file = [Link]();
Custom Canvas
• • Canvas class for drawing graphics
• Example:
• class MyCanvas extends Canvas {
• public void paint(Graphics g) {
• [Link]("Hello AWT", 50, 50);
• }
• }
Graphics Class
• • Provides methods for drawing shapes, text,
images
• Example:
• [Link](20,30,200,30);
• [Link](40,50,60,30);
• [Link]([Link]);
• [Link](120,50,50,50);
Colors & Fonts
• • Use Color class for predefined & custom
colors
• • Use Font class for text style
• Example:
• [Link]([Link]);
• [Link](new Font("Serif", [Link], 18));
Images in AWT
• • Load and draw images
• Example:
• Image img =
[Link]().getImage("[Link]");
• [Link](img, 20, 20, this);
Double Buffering
• • Technique to avoid flickering in graphics
• • Draw off-screen, then display
• Example:
• BufferedImage buffer = new BufferedImage(w,
h, TYPE_INT_ARGB);
• Graphics g2 = [Link]();
Clipboard & Data Transfer
• • Supports cut, copy, paste
• Example:
• Clipboard cb =
[Link]().getSystemClipboard
();
• StringSelection s = new
StringSelection("Hello");
• [Link](s, null);