Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package nl.rigault.colormix.model;
- import java.util.Observable;
- public class ColorModel extends Observable {
- private int red, green, blue;
- private static ColorModel theModel = null;
- public static ColorModel getInstance() {
- if (theModel == null) {
- theModel = new ColorModel(255,0,0);
- }
- return theModel;
- }
- private ColorModel(int r, int g, int b) {
- this.red = r;
- this.green = g;
- this.blue = b;
- }
- public void setR(int r) {
- if(this.red != r) {
- if(r<0) {
- this.red = 0;
- }
- else if (r>255) {
- this.red = 255;
- }
- else {
- this.red = r;
- }
- setChanged();
- notifyObservers();
- }
- }
- public void setG(int g) {
- if(this.green != g) {
- if(g<0) {
- this.green = 0;
- }
- else if (g>255) {
- this.green = 255;
- }
- else {
- this.green = g;
- }
- setChanged();
- notifyObservers();
- }
- }
- public void setB(int b) {
- if(this.blue != b) {
- if(b<0) {
- this.blue = 0;
- }
- else if (b>255) {
- this.blue = 255;
- }
- else {
- this.blue = b;
- }
- setChanged();
- notifyObservers();
- }
- }
- public int getR() {
- return red;
- }
- public int getG() {
- return green;
- }
- public int getB() {
- return blue;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement