Last active
January 4, 2019 20:44
-
-
Save memish/49c4b635c415b929507bccb4fc3c33fc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.swing.JFrame; | |
import javax.swing.JPanel; | |
import javax.swing.WindowConstants; | |
import java.awt.Dimension; | |
import java.awt.Graphics; | |
import java.awt.Graphics2D; | |
import java.awt.Point; | |
import java.awt.event.MouseListener; | |
import java.awt.event.MouseEvent; | |
import java.awt.Color; | |
import java.io.*; | |
import java.util.*; | |
public class DrawBarGraph { | |
private JFrame frame; | |
public DrawBarGraph() { | |
frame = new JFrame("Bar Graph"); | |
frame.setSize(600, 400); | |
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); | |
frame.setPreferredSize(frame.getSize()); | |
frame.add(new ReadFile(frame.getSize())); | |
frame.pack(); | |
frame.setVisible(true); | |
} | |
public static void main(String... argv) { | |
new DrawBarGraph(); | |
} | |
public static class ReadFile extends JPanel implements MouseListener{ | |
int startX = 0; | |
int startY = 400; | |
ArrayList<String> al = new ArrayList<String>(); | |
ArrayList<String> pnames = new ArrayList<String>(); | |
ArrayList<Integer> count = new ArrayList<Integer>(); | |
String name = "player"; | |
int amount = 1; | |
int size = 1; | |
int width = 600; | |
public ReadFile(Dimension dimension) { | |
setSize(dimension); | |
setPreferredSize(dimension); | |
addMouseListener(this); | |
try{ | |
read(); | |
}catch(Exception e){ | |
System.out.println("Problem"); | |
} | |
} | |
@Override | |
public void paintComponent(Graphics g) { | |
Graphics2D g2 = (Graphics2D)g; | |
Dimension d = getSize(); | |
g2.drawString(name + " " + amount, 10, 30); | |
if(count.size()>0) | |
size = (width/count.size()); | |
//printArray(size + " " + width + " " + count.size()); | |
g2.fillRect(10,10,10,10); | |
startX = 0; | |
startY = 200; | |
System.out.println("Paint"+ name); | |
for(int j=0; j<count.size(); j++){ | |
g2.setColor(new Color(255, 0, 0) ); | |
int spot = 200-count.get(j); | |
g2.fillRect(startX,spot,size,count.get(j)); | |
startX += size; | |
} | |
} | |
public void read()throws IOException{ | |
BufferedReader f = new BufferedReader(new FileReader("nba.csv")); | |
String s; | |
while ((s=f.readLine())!=null){ | |
// System.out.println(s); | |
al.add(s); | |
} | |
for(int i=0; i<al.size(); i++){ | |
String[] s1 = al.get(i).split(",");//split up each line | |
//players name s1[1] | |
//determine how many times each name appears in the data | |
//how can we do this? | |
/* */ | |
} | |
//find the highest | |
// int max = count.get(0); | |
int spot = 0; | |
// System.out.println("Most Frequent: " + pnames.get(spot)); | |
//get rid of all low counts | |
//remove if not more than 9 times | |
System.out.println(count.size()); | |
repaint(); | |
} | |
public void mousePressed(MouseEvent e) { | |
int x = e.getX(); | |
int y = e.getY(); | |
repaint(); | |
} | |
public void mouseReleased(MouseEvent e) { | |
} | |
public void mouseEntered(MouseEvent e) { | |
} | |
public void mouseExited(MouseEvent e) { | |
} | |
public void mouseClicked(MouseEvent e) { | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment