Topic: Name: _____________________________________________________ Period: _______ Date: _______________________ Lab0: Intro to Graphics

advertisement
Topic:
Lab0: Intro to Graphics
Objectives
What is JFrame?
What is a JPanel?
What is an API?
3 classes to become familiar
with:
Color class
Font class
Graphics class
paintComponent
Name: _____________________________________________________
Period: _______ Date: _______________________




I will be able to give a high level description of a JFrame and a JPanel.
I will be able to draw squares, rectangles, circles, ovals and lines in a Windows screen.
I will be able to draw figures in different colors.
I will be able to write Strings to a Windows screen.


A JFrame is a Windows screen and it includes a title,
A JPanel is the contents within the JFrame
Applications Programmers Interface – Document which describes what all the methods do
- Including the method signature.



Graphics
Color
Font
2 ways to create a Color:
 Hard coded: Color.blue; 13 colors defined.
 Create a new color new Color (int red, int green, int blue)
Similar to the word document, you can specify different types, sizes, bold, etc.
new Font (<name>, <style>, size );






setColor
setFont
drawString
drawLine
fillRect, drawRect
fillOval, drawOval
Called automatically when the JFrame is resized or repaint() is called.
public void paintComponent( Graphics g )
{
// Your code here
}
Coordinates in Java
All values are in pixels: dots on your terminal (eg. 900 x 1200)
setFont
drawstring
g.setFont( new Font (“serif”, Font.Bold, 50) );
g.drawString ( "string", x, y );
setColor
fillRect
drawRect
g.setColor ( Color.red );
g.fillRect(x, y, width, length);
g.drawRect(x, y, width, length);
setColor
fillOval
drawOval
g.setColor (new Color (234, 5, 59);
g.fillOval(x, y, width, length)
g.drawOval(x, y, width, length);
drawLine
g.drawLine(x1, y1, x2, y2);
Summary:
//rectangle is filled in.
//just the outline
Download