Transperencies AJP Chapter 01
Transperencies AJP Chapter 01
AWT Classes
AWTEvent AWTEventMulticaster BorderLayout
Button Canvas CardLayout
Checkbox CheckboxGroup
CheckboxMenuItem Choice Color
Component Container Cursor
Dialog Dimension Event
EventQueue FileDialog FlowLayout
Font FontMetrics Frame
Graphics GraphicsDevice
GraphicsEnvironment GridBagLayout GridLayout
Image Insets Label
List MediaTracker Menu
MenuBar MenuComponent MenuItem
MenuShortcut Panel Point
Polygon PopupMenu PrintJob
Rectangle Robot Scrollbar
ScrollPane SystemColor TextArea
TextComponent TextField Toolkit
Window
Window Fundamentals
Component
Container
MenuContainer
Window Panel
Interface
Frame Applet
Dimension
Fields:
int height
int width
Constructors:
1. Dimension()
2. Dimension(Dimension d)
3. Dimension(int width, int height)
Methods:
2. double getHeight()
3. Dimension getSize()
4. double getWidth()
5. void setSize(Dimension d)
Frame Window
Constructors:
1. Frame( )
2. Frame(String title)
3. Dimension getSize( )
Output:
A Windowed Program
Color
Constructors:
Color(int red, int green, int blue)
Color(int rgbValue)
Color(float r, float g, float b)
e.g.
new Color(255, 100, 100);//light red.
int getRed( )
int getGreen( )
int getBlue( )
int getRGB( )
Using Color
/*
<applet code="ColorDemo" width=300 height=200>
</applet>
*/
public class ColorDemo extends Applet
{
public void paint(Graphics g)
{
Color c1 = new Color(202, 146, 20);
Color c2 = new Color(110, 169, 107);
Color c3 = new Color(160, 100, 200);
g.setColor(c1);
g.drawLine(0, 0, 100, 100);
g.drawLine(0, 100, 100, 0);
g.setColor(Color.red);
g.drawLine(40, 25, 250, 180);
g.setColor(c3);
g.drawLine(20, 150, 400, 40);
g.setColor(c2);
g.drawOval(10, 10, 50, 50);
g.fillOval(70, 90, 140, 100);
}
}
Font
Variables:
Variable Meaning
String name Name of the font
float pointSize Size of the font in points
int size Size of the font in points
int style Font style
Methods:
static Font decode(String str)
boolean equals(Object FontObj)
String getFamily( )
String getFontName()
String getName( )
int getSize( )
int getStyle( )
int hashCode( )
boolean isBold( )
boolean isItalic( )
boolean isPlain( )
String toString( )
/*
<applet code="ShowFonts" width=550 height=60>
</applet>
*/
import java.applet.*;
import java.awt.*;
public class ShowFonts extends Applet
{
public void paint(Graphics g)
{
String msg = "";
String FontList[];
GraphicsEnvironment ge =
GraphicsEnvironment.getLocalGraphicsEnvironment();
FontList = ge.getAvailableFontFamilyNames();
for(int i = 0; i < FontList.length; i++)
msg += FontList[i] + " ";
g.drawString(msg, 4, 16);
}
}
Font Style:
Font.PLAIN
Font.BOLD
Font.ITALIC
g.drawString(msg, 4, 16);
}
}