Modernas Programme - PowerPoint PPT Presentation

1 / 33
About This Presentation
Title:

Modernas Programme

Description:

Ievads GUI (Graphical User Interface) 'Java How to Program, Sixth Edition' ... Satur klases ar kuru palidzibu var veidot GUI. Klase javax.swing.JOptionPane ... – PowerPoint PPT presentation

Number of Views:63
Avg rating:3.0/5.0
Slides: 34
Provided by: Edg89
Category:

less

Transcript and Presenter's Notes

Title: Modernas Programme


1
Modernas Programmešanas Tehnologijas (Advanced
Programming Technologies)
  • Edgars Celms, Martinš Opmanis
  • (askola_at_mii.lu.lv)

Latvijas Universitates Matematikas un
informatikas instituts 2007, Riga, Latvija
2
Ievads GUI (Graphical User Interface)
  • Java How to Program, Sixth Edition
  • Chapter 3. Introduction to Classes and Objects
  • Ievads GUI (Graphical User Interface) dialogu
    logu lietojums
  • 3.9. (Optional) GUI and Graphics Case Study
    Using Dialog Boxes
  • Chapter 4. Control Statements Part I
  • Ievads GUI liniju zimešana
  • 4.14. GUI and Graphics Case Study Creating
    Simple Drawings
  • Chapter 5. Control Statements Part II
  • Ievads GUI cetrsturu un ovalu zimešana
  • 5.10. (Optional) GUI and Graphics Case Study
    Drawing Rectangles and Ovals
  • Chapter 6. Methods A Deeper Look
  • Ievads GUI krasas un krasainas figuras
  • 6.13. (Optional) GUI and Graphics Case Study
    Colors and Filled Shapes
  • Chapter 7. Arrays
  • Ievads GUI loku zimešana
  • 7.13. (Optional) GUI and Graphics Case Study
    Drawing Arcs
  • Chapter 8. Classes and Objects A Deeper Look
  • Ievads GUI objektu lietošana kopa ar grafiskiem
    elementiem
  • 8.18. (Optional) GUI and Graphics Case Study
    Using Objects with Graphics

3
Dialogu logu lietojums I
  • Pakotne (package) javax.swing
  • Satur klases ar kuru palidzibu var veidot GUI
  • Klase javax.swing.JOptionPane
  • Satur statisku (static) metodi showMessageDialog
  • tiek izmantota, lai izspidinatu zinojuma logu
    (message box)
  • Satur statisku metodi showInputDialog
  • tiek izmantota, lai dotu iespeju lietotajam
    ievadit kadu informaciju

4
Dialogu logu lietojums II
import javax.swing.JOptionPane public class
NameDialog public static void main(String
args ) String name
JOptionPane.showInputDialog("What is your
name?") String message
"Hello " name
JOptionPane.showMessageDialog(null, message)

5
Liniju zimešana I
  • Javas koordinatu sistema
  • Tiek defineta izmantojot x un y koordinatas
  • Tiek sauktas ari par horizontalam un vertikalam
    koordinatam
  • Are measured along the x-axis and y-axis
  • Koordinatu mervieniba ir pikselis (pixel)
  • Klase Graphics no java.awt pakotnes
  • Nodrošina metodes lai varetu zimet figuras un
    grafiski attelot tekstualu informaciju
  • Klase JPanel no javax.swing pakotnes
  • Nodrošina laukumu uz kura zimet

6
Liniju zimešana II
  • Inheriting
  • extends keyword
  • The subclass inherits from the superclass
  • The subclass has the data and methods that the
    superclass has as well as any it defines for
    itself
  • The JPanel class
  • Every JPanel has a paintComponent method
  • paintComponent is called whenever the system
    needs to display the JPanel
  • getWidth and getHeight methods
  • Return the width and height of the JPanel,
    respectively
  • drawLine method
  • Draws a line from the coordinates defined by its
    first two arguments to the coordinates defined by
    its second two arguments

7
Liniju zimešana III
Import the java.awt.Graphics and the
javax.swing.JPanel classes
The DrawPanel class extends the JPanel class
Declare the paintComponent method
Retrieve the JPanels width and height
Draw the two lines
8
Liniju zimešana IV
  • JFrame class from the javax.swing package
  • Allows the programmer to create a window
  • setDefaultCloseOperation method
  • Pass JFrame.EXIT_ON_CLOSE as its argument to set
    the application to terminate when the user closes
    the window
  • add method
  • Attaches a JPanel to the JFrame
  • setSize method
  • Sets the width (first argument) and height
    (second argument) of the JFrame

9
Liniju zimešana V
Import the JFrame class from the javax.swing class
Create DrawPanel and JFrame objects
Set the application to terminate when the user
closes the window
Add the DrawPanel to the JFrame
Set the size of and display the JFrame
10
Liniju zimešana VI
11
Figuru (cetrsturu un ovalu) zimešana I
  • Draw rectangles
  • Method drawRect of Graphics
  • Draw ovals
  • Method drawOval of Graphics

12
Figuru (cetrsturu un ovalu) zimešana II
13
Figuru (cetrsturu un ovalu) zimešana III
14
Figuru (cetrsturu un ovalu) zimešana IV
15
Figuru (cetrsturu un ovalu) zimešana V
16
Krasas un krasainu figuru zimešana I
  • Krasas datora tiek glabatas, ka krasu trijnieki
    (RGB value (red, green, blue)).
  • katrai komponentei vertiba no 0 lidz 255
  • java.awt.Color klase satur predefinetas
    konstantes biežak lietotajam krasam
  • 13 predefineti static Color objekti
  • Color.Black, Coor.BLUE, Color.CYAN,
    Color.DARK_GRAY, Color.GRAY, Color.GREEN,
    Color.LIGHT_GRAY, Color.MAGENTA, Color.ORANGE,
    Color.PINK, Color.RED, Color.WHITE and
    Color.YELLOW
  • Ir pieejams ari klases konstruktors
  • public Color(int r, int g, int b)

17
Krasas un krasainu figuru zimešana II
  • Lai zimetu krasainas figuras varam lietot klases
    Graphics metodes fillRect un fillOval
  • Darbojas lidzigi ka drawRect un drawOval tikai
    papildus aizpilda cetrsturus un ovalus ar krasu
  • Pirmie divi parametri specifice augšejo kreiso
    sturi un pedejie divi nosaka platumu un augstumu
  • Klases Graphics setColor metode
  • Iestada tekošo krasu

18
Import Color class
19
(No Transcript)
20
Krasas un krasainu figuru zimešana III
  • A bulls-eye with two alternating, random colors
  • Randomly generated shapes.

21
Krasainu loku zimešana I
  • Piemera tiek demonstrets ka uzzimet varaviksni
  • Tiek demonstretas sekojošas lietas
  • Masivu lietojums
  • Klases Graphics metodes fillArc lietojums

22
Krasainu loku zimešana II
Uzstadam baltu pamatkrasu
23
Uzzime krasainu pusapli
24
Krasainu loku zimešana IV
  • Spirales zimešana izmantojot drawLine metodi
  • Spirales zimešana izmantojot drawArc metodi

25
Objektu lietošana kopa ar grafiskiem elementiem
  • To create a consistent drawing that remains the
    same each time it is drawn
  • Store information about the displayed shapes so
    that they can be reproduced exactly the same way
    each time paintComponent is called

26
Instance variables to store coordinates and color
for a line
Initialize instance variables
Draw a line in the proper color at the proper
coordinates
27
Declare a MyLine array
Create the MyLine array
28
Generate coordinates for this line
Generate a color for this line
Create the new MyLine object with the generated
attributes
Draw each MyLine
29
(No Transcript)
30
Tekstu un attelu attelošana izmantojot JLabel
klasi
  • Labels
  • Display information and instructions
  • JLabel
  • Display a single line of text
  • Display an image
  • Display both text and image

31
Declare and initialize centerLabel with a JLabel
that displays the labelIcon
32
(No Transcript)
33
Jautajumi ?
Write a Comment
User Comments (0)
About PowerShow.com