Advertisement
Guest User

Untitled

a guest
May 20th, 2014
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.17 KB | None | 0 0
  1. import java.awt.BorderLayout;
  2. import java.awt.Dimension;
  3. import java.awt.Graphics;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6. import java.awt.event.KeyEvent;
  7. import java.awt.image.BufferedImage;
  8. import java.io.BufferedReader;
  9. import java.io.IOException;
  10. import java.io.InputStreamReader;
  11. import java.net.MalformedURLException;
  12. import java.net.URL;
  13. import java.net.URLConnection;
  14. import java.util.ArrayList;
  15. import java.util.StringTokenizer;
  16.  
  17. import javax.imageio.IIOException;
  18. import javax.imageio.ImageIO;
  19. import javax.swing.JButton;
  20. import javax.swing.JFrame;
  21. import javax.swing.JMenuBar;
  22. import javax.swing.JMenuItem;
  23. import javax.swing.JPanel;
  24. import javax.swing.JSplitPane;
  25. import javax.swing.JTextField;
  26. import javax.swing.Timer;
  27.  
  28.  
  29. public class Icons  extends JPanel {
  30.  
  31.    static final boolean big = true;
  32.    String type = big ? "obj_big" : "obj_sprite";
  33.    int size = big ? 80 : 40;
  34.    int perrow = big ? 14 : 30;
  35.    static final Dimension d2 = new Dimension(500,380);
  36.    static final JTextField input = new JTextField("14316");
  37.    static final JSplitPane sp = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
  38.    private final JFrame frame = new JFrame("Stuff");
  39.    private ArrayList<String> intSeq = new ArrayList<String>();
  40.    private String name;
  41.    static final JButton start = new JButton("Go");
  42.    public static void main(String[] args) throws IOException
  43.    {
  44.       final Icons f = new Icons();
  45.       f.getSeq("55");
  46.       f.setVisible(true);
  47.       f.repaint();
  48.       f.print();
  49.       final Timer timer = new Timer(30, new ActionListener(){
  50.  
  51.          public void actionPerformed(ActionEvent e) {
  52.              f.repaint();
  53.          }});
  54.      timer.start();
  55.    }
  56.    
  57.    public Icons() {
  58.       frame.add(sp);
  59.       sp.setTopComponent(this);
  60.       frame.add(sp);
  61.       JPanel frame2 = new JPanel();
  62.       this.setPreferredSize(d2);
  63.       this.setMinimumSize(d2);
  64.       start.addActionListener(new ActionListener(){
  65.  
  66.          public void actionPerformed(ActionEvent arg0) {
  67.              input.setText(input.getText().replaceAll("[^0-9,-]","").replaceAll("(-|,){2,}","$1"));
  68.              String inputValue = input.getText();
  69.              try {
  70.                getSeq(inputValue);
  71.             } catch (IOException e) {
  72.                // TODO Auto-generated catch block
  73.                e.printStackTrace();
  74.             }
  75.          }});
  76.       start.setMnemonic(KeyEvent.VK_C);
  77.       frame2.add(start);
  78.       frame2.add(input, BorderLayout.SOUTH);
  79.       sp.setBottomComponent(frame2);
  80.       frame.setMinimumSize(new Dimension(1200,580));
  81.    }
  82.    
  83.    public void setVisible(boolean arg) {
  84.       frame.setVisible(arg);
  85.    }
  86.    
  87.    public void getSeq(String integers) throws IOException {
  88.       StringTokenizer split = new StringTokenizer(integers, ",");
  89.       intSeq.clear();
  90.       while (split.hasMoreElements()) {
  91.          String next = (String) split.nextElement();
  92.          if (next.contains("-")) {
  93.             int loc = next.indexOf('-');
  94.             int start = Integer.parseInt(next.substring(0,loc));
  95.             int end = Integer.parseInt(next.substring(loc+1));
  96.             for (int i = start; i <= end; i++)
  97.                intSeq.add(Integer.toString(i));
  98.          }
  99.          else
  100.             intSeq.add(next);
  101.       }
  102.       setFiles();
  103.    }
  104.    
  105.    private ArrayList<BufferedImage> iconList = new ArrayList<BufferedImage>();
  106.    public void paint(Graphics g)
  107.    {      
  108.        g.clearRect(0, 0, getWidth(), getHeight());
  109.        for (int i = 0; i < iconList.size(); i++)
  110.           g.drawImage(iconList.get(i),size * (i % perrow), size * (i / perrow)+5,null);
  111.        }
  112.    
  113.    public void setFiles() throws MalformedURLException, IOException
  114.    {
  115.       iconList.clear();
  116.       String runedate = getRuneDate();
  117.       for (String i : intSeq) {
  118.          //obj_sprite.gif for inv
  119.          //obj_big.gif for dii
  120.            try {
  121.               iconList.add(ImageIO.read(new URL("https://secure.runescape.com/l=0/a=0/m=itemdb_rs/"+runedate+"_"+type+".gif?id="+i)));
  122.            } catch (IIOException e) {}
  123.       repaint();
  124.       }
  125.    }
  126.    
  127.    public void print() {
  128.       int h = 0;
  129.       for (String i : intSeq) {
  130.          System.out.println(i + "; " + iconList.get(h));
  131.          h++;
  132.       }
  133.    }
  134.    
  135.    public void addMenu()
  136.    {
  137.        JMenuBar menu = new JMenuBar();
  138.        frame.setJMenuBar(menu);
  139.        JMenuItem newSeq = new JMenuItem("New Sequence");
  140.        newSeq.addActionListener(new ActionListener(){
  141.  
  142.            public void actionPerformed(ActionEvent arg0) {
  143.                    
  144.            }});
  145.        menu.add(newSeq);
  146.    }
  147.    
  148.    public String getRuneDate() throws IOException {
  149.       URL oracle;
  150.       URLConnection yc;
  151.       BufferedReader in;
  152.       String date = "";
  153.       String inputLine;
  154.       oracle = new URL("https://secure.runescape.com/m=itemdb_rs/api/info.json");
  155.       yc = oracle.openConnection();
  156.       yc.connect();
  157.       in = new BufferedReader(new InputStreamReader(
  158.               yc.getInputStream()));
  159.       while ((inputLine = in.readLine()) != null)
  160.          date = inputLine.replaceAll("\\{\"lastConfigUpdateRuneday\":(.*)\\}","$1");
  161.       return date;
  162.         }
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement