Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.samkough.main;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- @SuppressWarnings("serial")
- public class Win extends JFrame implements MouseListener
- {
- private static final int WIDTH = 300;
- private static final int HEIGHT = 300;
- JPanel p1;
- public Win()
- {
- p1 = new JPanel();
- p1.setBackground(randomColor());
- add(p1);
- p1.addMouseListener(this);
- }
- // this lets us get a random color
- public Color randomColor()
- {
- int r = (int)(Math.random()*256);
- int g = (int)(Math.random()*256);
- int b = (int)(Math.random()*256);
- return(new Color(r,g,b));
- }
- public void mouseClicked(MouseEvent e)
- {
- p1.setBackground(randomColor());
- }
- public void mouseEntered(MouseEvent e)
- {
- }
- public void mouseExited(MouseEvent e)
- {
- }
- public void mousePressed(MouseEvent e)
- {
- }
- public void mouseReleased(MouseEvent e)
- {
- }
- public static void main(String args[])
- {
- Win frame = new Win();
- frame.setVisible(true);
- frame.setSize(WIDTH, HEIGHT);
- // frame.pack();
- frame.setTitle("Random Coloring Panel");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setLocationRelativeTo(null);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement