1 / 33

Modernās Programmēšanas Tehnoloģijas (Advanced Programming Technologies )

Modernās Programmēšanas Tehnoloģijas (Advanced Programming Technologies ). Edgars Celms, Mārtiņš Opmanis (askola@mii.lu.lv). Latvijas Universitātes Matemātikas un informātikas institūts 200 7, Rīga, Latvija. Ievads GUI (Graphical User Interface). “ Java ™ How to Program, Sixth Edition ”

paniz
Télécharger la présentation

Modernās Programmēšanas Tehnoloģijas (Advanced Programming Technologies )

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Modernās Programmēšanas Tehnoloģijas(Advanced Programming Technologies) Edgars Celms, Mārtiņš Opmanis (askola@mii.lu.lv) Latvijas Universitātes Matemātikas un informātikas institūts 2007,Rīga, 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 – līniju zīmēšana • 4.14. GUI and Graphics Case Study: Creating Simple Drawings • Chapter 5. Control Statements: Part II • Ievads GUI – četrstūru un ovālu zīmēšana • 5.10. (Optional) GUI and Graphics Case Study: Drawing Rectangles and Ovals • Chapter 6. Methods: A Deeper Look • Ievads GUI – krāsas un krāsainas figūras • 6.13. (Optional) GUI and Graphics Case Study: Colors and Filled Shapes • Chapter 7. Arrays • Ievads GUI – loku zīmēšana • 7.13. (Optional) GUI and Graphics Case Study: Drawing Arcs • Chapter 8. Classes and Objects: A Deeper Look • Ievads GUI – objektu lietošana kopā ar grafiskiem elementiem • 8.18. (Optional) GUI and Graphics Case Study: Using Objects with Graphics • Chapter 9. Object-Oriented Programming: Inheritance • Ievads GUI – tekstu un attēlu attēlošana izmantojot JLabel klasi • 9.8. (Optional) GUI and Graphics Case Study: Displaying Text and Images Using Labels

  3. Dialogu logu lietojums I • Pakotne (package) javax.swing • Satur klases ar kuru palīdzību var veidot GUI • Klase javax.swing.JOptionPane • Satur statisku (static) metodi showMessageDialog • tiek izmantota, lai izspīdinātu ziņojuma logu (message box) • Satur statisku metodi showInputDialog • tiek izmantota, lai dotu iespēju lietotājam ievadīt kādu informāciju

  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. Līniju zīmēšana I • Javas koordinātu sistēma • Tiek definēta izmantojot x un y koordinātas • Tiek sauktas arī par horizontālām un vertikālām koordinātām • Are measured along the x-axis and y-axis • Koordinātu mērvienība ir pikselis (pixel) • Klase Graphicsno java.awt pakotnes • Nodrošina metodes lai varētu zīmēt figūras un grafiski attēlot tekstuālu informāciju • Klase JPanelnojavax.swingpakotnes • Nodrošina laukumu uz kura zīmēt

  6. Līniju zīmēš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. Līniju zīmēš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 JPanel’s width and height Draw the two lines

  8. Līniju zīmēš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. Līniju zīmēš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. Līniju zīmēšana VI

  11. Figūru (četrstūru un ovālu) zīmēšana I • Draw rectangles • Method drawRect of Graphics • Draw ovals • Method drawOval of Graphics

  12. Figūru (četrstūru un ovālu) zīmēšana II

  13. Draw rectangles Draw ovals Figūru (četrstūru un ovālu) zīmēšana III

  14. Figūru (četrstūru un ovālu) zīmēšana IV

  15. Figūru (četrstūru un ovālu) zīmēšana V

  16. Krāsas un krāsainu figūru zīmēšana I • Krāsas datorā tiek glabātas, kā krāsu trijnieki (RGB value (red, green, blue)). • katrai komponentei vērtība no 0 līdz 255 • java.awt.Colorklase satur predefinētas konstantes biežāk lietotajām krāsām • 13 predefinētistaticColor 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 arī klases konstruktors • public Color(int r, int g, int b)

  17. Krāsas un krāsainu figūru zīmēšana II • Lai zīmētu krāsainas figūras varam lietot klases Graphicsmetodes fillRectunfillOval • Darbojas līdzīgi kā drawRectun drawOvaltikai papildus aizpilda četrstūrus un ovālus ar krāsu • Pirmie divi parametri specificē augšējo kreiso stūri un pēdējie divi nosaka platumu un augstumu • Klases GraphicssetColormetode • Iestāda tekošo krāsu

  18. Import Color class

  19. Krāsas un krāsainu figūru zīmēšana III • A bull’s-eye with two alternating, random colors • Randomly generated shapes.

  20. Krāsainu loku zīmēšana I • Piemērā tiek demonstrēts kā uzzīmēt varavīksni • Tiek demonstrētas sekojošas lietas • Masīvu lietojums • Klases Graphics metodes fillArclietojums

  21. Krāsainu loku zīmēšana II Uzstādam baltu pamatkrāsu

  22. Uzzīmē krāsainu pusapli

  23. Krāsainu loku zīmēšana IV • Spirāles zīmēšana izmantojot drawLinemetodi • Spirāles zīmēšana izmantojot drawArcmetodi

  24. Objektu lietošana kopā 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

  25. Instance variables to store coordinates and color for a line Initialize instance variables Draw a line in the proper color at the proper coordinates

  26. Declare a MyLine array Create the MyLine array

  27. Generate coordinates for this line Generate a color for this line Create the new MyLine object with the generated attributes Draw each MyLine

  28. Tekstu un attēlu attēlošana izmantojot JLabel klasi • Labels • Display information and instructions • JLabel • Display a single line of text • Display an image • Display both text and image

  29. Change the text the southLabel displays Create a JLabel that displays the string “North” ImageIcon constructor argument specifies the path to the image Declare and initialize centerLabel with a JLabel that displays the labelIcon

  30. Attach the labels to the JFrame at north, center and south

  31. Jautājumi ?

More Related