// glasses1.java show many colors import java.awt.*; import java.awt.event.*; public class glasses1 extends Frame { final int width = 600; final int height = 600; glasses1() { setTitle("glasses1 see colors"); setSize(width,height); setBackground(Color.white); setForeground(Color.black); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); setVisible(true); this.addMouseListener (new mousePressHandler()); } // end glasses1 constructor public void paint(Graphics g) { int x, y, w, h, rc, gc, bc, d, dd; GraphicsEnvironment ge = GraphicsEnvironment. getLocalGraphicsEnvironment(); Font f[] = ge.getAllFonts(); x = 10; y = 30; w = 50; h = 50; rc = 255; gc = 0; bc = 0; d = 1; dd = 5; // call methods to do actual drawing Color drawColor = new Color(rc, gc, bc); // Color of object being drawn g.clearRect(0, 0, width, height); Font f12 = new Font("Courier", Font.BOLD, 12); g.setFont(f12); g.drawString(" red green blue cyan black", 10, 95); Font f16 = new Font("Courier", Font.PLAIN, 16); g.setFont(f16); g.drawString("right lens: cyan->white, red->black green,blue about same", 10, height-35); g.drawString("left lens: red ->white, green,blue,cyan->black", 10, height-55); g.drawString("both lens: white stays white. black stays black", 10, height-15); g.setColor(drawColor); g.fillRect(x, y, w, h); x = x + 50; rc = 0; gc = 255; drawColor = new Color(rc, gc, bc); g.setColor(drawColor); g.fillRect(x, y, w, h); x = x + 50; gc = 0; bc = 255; drawColor = new Color(rc, gc, bc); g.setColor(drawColor); g.fillRect(x, y, w, h); x = x + 50; gc = 255; bc = 255; drawColor = new Color(rc, gc, bc); g.setColor(drawColor); g.fillRect(x, y, w, h); x = x + 50; rc = 0; gc = 0; bc = 0; drawColor = new Color(rc, gc, bc); g.setColor(drawColor); g.fillRect(x, y, w, h); // 3D anagraph of simple cube // 170,130 470,130 // 100,200 400,200 // // 170,430 470,430 // 100,500 400,500 for(d=1; d<=dd; d++) { rc = 0; gc = 255; bc = 255; drawColor = new Color(rc, gc, bc); g.setColor(drawColor); g.drawLine(100-d,200,100-d,500); g.drawLine(400-d,200,400-d,500); g.drawLine(170-d,130,170-d,430); g.drawLine(470-d,130,470-d,430); } for(d=1; d<=dd+dd/2; d++) { g.drawLine(100-d,200,170-d,130); g.drawLine(100-d,500,170-d,430); g.drawLine(400-d,200,470-d,130); g.drawLine(400-d,500,470-d,430); } for(d=1; d<=dd; d++) { rc = 255; gc = 0; bc = 0; drawColor = new Color(rc, gc, bc); g.setColor(drawColor); g.drawLine(100+d,200,100+d,500); g.drawLine(400+d,200,400+d,500); g.drawLine(170+d,130,170+d,430); g.drawLine(470+d,130,470+d,430); } for(d=1; d<=dd+dd/2; d++) { g.drawLine(100+d,200,170+d,130); g.drawLine(100+d,500,170+d,430); g.drawLine(400+d,200,470+d,130); g.drawLine(400+d,500,470+d,430); } for(d=1; d<=dd; d++) { rc = 0; gc = 0; bc = 0; drawColor = new Color(rc, gc, bc); g.setColor(drawColor); g.drawLine(170,130+d,470,130+d); g.drawLine(100,200+d,400,200+d); g.drawLine(170,430+d,470,430+d); g.drawLine(100,500+d,400,500+d); // g.drawLine(100,200,100,500); // g.drawLine(400,200,400,500); // g.drawLine(170,130,170,430); // g.drawLine(470,130,470,430); // g.drawLine(100,200,170,130); // g.drawLine(100,500,170,430); // g.drawLine(400,200,470,130); // g.drawLine(400,500,470,430); } } // end paint class mousePressHandler extends MouseAdapter { public void mousePressed (MouseEvent e) { requestFocus(); System.out.println("press"); // debug print repaint(); System.exit(0); } } static public void main(String[] args) { new glasses1(); System.out.println("glasses1 main ending"); } // end main } // end class glasses1