Skip to content

Instantly share code, notes, and snippets.

@memish
Last active January 4, 2019 21:18
Show Gist options
  • Save memish/57b751af8b40d043970d908cb750dbf9 to your computer and use it in GitHub Desktop.
Save memish/57b751af8b40d043970d908cb750dbf9 to your computer and use it in GitHub Desktop.
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 BarGraph {
private JFrame frame;
public BarGraph() {
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 BarGraph();
}
public static class ReadFile extends JPanel implements MouseListener{
String name = " NBA";
ArrayList<String> stats = new ArrayList<String>();
ArrayList<String> pnames = new ArrayList<String>();
ArrayList<Integer> count = new ArrayList<Integer>();
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("player: " + name, 10, 30);
}
public void read()throws IOException{
BufferedReader f = new BufferedReader(new FileReader("nba.csv"));
String s;
while ((s=f.readLine())!=null){
// System.out.println(s);
stats.add(s);
}
name = "stats: " + stats.get(0);
repaint();
/*
for(int i=0; i<stats.size(); i++){
String[] s1 = stats.get(i).split(",");
//players name s1[1]
boolean found = false;
for(int j=0; j<pnames.size(); j++){
if(pnames.get(j).equals(s1[1])){
count.set(j,count.get(j)+1);
found = true;
}
}
if(found==false){
pnames.add(s1[1]);
count.add(1);
}
}
//find the highest
int max = count.get(0);
int spot = 0;
for(int i=0; i<count.size(); i++){
if(count.get(i)>max){
max = count.get(i);
spot = i;
}
}
name = pnames.get(spot);
*/
}
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