swing:color

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

swing:color [2015/05/05 13:03]
gthanos
swing:color [2016/02/26 11:15]
Line 1: Line 1:
-====== Η κλάση Color ====== 
  
-Η κλάση [[https://​docs.oracle.com/​javase/​7/​docs/​api/​java/​awt/​Color.html|Color]] δίνει την δυνατότητα να ορίσετε χρώματα στο //​background//,​ το //​foreground//​ ή τα //borders// των αντικειμένων που χρησιμοποιείτε. Για παράδειγμα αν θέλετε να ορίσετε το χρώμα στο background αντικειμένων του τύπου [[http://​docs.oracle.com/​javase/​7/​docs/​api/​javax/​swing/​JComponent.html|JComponent]] (π.χ. JPanel, JMenu, JButton, JLabel) μπορείτε να το κάνετε με χρήση της μεθόδου 
-<code java> 
-public void setBackground(Color bg) 
-</​code>​ 
- 
-Για παράδειγμα,​ αν θέλετε να αλλάξετε το background color σε μπλε σε ένα παράθυρο,​ αυτό μπορείτε να το κάνετε με μία δήλωση της μορφής (υποθέτωντας ότι είστε σε μία μέθοδο ή στον κατασκευαστή της κλάσης που κληρονομεί την κλάση JFrame): 
-<code java> 
-this.getContnetPane().setBackground(Color.BLUE);​ 
-</​code>​ 
- 
-Η κλάση Color παρέχει τα παρακάτω χρώματα ως στατικές μεταβλητές τύπου Color. 
-<code java> 
-  Color.BLACK 
-  Color.BLUE 
-  Color.CYAN 
-  Color.DARK_GRAY 
-  Color.GRAY 
-  Color.GREEN 
-  Color.LIGHT_GRAY 
-  Color.MAGENTA 
-  Color.ORANGE 
-  Color.PINK 
-  Color.RED 
-  Color.WHITE 
-  Color.YELLOW 
-</​code>​ 
- 
-Αν θέλετε να ορίσετε τα δικά σας αντικείμενα τύπου Color μπορείτε να το κάνετε με ένα από τους ​ παρακάτω [[https://​docs.oracle.com/​javase/​7/​docs/​api/​java/​awt/​Color.html#​constructor_summary|κατασκευαστές]]. 
-<code java> 
-Color(ColorSpace cspace, float[] components, float alpha) 
-Creates a color in the specified ColorSpace with the color components specified in the float array and the specified alpha. 
-------------------------------------------------------------------------- 
-Color(float r, float g, float b) 
-Creates an opaque sRGB color with the specified red, green, and blue values in the range (0.0 - 1.0). 
-------------------------------------------------------------------------- 
-Color(float r, float g, float b, float a) 
-Creates an sRGB color with the specified red, green, blue, and alpha values in the range (0.0 - 1.0). 
-------------------------------------------------------------------------- 
-Color(int rgb) 
-Creates an opaque sRGB color with the specified combined RGB value consisting of the red component in bits 16-23, the green component in bits 8-15, and the blue component in bits 0-7. 
-------------------------------------------------------------------------- 
-Color(int rgba, boolean hasalpha) 
-Creates an sRGB color with the specified combined RGBA value consisting of the alpha component in bits 24-31, the red component in bits 16-23, the green component in bits 8-15, and the blue component in bits 0-7. 
-------------------------------------------------------------------------- 
-Color(int r, int g, int b) 
-Creates an opaque sRGB color with the specified red, green, and blue values in the range (0 - 255). 
-------------------------------------------------------------------------- 
-Color(int r, int g, int b, int a) 
-Creates an sRGB color with the specified red, green, blue, and alpha values in the range (0 - 255). 
- 
-</​code>​ 
swing/color.txt · Last modified: 2016/02/26 11:15 (external edit)