Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.BorderLayout;
- import java.awt.Dimension;
- import java.awt.Graphics;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.KeyEvent;
- import java.awt.image.BufferedImage;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.net.URLConnection;
- import java.util.ArrayList;
- import java.util.StringTokenizer;
- import javax.imageio.IIOException;
- import javax.imageio.ImageIO;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JMenuBar;
- import javax.swing.JMenuItem;
- import javax.swing.JPanel;
- import javax.swing.JSplitPane;
- import javax.swing.JTextField;
- import javax.swing.Timer;
- public class Icons extends JPanel {
- static final boolean big = true;
- String type = big ? "obj_big" : "obj_sprite";
- int size = big ? 80 : 40;
- int perrow = big ? 14 : 30;
- static final Dimension d2 = new Dimension(500,380);
- static final JTextField input = new JTextField("14316");
- static final JSplitPane sp = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
- private final JFrame frame = new JFrame("Stuff");
- private ArrayList<String> intSeq = new ArrayList<String>();
- private String name;
- static final JButton start = new JButton("Go");
- public static void main(String[] args) throws IOException
- {
- final Icons f = new Icons();
- f.getSeq("55");
- f.setVisible(true);
- f.repaint();
- f.print();
- final Timer timer = new Timer(30, new ActionListener(){
- public void actionPerformed(ActionEvent e) {
- f.repaint();
- }});
- timer.start();
- }
- public Icons() {
- frame.add(sp);
- sp.setTopComponent(this);
- frame.add(sp);
- JPanel frame2 = new JPanel();
- this.setPreferredSize(d2);
- this.setMinimumSize(d2);
- start.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent arg0) {
- input.setText(input.getText().replaceAll("[^0-9,-]","").replaceAll("(-|,){2,}","$1"));
- String inputValue = input.getText();
- try {
- getSeq(inputValue);
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }});
- start.setMnemonic(KeyEvent.VK_C);
- frame2.add(start);
- frame2.add(input, BorderLayout.SOUTH);
- sp.setBottomComponent(frame2);
- frame.setMinimumSize(new Dimension(1200,580));
- }
- public void setVisible(boolean arg) {
- frame.setVisible(arg);
- }
- public void getSeq(String integers) throws IOException {
- StringTokenizer split = new StringTokenizer(integers, ",");
- intSeq.clear();
- while (split.hasMoreElements()) {
- String next = (String) split.nextElement();
- if (next.contains("-")) {
- int loc = next.indexOf('-');
- int start = Integer.parseInt(next.substring(0,loc));
- int end = Integer.parseInt(next.substring(loc+1));
- for (int i = start; i <= end; i++)
- intSeq.add(Integer.toString(i));
- }
- else
- intSeq.add(next);
- }
- setFiles();
- }
- private ArrayList<BufferedImage> iconList = new ArrayList<BufferedImage>();
- public void paint(Graphics g)
- {
- g.clearRect(0, 0, getWidth(), getHeight());
- for (int i = 0; i < iconList.size(); i++)
- g.drawImage(iconList.get(i),size * (i % perrow), size * (i / perrow)+5,null);
- }
- public void setFiles() throws MalformedURLException, IOException
- {
- iconList.clear();
- String runedate = getRuneDate();
- for (String i : intSeq) {
- //obj_sprite.gif for inv
- //obj_big.gif for dii
- try {
- iconList.add(ImageIO.read(new URL("https://secure.runescape.com/l=0/a=0/m=itemdb_rs/"+runedate+"_"+type+".gif?id="+i)));
- } catch (IIOException e) {}
- repaint();
- }
- }
- public void print() {
- int h = 0;
- for (String i : intSeq) {
- System.out.println(i + "; " + iconList.get(h));
- h++;
- }
- }
- public void addMenu()
- {
- JMenuBar menu = new JMenuBar();
- frame.setJMenuBar(menu);
- JMenuItem newSeq = new JMenuItem("New Sequence");
- newSeq.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent arg0) {
- }});
- menu.add(newSeq);
- }
- public String getRuneDate() throws IOException {
- URL oracle;
- URLConnection yc;
- BufferedReader in;
- String date = "";
- String inputLine;
- oracle = new URL("https://secure.runescape.com/m=itemdb_rs/api/info.json");
- yc = oracle.openConnection();
- yc.connect();
- in = new BufferedReader(new InputStreamReader(
- yc.getInputStream()));
- while ((inputLine = in.readLine()) != null)
- date = inputLine.replaceAll("\\{\"lastConfigUpdateRuneday\":(.*)\\}","$1");
- return date;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement