RGarbageB

/* friendship ended with RGB scanner now crapsGame is my best friend My extra addition is the seconds counter that is displayed on screen in the boardColor method. It's a pretty weird functionality that I called. */ import java.awt.event.MouseListener; import java.awt.event.MouseEvent; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Toolkit; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import javax.swing.Timer; import java.util.ArrayList; import java.util.Iterator; import java.util.Random; import javax.swing.ImageIcon; import javax.swing.JPanel; import javax.imageio.*; import java.awt.image.*; import java.io.*; import java.util.Scanner; public class rgbBoard extends JPanel implements Runnable, MouseListener { private Dimension d; int BOARD_WIDTH=500; int BOARD_HEIGHT=500; int x = 0; private Thread animator; //RGB Values ******** STEP 1: no need to code here, just be aware of variables to use int cyan = 0; int magenta = 0; int yellow = 0; public BoardColor() { addMouseListener(this); setFocusable(true); d = new Dimension(BOARD_WIDTH, BOARD_HEIGHT); if (animator == null ) { animator = new Thread(this); animator.start(); } setDoubleBuffered(true); class MyObj { private final long createdMillis = System.currentTimeMillis(); public int getAgeInSeconds() { long nowMillis = System.currentTimeMillis(); return (int)((nowMillis - this.createdMillis) / 1000); } } } public void paint(Graphics g){ super.paint(g); g.setColor(Color.white); g.fillRect(0, 0, d.width, d.height); g.setColor(Color.black); g.drawString(" C: " + cyan + " M: " + magenta + " Y: " + yellow,10, d.height-60); Color c = new Color(red,green,blue); g.setColor(c); g.fillOval(60,230, 75, 75); g.setColor(Color.cyan); g.fillOval(10,10, 20, 20); g.setColor(Color.cyan); g.fillOval(10,50, 20, 20); g.setColor(Color.magenta); g.fillOval(100,10, 20, 20); g.setColor(Color.magenta); g.fillOval(100,50, 20, 20); g.setColor(Color.yellow); g.fillOval(200,10, 20, 20); g.setColor(Color.yellow); g.fillOval(200,50, 20, 20); Toolkit.getDefaultToolkit().sync(); g.dispose(); } public void run() { long beforeTime, timeDiff, sleep; beforeTime = System.currentTimeMillis(); int animationDelay = 500; long time = System.currentTimeMillis(); while (true) {//infinite loop // spriteManager.update(); repaint(); try { time += animationDelay; Thread.sleep(Math.max(0,time - System.currentTimeMillis())); }catch (InterruptedException e) { System.out.println(e); }//end catch }//end while loop }//end of run public void mousePressed(MouseEvent e) { int x = e.getX(); int y = e.getY(); if(x > 10 && x < 30 && y > 10 && y < 30 && red < 255) cyan += 5; if(x > 10 && x < 30 && y > 50 && y < 70 && red > 0) cyan -= 5; if(x > 100 && x < 130 && y > 10 && y < 30 && green < 255) magenta += 5; if(x > 100 && x < 130 && y > 50 && y < 70 && green > 0) magenta -= 5; if(x > 200 && x < 230 && y > 10 && y < 30 && blue < 255) yellow += 5; if(x > 200 && x < 230 && y > 50 && y < 70 && blue > 0) yellow -= 5; if(x > 200 && x < 230 && y > 240 && y < 270) { cyan = 0; magenta = 0; yellow = 0; } } public void mouseReleased(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mouseClicked(MouseEvent e) { } }//end of class

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.