Computer Science A 11: 20/2 - PowerPoint PPT Presentation

1 / 25
About This Presentation
Title:

Computer Science A 11: 20/2

Description:

Events from mouse clicks, keyboard etc. Can be quite ... drawString('(Gy )',50,200); Paint. canvas.setPaint(Color.red); canvas.fillRect(50,50,100,100) ... – PowerPoint PPT presentation

Number of Views:26
Avg rating:3.0/5.0
Slides: 26
Provided by: madsros
Category:

less

Transcript and Presenter's Notes

Title: Computer Science A 11: 20/2


1
Computer Science A 11 20/2

CS A
2
Java and swing
  • Graphics programming
  • Windows with menus
  • Buttons, textfields, scroll panels etc
  • Animations, images,
  • Events from mouse clicks, keyboard etc.
  • Can be quite complicated

3
EmptyFrame.java
  • import javax.swing.JFrame
  • public class EmptyFrame
  • public static void main(String args)
  • JFrame framenew JFrame("EmptyFrame")
  • frame.setSize(600,600)
  • frame.setDefaultCloseOperation(
  • JFrame.EXIT_ON_CLOSE)
  • frame.setVisible(true)

4
EmptyFrame

5
Add a canvas to the window
  • public static void main(String args)
  • JFrame framenew JFrame()
  • frame.setSize(600,600)
  • frame.setTitle("DrawShapes")
  • frame.setDefaultCloseOperation(
  • JFrame.EXIT_ON_CLOSE)
  • JCanvas canvas new JCanvas()
  • frame.add(canvas)
  • frame.setVisible(true)
  • ..

6
Coordinate system

7
drawLine(135,230,335,370)

8
drawOval(135,230,200,140)

9
What to draw on a canvas
  • Line
  • Oval/ellipsis
  • Arcs (parts of an ellipsis
  • Rectangles
  • Curves, quadratic, qubic, bezier
  • Images
  • Text

10
The state when drawing
  • Current Font
  • Current Stroke (width of lines)
  • Current Paint (color of areas)
  • Current Transform (scaling, rotation, deformation
    of drawings)
  • Current Composite (new items can be made
    partially transparent
  • Current clipping area. (limit the area in which
    you can draw)

11
setFont(new Font("Serif",Font.BOLD,150))drawStri
ng("(GyÑ)",50,200)

12
Paint
  • canvas.setPaint(Color.red)
  • canvas.fillRect(50,50,100,100)
  • canvas.setPaint(Color.blue)
  • canvas.fillOval(250,50,100,100)
  • canvas.setPaint(Color.green)
  • canvas.fillArc(450,50,100,100,45,270)
  • canvas.setPaint(new GradientPaint(
  • 50,350,Color.red,450,350,Color.blue))
  • canvas.fillRect(50,300,500,100)

13
Paint

14
More to come
  • Transformations
  • Partially transparent
  • Images
  • Other components buttons etc
  • Events from windows.

15
Java swing components
  • Windows and components

16
Example

17
JLabel
  • A bit of text and/or an icon
  • new JLabel(Label 1,new IconImage(..))

18
JButton
  • A button you can press.
  • Text and/or an image (icon)

19
Radiobutton and checkbox
  • Press to select or de-select

20
JTextField
  • TextField a line where you can enter text using
    the keyboard.

21
JTextArea
  • TextArea a multi-line area for entering text

22
JSlider
  • A slider select a value
  • By dragging a knob

23
JSpinner
  • Select a value
  • by stepping through
  • a bounded range
  • of values

24
JComboBox
  • Select a value from
  • a drop-down list

25
JList
  • Select an a value
  • or an interval
  • of values from
  • a list
Write a Comment
User Comments (0)
About PowerShow.com