Title: Modernas Programme
1Modernas Programmešanas Tehnologijas (Advanced
Programming Technologies)
- Edgars Celms, Martinš Opmanis
- (askola_at_mii.lu.lv)
Latvijas Universitates Matematikas un
informatikas instituts 2007, Riga, Latvija
2Ievads 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
3Dialogu 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
4Dialogu 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)
5Liniju 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
6Liniju 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
7Liniju 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
8Liniju 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
9Liniju 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
10Liniju zimešana VI
11Figuru (cetrsturu un ovalu) zimešana I
- Draw rectangles
- Method drawRect of Graphics
- Draw ovals
- Method drawOval of Graphics
12Figuru (cetrsturu un ovalu) zimešana II
13Figuru (cetrsturu un ovalu) zimešana III
14Figuru (cetrsturu un ovalu) zimešana IV
15Figuru (cetrsturu un ovalu) zimešana V
16Krasas 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)
17Krasas 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
18Import Color class
19(No Transcript)
20Krasas un krasainu figuru zimešana III
- A bulls-eye with two alternating, random colors
- Randomly generated shapes.
21Krasainu loku zimešana I
- Piemera tiek demonstrets ka uzzimet varaviksni
- Tiek demonstretas sekojošas lietas
- Masivu lietojums
- Klases Graphics metodes fillArc lietojums
22Krasainu loku zimešana II
Uzstadam baltu pamatkrasu
23Uzzime krasainu pusapli
24Krasainu loku zimešana IV
- Spirales zimešana izmantojot drawLine metodi
- Spirales zimešana izmantojot drawArc metodi
25Objektu 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
26Instance variables to store coordinates and color
for a line
Initialize instance variables
Draw a line in the proper color at the proper
coordinates
27Declare a MyLine array
Create the MyLine array
28Generate 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)
30Tekstu 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
31Declare and initialize centerLabel with a JLabel
that displays the labelIcon
32(No Transcript)
33Jautajumi ?