------------------------------------------------------------------------------------------- ■ 例外表現とprivate、public 実例 --- java.awt.Colorクラスを概観してみる ------------------------------------------------------------------------------------------- package mycolor; public class Color{ //不適切な数字をクラス外から代入されないようにprivate private int red;//0〜255 private int green;//0〜255 private int blue;//0〜255 public static final Color black = new Color(0,0,0); public static final Color white = new Color(255,255,255); public Color(int red, int green, int blue){ super(); if(testColorValueRange(red, green, blue)){ this.red = red; this.green = green; this.blue = blue; } } private static boolean testColorValueRange(int red, int green, int blue){ if(0<=red && red<=255 && 0<=green && green<=255 && 0<=blue && blue<=255 ){ return true; }else{ throw new IllegalArgumentException("色調の数字は0から255の間で設定してください"); } } public static void main(String[] args){ Color c1 = new Color(-10,0,0); } }