Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.Frame;
- import java.awt.Graphics;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
- public class DataOrganizer extends Frame implements MouseListener{
- private Buttons randomButton, maxButton, minButton, removeButton;
- private final int BUTTON_WIDTH = 96;
- private final int BUTTON_HEIGHT = 32;
- private Item highlighted = new Item(0,0,0);
- private int x, y;
- private DataCollection data = new DataCollection();
- public DataOrganizer(){
- System.out.println("I don't really know what goes here yet");
- // Window Initialization
- setSize(1024, 350);
- setTitle("Program 01");
- setResizable(false);
- CloseWindow window = new CloseWindow();
- setBackground(Color.GRAY);
- addWindowListener(window);
- setVisible(true);
- // MouseListener to search for mouse input
- addMouseListener(this);
- // Constructors for buttons
- randomButton = new Buttons("Randomize", Color.green, 50, 100, BUTTON_WIDTH, BUTTON_HEIGHT);
- maxButton = new Buttons("Maximum", Color.yellow, 50, 150, BUTTON_WIDTH, BUTTON_HEIGHT);
- minButton = new Buttons("Minimum", Color.orange, 50, 200, BUTTON_WIDTH, BUTTON_HEIGHT);
- removeButton = new Buttons("Remove", Color.red, 50, 250, BUTTON_WIDTH, BUTTON_HEIGHT);
- }
- public void paint(Graphics pane){
- // Null checks for buttons
- if (randomButton != null)
- randomButton.paint(pane);
- if (maxButton != null)
- maxButton.paint(pane);
- if (minButton != null)
- minButton.paint(pane);
- if (removeButton != null)
- removeButton.paint(pane);
- if (data != null)
- showGraphs(pane);
- }
- public void showGraphs(Graphics pane){
- data.reset();
- while (data.hasNext()== true){
- data.next().paint(pane);
- }
- if (highlighted!=null)
- data.reset(highlighted);
- }
- @Override
- public void mouseClicked(MouseEvent e) {
- // TODO Auto-generated method stub
- }
- @Override
- public void mouseEntered(MouseEvent e) {
- // TODO Auto-generated method stub
- }
- @Override
- public void mouseExited(MouseEvent e) {
- // TODO Auto-generated method stub
- }
- @Override
- public void mousePressed(MouseEvent e) {
- // TODO Auto-generated method stub
- x = e.getX();
- y = e.getY();
- if (randomButton.isInside(x, y)){
- randomButton.flip();
- highlighted = null;
- repaint();
- }
- if (maxButton.isInside(x, y)){
- maxButton.flip();
- repaint();
- }
- if (minButton.isInside(x, y)){
- minButton.flip();
- repaint();
- }
- if (removeButton.isInside(x, y)){
- removeButton.flip();
- highlighted = null;
- repaint();
- }
- }
- public void mouseReleased(MouseEvent e) {
- // TODO Auto-generated method stub
- if (randomButton.isInside(x, y)){
- randomButton.flip();
- System.out.println("1");
- data.randomize();
- repaint();
- }
- if (maxButton.isInside(x, y)){
- maxButton.flip();
- Item largest = new Item(0, 0,Integer.MIN_VALUE);
- for(Item currentItem; (currentItem = data.next()) != null;) {
- if (currentItem.getValue()>largest.getValue())
- largest = currentItem;
- }
- highlighted = largest;
- data.reset(largest);
- repaint();
- }
- if (minButton.isInside(x, y)){
- minButton.flip();
- Item smallest = new Item(0, 0,Integer.MAX_VALUE);
- for(Item currentItem; (currentItem = data.next()) != null;) {
- if (currentItem.getValue()<smallest.getValue())
- smallest = currentItem;
- }
- highlighted = smallest;
- data.reset(largest)
- repaint();
- }
- if (removeButton.isInside(x, y)){
- removeButton.flip();
- System.out.println("4");
- repaint();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment