Guest User

Jframe

a guest
Aug 24th, 2013
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.78 KB | None | 0 0
  1. import sign.signlink;
  2. import java.net.*;
  3. import java.awt.*;
  4. import java.awt.event.ActionListener;
  5. import java.awt.event.ActionEvent;
  6. import javax.swing.*;
  7. import javax.swing.plaf.metal.MetalLookAndFeel;
  8.  
  9. import java.io.File;
  10. import java.io.IOException;
  11. import java.awt.event.*;
  12. import javax.imageio.ImageIO;
  13. import java.awt.image.BufferedImage;
  14. import javax.swing.filechooser.FileFilter;
  15. import java.io.FileOutputStream;
  16. import java.text.SimpleDateFormat;
  17. import java.awt.image.*;
  18. import java.io.*;
  19. import javax.imageio.*;
  20. import java.awt.*;
  21.  
  22.  
  23. public class Jframe extends client implements ActionListener {
  24.  
  25. private static Item menuItem;
  26. public static JFrame frame;
  27. public static JPanel gamePanel;
  28. public static TrayIcon trayIcon;
  29.  
  30. public void setTray() {
  31. if (SystemTray.isSupported()) {
  32. Image icon = Toolkit.getDefaultToolkit().getImage("C:/.hack3rClient/sprites/cursors/icon.png");
  33. trayIcon = new TrayIcon(icon, "Legacy One");
  34. trayIcon.setImageAutoSize(true);
  35. try {
  36. SystemTray tray = SystemTray.getSystemTray();
  37. tray.add(trayIcon);
  38. trayIcon.displayMessage("Legacy One", "Legacy One has been launched!", TrayIcon.MessageType.INFO);
  39. PopupMenu menu = new PopupMenu();
  40. final MenuItem minimizeItem = new MenuItem("Hide Legacy One");
  41. MenuItem BLANK = new MenuItem("-");
  42. MenuItem exitItem = new MenuItem("Quit");
  43. menu.add(minimizeItem);
  44. menu.add(BLANK);
  45. menu.add(exitItem);
  46. trayIcon.setPopupMenu(menu);
  47. ActionListener minimizeListener = new ActionListener() {
  48. public void actionPerformed(ActionEvent e) {
  49. if(frame.isVisible()) {
  50. frame.setVisible(false);
  51. minimizeItem.setLabel("Show 1# Legacy One.");
  52. } else {
  53. frame.setVisible(true);
  54. minimizeItem.setLabel("Hide 1# Legacy One");
  55. }
  56. }
  57. };
  58. minimizeItem.addActionListener(minimizeListener);
  59. ActionListener exitListener = new ActionListener() {
  60. public void actionPerformed(ActionEvent e) {
  61. System.exit(0);
  62. }
  63. };
  64. exitItem.addActionListener(exitListener);
  65. } catch (AWTException e) {
  66. System.err.println(e);
  67. }
  68. }
  69. }
  70.  
  71. public static void setCursor(client client, int id) {
  72. Toolkit toolkit = Toolkit.getDefaultToolkit();
  73. Cursor cursor = toolkit.createCustomCursor(toolkit.getImage("C:/.hack3rClient/Sprites/Cursors/Cursor "+id+".PNG"), new Point(0,0), "C:/.hack3rClient/Sprites/Cursors/Cursor "+id+".PNG");
  74. //Cursor cursor = toolkit.createCustomCursor(toolkit.getImage("Cursors/Cursor "+id+".PNG"), new Point(0,0), ".Cursor/Cursor "+id+".PNG");
  75. frame.setCursor(cursor);
  76. // client.gameFrame.setCursor(cursor);
  77. }
  78.  
  79. public void actionPerformed(ActionEvent evt) {
  80. String cmd = evt.getActionCommand();
  81. try {
  82. if (cmd != null) {
  83. if (cmd.equalsIgnoreCase("Screenshot")) {
  84. screeny();
  85. }
  86. if (cmd.equalsIgnoreCase("Exit")) {
  87. System.exit(0);
  88. }
  89. if (cmd.equalsIgnoreCase("View Images")) {
  90. if(Desktop.isDesktopSupported()) {
  91. //if(Desktop.getDesktop().isSupported(Action.OPEN)) {
  92. Desktop.getDesktop().open(new File("C:/.hack3rClient/Scre"));
  93. //}
  94. }
  95. }
  96. if (cmd.equalsIgnoreCase("Toggle 10x Damage"))
  97. {
  98. newDamage = true;
  99. }
  100. if (cmd.equalsIgnoreCase("Untoggle 10x Damage"))
  101. {
  102. newDamage = false;
  103. }
  104. if (cmd.equalsIgnoreCase("Website"))
  105. {
  106. openUpWebSite("http://www.legacy-one.org");
  107. }
  108. if (cmd.equalsIgnoreCase("Forums"))
  109. {
  110. openUpWebSite("http://www.legacy-one.org/index");
  111. }
  112. if (cmd.equalsIgnoreCase("Vote")) {
  113. openUpWebSite("http://www.legacy-one.org/vote/");
  114. }
  115. if (cmd.equalsIgnoreCase("Donate")) {
  116. openUpWebSite("http://www.legacy-one.org/index");
  117. }
  118. if (cmd.equalsIgnoreCase("Highscores")) {
  119. openUpWebSite("http://www.legacy-one.org");
  120. }
  121. if (cmd.equalsIgnoreCase("YouTube")) {
  122. openUpWebSite("http://youtube.com/8558sebi123");
  123. }
  124. if (cmd.equalsIgnoreCase("Guides")) {
  125. openUpWebSite("http://www.legacy-one.org/index/guides");
  126. }
  127. if (cmd.equalsIgnoreCase("Support")) {
  128. openUpWebSite("http://legacy-one.org/support");
  129. JOptionPane.showMessageDialog(this, "A link to our support center on our forums has Popped up. Please create a new thread!", "Client Support", JOptionPane.INFORMATION_MESSAGE);
  130. }
  131. if (cmd.equalsIgnoreCase("Client Information")){
  132. JOptionPane.showMessageDialog(this, "Legacy One is Developed By Seb. We hope you enjoy the server!", "Client Updates", JOptionPane.INFORMATION_MESSAGE);
  133. }
  134. if (cmd.equalsIgnoreCase("World Map")){
  135. launchURL("3. WorldMap.jar");
  136. }
  137. if (cmd.equalsIgnoreCase("Item Search")){
  138. launchURL("1. ItemList.bat");
  139. }
  140. if (cmd.equalsIgnoreCase("Screenshot")) {
  141. takeScreenshot(true);
  142. }
  143. }
  144. } catch (Exception e) {
  145. }
  146. }
  147.  
  148.  
  149. public void takeScreenshot(boolean flag)
  150. {
  151. BufferedImage bufferedimage;
  152. try
  153. {
  154. Robot robot = new Robot();
  155. Point point = getLocationOnScreen();
  156. Rectangle rectangle = new Rectangle(point.x, point.y, getWidth(), getHeight());
  157. bufferedimage = robot.createScreenCapture(rectangle);
  158. }
  159. catch(Throwable throwable)
  160. {
  161. JOptionPane.showMessageDialog(frame, "An error occured while trying to create a screenshot!", "Screenshot Error", 0);
  162. return;
  163. }
  164. String s = null;
  165. try
  166. {
  167. s = getNearestScreenshotFilename();
  168. }
  169. catch(IOException ioexception)
  170. {
  171. if(flag)
  172. {
  173. JOptionPane.showMessageDialog(frame, "A screenshot directory does not exist, and could not be created!", "No Screenshot Directory", 0);
  174. return;
  175. }
  176. }
  177. if(s == null && flag)
  178. {
  179. JOptionPane.showMessageDialog(frame, "There are too many screenshots in the screenshot directory!\n"+"Delete some screen\n" +"shots and try again." , "Screenshot Directory Full", 0);
  180. return;
  181. }
  182. if(!flag)
  183. {
  184. final JFileChooser fileChooser = new JFileChooser();
  185. final JDialog fileDialog = createFileChooserDialog(fileChooser, "Save Screenshot", this);
  186. final BufferedImage si = bufferedimage;
  187. JFileChooser _tmp = fileChooser;
  188. fileChooser.setFileSelectionMode(0);
  189. fileChooser.addChoosableFileFilter(new imageFileFilter());
  190. fileChooser.setCurrentDirectory(new File("C:/.hack3rClient/Scre/"));
  191. fileChooser.setSelectedFile(new File(s));
  192. JFileChooser _tmp1 = fileChooser;
  193. fileChooser.setDialogType(1);
  194. fileChooser.addActionListener(new ActionListener() {
  195.  
  196. public void actionPerformed(ActionEvent actionevent)
  197. {
  198. String s1 = actionevent.getActionCommand();
  199. if(s1.equals("ApproveSelection"))
  200. {
  201. File file = fileChooser.getSelectedFile();
  202. if(file != null && file.isFile())
  203. {
  204. int i = JOptionPane.showConfirmDialog(frame, (new StringBuilder()).append(file.getAbsolutePath()).append(" already exists.\n"+"Do you want to replace it?").toString(), "Save Screenshot", 2);
  205. if(i != 0)
  206. {
  207. return;
  208. }
  209. }
  210. try
  211. {
  212. ImageIO.write(si, "png", file);
  213. //client.pushMessage("Screenshot taken.", 3, "@blu@ Client");
  214. //JOptionPane.showMessageDialog(frame,"Screenshot Taken");
  215. }
  216. catch(IOException ioexception2)
  217. {
  218. JOptionPane.showMessageDialog(frame, "An error occured while trying to save the screenshot!\n"+"Please make sure you have\n"+" write access to the screenshot directory." , "Screenshot Error", 0);
  219. }
  220. fileDialog.dispose();
  221. } else
  222. if(s1.equals("CancelSelection"))
  223. {
  224. fileDialog.dispose();
  225. }
  226. }
  227.  
  228.  
  229. {
  230.  
  231. }
  232. });
  233. fileDialog.setVisible(true);
  234. } else
  235. {
  236. try
  237. {
  238. ImageIO.write(bufferedimage, "png", new File((new StringBuilder()).append("C:/.hack3rClient/Scre/").append(s).toString()));
  239. JOptionPane.showMessageDialog(frame, "Image has been saved to C:/.hack3rclient/Scre. You can view your images by pushing File>View Images in the menu dropdowns." , "Screenshot manager", JOptionPane.INFORMATION_MESSAGE);
  240. //client.pushMessage("Screenshot taken.", 3, "@cr2@ Client");
  241. //JOptionPane.showMessageDialog(frame,"Screenshot taken.");
  242. }
  243. catch(IOException ioexception1)
  244. {
  245. JOptionPane.showMessageDialog(frame, "An error occured while trying to save the screenshot!\n"+"Please make sure you have\n"+" write access to the screenshot directory." , "Screenshot Error", 0);
  246. }
  247. }
  248. }
  249.  
  250. public static String getNearestScreenshotFilename()
  251. throws IOException
  252. {
  253. File file = new File("C:/.hack3rClient/Scre/");
  254. int i = 0;
  255. do
  256. {
  257. String s = " .png";
  258. if(i < 10)
  259. {
  260. s = s.replaceFirst(" ", (new StringBuilder()).append("000").append(i).toString());
  261. } else
  262. if(i < 100)
  263. {
  264. s = s.replaceFirst(" ", (new StringBuilder()).append("00").append(i).toString());
  265. } else
  266. if(i < 1000)
  267. {
  268. s = s.replaceFirst(" ", (new StringBuilder()).append("0").append(i).toString());
  269. } else
  270. if(i < 10000)
  271. {
  272. s = s.replaceFirst(" ", (new StringBuilder()).append(" ").append(i).toString());
  273. }
  274. if((new File(file, s)).isFile())
  275. {
  276. i++;
  277. } else
  278. {
  279. return s;
  280. }
  281. } while(i < 10000);
  282. return null;
  283. }
  284.  
  285.  
  286.  
  287. class imageFileFilter extends FileFilter
  288. {
  289.  
  290. imageFileFilter()
  291. {
  292. }
  293.  
  294. public boolean accept(File file)
  295. {
  296. String s = file.getName();
  297. return file.isDirectory() || s.toLowerCase().endsWith(".png") && s.indexOf("$") == -1;
  298. }
  299.  
  300. public String getDescription()
  301. {
  302. return "PNG (*.png)";
  303. }
  304. }
  305.  
  306.  
  307.  
  308. public Jframe(String args[]) {
  309. super();
  310. try {
  311. sign.signlink.startpriv(InetAddress.getByName(serverip));
  312. initUI();
  313. setTray();
  314. } catch (Exception ex) {
  315. ex.printStackTrace();
  316. }
  317. }
  318.  
  319. public void initUI() {
  320. try {
  321. UIManager.setLookAndFeel("org.jvnet.substance.skin.SubstanceMetalLookAndFeel");
  322. JPopupMenu.setDefaultLightWeightPopupEnabled(true);
  323. frame = new JFrame("Legacy One");
  324. JButton screenshot = new JButton("Screenshot");
  325. screenshot.setActionCommand("Screenshot");
  326. screenshot.addActionListener(this);
  327. frame.setIconImage(Toolkit.getDefaultToolkit().getImage(signlink.findcachedir()+ "Cursor.png"));
  328. frame.setLayout(new BorderLayout());
  329. frame.setResizable(false);
  330. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  331. JPanel gamePanel = new JPanel();
  332. gamePanel.setLayout(new BorderLayout());
  333. gamePanel.add(this);
  334. Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
  335. int w = 765;
  336. int h = 503;
  337. int x = (dim.width-w)/2;
  338. int y = (dim.height-h)/2;
  339. frame.setLocation(x, y);
  340. gamePanel.setPreferredSize(new Dimension(765, 503));
  341. JMenu fileMenu = new JMenu("Legacy One");
  342. JMenu toolMenu = new JMenu("Vote");
  343. JMenu infoMenu = new JMenu("Info");
  344. JMenu toggleMenu = new JMenu(" Toggles ");
  345. JMenu profileMenu = new JMenu(" Links ");
  346. JButton shotMenu = new JButton("Take Screenshot");
  347. shotMenu.setActionCommand("Screenshot");
  348. shotMenu.addActionListener(this);
  349. String[] mainButtons = new String[] { "Homepage", "Forums" };
  350. String[] toolButtons = new String[] { "Vote"};
  351. String[] infoButtons = new String[] { "Client Information", "Support" };
  352. String[] toggleButtons = new String[] { "Toggle 10x Damage", "Untoggle 10x Damage"};
  353. String[] profileButtons = new String[] { "Donate", "Vote", "-", "Highscores", "Guides", "YouTube", "Forums" };
  354.  
  355.  
  356.  
  357. for (String name : mainButtons) {
  358. JMenuItem menuItem = new JMenuItem(name);
  359. if (name.equalsIgnoreCase(" - ")) {
  360. fileMenu.addSeparator();
  361. } else {
  362. menuItem.addActionListener(this);
  363. fileMenu.add(menuItem);
  364. }
  365. }
  366. for (String name : toolButtons)
  367. {
  368. JMenuItem menuItem = new JMenuItem(name);
  369. if (name.equalsIgnoreCase(" - "))
  370. toolMenu.addSeparator();
  371. else {
  372. menuItem.addActionListener(this);
  373. toolMenu.add(menuItem);
  374.  
  375. }
  376. }
  377.  
  378. for (String name : infoButtons)
  379. {
  380. JMenuItem menuItem = new JMenuItem(name);
  381. if (name.equalsIgnoreCase("-"))
  382. infoMenu.addSeparator();
  383. else {
  384. menuItem.addActionListener(this);
  385. infoMenu.add(menuItem);
  386. }
  387. }
  388. for (String name : toggleButtons)
  389. {
  390. JMenuItem menuItem = new JMenuItem(name);
  391. if (name.equalsIgnoreCase("-"))
  392. toggleMenu.addSeparator();
  393. else {
  394. menuItem.addActionListener(this);
  395. toggleMenu.add(menuItem);
  396. }
  397. }
  398. for (String name : profileButtons)
  399. {
  400. JMenuItem menuItem = new JMenuItem(name);
  401. if (name.equalsIgnoreCase("-"))
  402. toggleMenu.addSeparator();
  403. else {
  404. menuItem.addActionListener(this);
  405. profileMenu.add(menuItem);
  406. }
  407. }
  408. JMenuBar menuBar = new JMenuBar();
  409. JMenuBar jmenubar = new JMenuBar();
  410.  
  411. frame.add(jmenubar);
  412. menuBar.add(screenshot);
  413. menuBar.add(fileMenu);
  414. menuBar.add(toolMenu);
  415. menuBar.add(infoMenu);
  416. menuBar.add(toggleMenu);
  417. menuBar.add(profileMenu);
  418. menuBar.add(shotMenu);
  419. frame.getContentPane().add(menuBar, BorderLayout.NORTH);
  420. frame.getContentPane().add(gamePanel, BorderLayout.CENTER);
  421. frame.pack();
  422.  
  423. frame.setVisible(true); // can see the client
  424. frame.setResizable(false); // resizeable frame
  425. init();
  426. } catch (Exception e) {
  427. e.printStackTrace();
  428. }
  429. }
  430.  
  431. public JDialog createFileChooserDialog(JFileChooser jfilechooser, String s, Container container)
  432. {
  433. JDialog jdialog = new JDialog(frame, s, true);
  434. jdialog.setDefaultCloseOperation(2);
  435. jdialog.add(jfilechooser);
  436. jdialog.pack();
  437. jdialog.setLocationRelativeTo(container);
  438. return jdialog;
  439. }
  440.  
  441. private int screenshot;
  442.  
  443. private boolean takeScreenshot = true;
  444.  
  445. public void screeny() {
  446. try {
  447. Window window = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
  448. Point point = window.getLocationOnScreen();
  449. int x = (int)point.getX();
  450. int y = (int)point.getY();
  451. int w = window.getWidth();
  452. int h = window.getHeight();
  453. Robot robot = new Robot(window.getGraphicsConfiguration().getDevice());
  454. Rectangle captureSize = new Rectangle(x, y, w, h);
  455. java.awt.image.BufferedImage bufferedimage = robot.createScreenCapture(captureSize);
  456. String fileExtension = "Legacy One";
  457. for (int i = 1; i <= 1000; i++) {
  458. File file = new File("Screenshots/"+ fileExtension +" "+ i +".png");
  459. if (!file.exists()) {
  460. screenshot = i;
  461. takeScreenshot = true;
  462. break;
  463. }
  464. }
  465. File file = new File((new StringBuilder()).append("Screenshots/" + fileExtension + " ").append(screenshot).append(".png").toString());
  466. if (takeScreenshot == true) {
  467. pushMessage("<col=6E0085>" + fileExtension + " "+ screenshot +" was saved in your screenshot folder!", 0, "");
  468. ImageIO.write(bufferedimage, "png", file);
  469. } else {
  470. pushMessage("<col=FF0000>Your screenshots folder is full!", 0, "");
  471. }
  472. } catch(Exception e) {
  473. e.printStackTrace();
  474. }
  475. }
  476.  
  477. public URL getCodeBase() {
  478. try {
  479. return new URL("http://" + serverip + "/cache");
  480. } catch (Exception e) {
  481. return super.getCodeBase();
  482. }
  483. }
  484.  
  485. public URL getDocumentBase() {
  486. return getCodeBase();
  487. }
  488.  
  489. public void loadError(String s) {
  490. System.out.println("loadError: " + s);
  491. }
  492.  
  493. public String getParameter(String key) {
  494. return "";
  495. }
  496.  
  497. private static void openUpWebSite(String url) {
  498. Desktop d = Desktop.getDesktop();
  499. try {
  500. d.browse(new URI(url));
  501. } catch (Exception e) {
  502. }
  503. }
  504.  
  505.  
  506.  
  507. }
Advertisement
Add Comment
Please, Sign In to add comment