Frame wnd = new Frame("My frame");
wnd.setSize(400,300);
wnd.setVisible(true);
public class AWTApp extends Frame {
public void paint(Graphics g) {
g.drawString("Hi!", 100, 100);
}
}
public class WindowClosingAdapter extends WindowAdapter {
@Override
public void windowClosing(WindowEvent event) {
event.getWindow().setVisible(false);
event.getWindow().dispose();
System.exit(0);
}
}
public class Main {
public static void main(String[] args) {
Frame f = new Frame("WindowClosingAdapter test");
f.addWindowListener(new WindowClosingAdapter());
f.setSize(400,300);
f.setLocation(100,100);
f.setVisible(true);
}
}
// Line
g.drawLine(x1, y1, x2, y2);
// Rectangle
// x,y is top left corner
g.drawRect(x,y, width, height);
// Polygon
// arx ... array of x coords
// ary ... array of y coords
// both arrays need to be synced
// int cnt .. num of coord pairs
g.drawPolygon(int[] arx, int[] ary, int cnt);
//Circle
// in the rect with widht and height
// with top left corner in x,y
// draw biggest ellipse
g.drawOval(int x, int y, int width, int height);
// Arc
// 0° - 3:00 pos
// positive angles ccw
g.drawArc(int x, int y, int width, int height,
int startAngle, int arcAnlge);
// Fillmodes
g.fillRect(int x, int y, int w, int h);
g.fillPolygon(int[] arx, int[] ary, int cnt);
g.fillOval(int x, int y, int width, int height);
g.fillArc(int x, int y, int width, int height,
int startAngle, int arcAngle);
// Copy/Clear areas
g.clearRect(int x, int y, int width, int height);
g.copyArea(int x, int y, int width, int height, int dx, int dy);
// Output to certain area
// Define smaller rects to limit "canvas"
g.clipRect(int x, int y, int width, int height);
// Define arb clip
g.setClip(int x, int y, int width, int height);
// Text output
// x,y defines basisline
g.drawString(String str, int x, int y);
g.drawChars(char[] data, int offset, int length; int x, int y);
g.drawBytes(byte[] data, int offset, int length, int x, int y),
// define different font objects
// no rotation etc. provided
// toolkit provides std fontlist
Toolkit.getDefaultToolkit().getFontList();
// Methods to get Font information
Frame frame = new Frame("Frame");
frame.setSize(300,200);
frame.setVisible(true);
// ...
frame.setVisible(false);
frame.dispose();
System.exit(0);
Handbuch der Java-Programmierung
(5. Auflage)
Thank you for your attention!