Thread: Client Frame

Page 1 of 3 123 LastLast
Results 1 to 10 of 23
  1. #1 Client Frame 
    Donator

    Arithium's Avatar
    Join Date
    May 2010
    Age
    31
    Posts
    4,721
    Thanks given
    199
    Thanks received
    1,256
    Rep Power
    1114
    Since I've been seeing my navigation bar being sold, I'm just going to release it. I offer no support for this, so if someone else wants to help you, thats on them not me.



    Add these classes
    Code:
    package com.pkrealm.client;
    
    import java.awt.AWTException;
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Cursor;
    import java.awt.Desktop;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.Image;
    import java.awt.Insets;
    import java.awt.KeyboardFocusManager;
    import java.awt.Point;
    import java.awt.Rectangle;
    import java.awt.Robot;
    import java.awt.Toolkit;
    import java.awt.Window;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.InputEvent;
    import java.awt.event.KeyEvent;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import java.net.URI;
    import java.nio.file.Files;
    import java.nio.file.Path;
    import java.nio.file.Paths;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.HashSet;
    import java.util.Set;
    
    import javax.imageio.ImageIO;
    import javax.swing.BorderFactory;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JPopupMenu;
    import javax.swing.JSeparator;
    import javax.swing.KeyStroke;
    import javax.swing.SwingConstants;
    import javax.swing.UIManager;
    import javax.swing.border.EmptyBorder;
    import javax.swing.plaf.ColorUIResource;
    
    import com.pkrealm.client.constants.Constants;
    import com.pkrealm.client.graphics.gameframe.GameFrame.ScreenMode;
    
    /**
     * Creates a new user interface to display the client
     * 
     * @author Arithium
     *
     */
    public class ClientFrame extends Client implements ActionListener {
    
    	/**
    	 * The default serialized version
    	 */
    	private static final long serialVersionUID = 1L;
    
    	/**
    	 * Create our frame
    	 */
    	public JFrame frame;
    
    	/**
    	 * Create our game panel to display the client
    	 */
    	private JPanel gamePanel;
    
    	/**
    	 * Our jpanel for the menu bar
    	 */
    	private JPanel menuPanel;
    
    	/**
    	 * Creates a new jframe to display the client
    	 * 
    	 * @param args
    	 */
    	public ClientFrame(String args[]) {
    		try {
    			initializeUserInterface();
    		} catch (Exception ex) {
    			ex.printStackTrace();
    		}
    	}
    
    	/**
    	 * Initializes the jframe
    	 */
    	public void initializeUserInterface() {
    		try {
    
    			/*
    			 * Initialize our look and feel
    			 */
    			// UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
    			// JFrame.setDefaultLookAndFeelDecorated(true);
    			JPopupMenu.setDefaultLightWeightPopupEnabled(false);
    
    			UIManager.put("InternalFrame.activeTitleBackground", new ColorUIResource(Color.black));
    			UIManager.put("InternalFrame.activeTitleForeground", new ColorUIResource(Color.WHITE));
    			UIManager.put("InternalFrame.titleFont", new Font("Dialog", Font.PLAIN, 11));
    
    			/*
    			 * Initialize the jframe which will hold everything
    			 */
    			frame = new JFrame(Constants.CLIENT_NAME + " Official");
    			frame.setLayout(new BorderLayout());
    			frame.setResizable(false);
    			frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    			frame.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, null);
    			frame.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, null);
    
    			Set<KeyStroke> forwardKeys = new HashSet<KeyStroke>(1);
    			forwardKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.CTRL_MASK));
    			setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, forwardKeys);
    
    			Set<KeyStroke> backwardKeys = new HashSet<KeyStroke>(1);
    			backwardKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK | InputEvent.CTRL_MASK));
    			setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, backwardKeys);
    
    			/*
    			 * Set our frame size
    			 */
    			int width = REGULAR_WIDTH;
    			int height = REGULAR_HEIGHT;
    			Insets insets = getInsets();
    			frame.setSize(width + insets.left + insets.right, height + insets.top + insets.bottom);
    			/*
    			 * Fetch our screen size and set the location to the center of the
    			 * screen
    			 */
    			Toolkit toolkit = Toolkit.getDefaultToolkit();
    			int x = (int) (toolkit.getScreenSize().getWidth() / 2 - (765 / 2));
    			int y = (int) (toolkit.getScreenSize().getHeight() / 2 - (503 / 2));
    			frame.setLocation(new Point(x, y));
    
    			/*
    			 * Add our window listener to check when the x is clicked
    			 */
    			frame.addWindowListener(new WindowAdapter() {
    				@Override
    				public void windowClosing(WindowEvent we) {
    					String options[] = { "Yes", "No" };
    					int userPrompt = JOptionPane.showOptionDialog(null, "Are you sure you wish to exit?", Constants.CLIENT_NAME, JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options,
    							options[1]);
    					if (userPrompt == JOptionPane.YES_OPTION) {
    						System.exit(0);
    					}
    				}
    
    				@Override
    				public void windowGainedFocus(WindowEvent e) {
    					getGamePanel().requestFocusInWindow();
    					getGamePanel().requestFocus();
    				}
    
    			});
    
    			/*
    			 * Fetch our icon and set it
    			 */
    			Image icon = ResourceLoader.loadImage("logo.png");
    
    			if (icon != null) {
    				frame.setIconImage(icon);
    			}
    
    			/*
    			 * Initialize our menu bar to be displayed on top
    			 */
    			initializeMenuBar();
    
    			/*
    			 * We initialize our game panel
    			 */
    			initializeGamePanel();
    
    			/*
    			 * Set the frame as non focusable
    			 */
    			frame.setFocusable(false);
    
    			/*
    			 * Pack the frame to remove any empty space and fit the applet
    			 */
    			frame.pack();
    
    			/*
    			 * Finally set our frame to visible
    			 */
    			frame.setVisible(true); // can see the client
    
    			/*
    			 * Create our applet
    			 */
    			init();
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    
    	/**
    	 * Initializes the game panel to display the applet
    	 */
    	private void initializeGamePanel() {
    		/*
    		 * Initialize
    		 */
    		setGamePanel(new JPanel());
    
    		/*
    		 * Set the layout to border layout
    		 */
    		getGamePanel().setLayout(new BorderLayout());
    
    		/*
    		 * Add the client to the game panel
    		 */
    		getGamePanel().add(this);
    
    		/*
    		 * Set the size of the game panel
    		 */
    		Dimension dimension = new Dimension(REGULAR_WIDTH, REGULAR_HEIGHT);
    		getGamePanel().setPreferredSize(dimension);
    		getGamePanel().setSize(dimension);
    
    		/*
    		 * Set the game panel as focusable
    		 */
    		getGamePanel().setFocusable(false);
    
    		/*
    		 * Request the focus to the game panel
    		 */
    		getGamePanel().requestFocus();
    
    		/*
    		 * Disable focus traversal keys
    		 */
    		getGamePanel().setFocusTraversalKeysEnabled(false);
    
    		getGamePanel().setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, null);
    		getGamePanel().setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, null);
    
    		/*
    		 * Place the game panel which will display the applet in the center
    		 */
    		frame.getContentPane().add(getGamePanel(), BorderLayout.CENTER);
    	}
    
    	/**
    	 * Initializes the menu bar
    	 */
    	public void initializeMenuBar() {
    
    		/*
    		 * Initialize our menu panel to hold our menu buttons
    		 */
    		menuPanel = new JPanel();
    
    		/*
    		 * Set the menu panel as non focusable
    		 */
    		menuPanel.setFocusable(false);
    		
    		/*
    		 * Disable focus traversal keys
    		 */
    		menuPanel.setFocusTraversalKeysEnabled(false);
    
    		// menuPanel.setBackground(Color.decode("0xFFFFFF"));
    
    		menuPanel.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, null);
    		menuPanel.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, null);
    
    		/*
    		 * Create our buttons
    		 */
    		JButton homeButton = createButton("Home", "home_icon.png", "Open the Pk-Realm homepage.");
    		JButton forumButton = createButton("Forum", "forum_icon.png", "Open the Pk-Realm forums.");
    		JButton storeButton = createButton("Store", "store_icon.png", "Open the official Pk-Realm store.");
    		JButton voteButton = createButton("Vote", "vote_icon.png", "Open the official Pk-Realm voting page.");
    		JButton hiscoresButton = createButton("Hiscores", "hiscore_icon.png", "Open the Pk-Realm Hiscores.");
    
    		/*
    		 * Add our buttons to the menu panel
    		 */
    
    		menuPanel.add(homeButton);
    		menuPanel.add(forumButton);
    		menuPanel.add(storeButton);
    		menuPanel.add(voteButton);
    		menuPanel.add(hiscoresButton);
    
    		JSeparator separator = new JSeparator(SwingConstants.VERTICAL);
    		separator.setPreferredSize(new Dimension(1, 18));
    		separator.setBackground(Color.BLACK);
    		separator.setBorder(BorderFactory.createEmptyBorder());
    		menuPanel.add(separator);
    
    		JButton facebook = createButton("", "facebook_icon.png", "Open the Pk-Realm facebook page.");
    		JButton youtube = createButton("", "youtube_icon.png", "Open the Pk-Realm youtube page.");
    
    		menuPanel.add(facebook);
    		menuPanel.add(youtube);
    
    		JSeparator separator2 = new JSeparator(SwingConstants.VERTICAL);
    		separator2.setPreferredSize(new Dimension(1, 18));
    		separator2.setBackground(Color.BLACK);
    		separator2.setBorder(BorderFactory.createEmptyBorder());
    		menuPanel.add(separator2);
    
    		JButton screenshot = createButton("Screenshot", "monitor_icon.png", "Open the Pk-Realm facebook page.");
    		JButton history = createButton("History", "history_icon.png", "Open the Pk-Realm youtube page.");
    
    		menuPanel.add(screenshot);
    		menuPanel.add(history);
    
    		/*
    		 * Add our menu panel to our frame
    		 */
    		frame.getContentPane().add(menuPanel, BorderLayout.NORTH);
    	}
    
    	/**
    	 * Creates a button on the menu panel
    	 * 
    	 * @param title
    	 *            The Title of the button
    	 * @param image
    	 *            The image to display
    	 * @param tooltip
    	 *            The tooltip when hovering over the button
    	 * @return The created button
    	 */
    	private JButton createButton(String title, String image, String tooltip) {
    		final JButton button = new JButton(title);
    		if (image != null) {
    			Image img = ResourceLoader.loadImage(image);
    			if (img != null) {
    				ImageIcon icon = new ImageIcon(img);
    				// Image resized = icon.getImage().getScaledInstance(30, 30,
    				// Image.SCALE_SMOOTH);
    				// icon = new ImageIcon(resized);
    				if (icon != null)
    					button.setIcon(icon);
    			}
    		}
    		button.addActionListener(this);
    		if (tooltip != null)
    			button.setToolTipText(tooltip);
    		button.setFocusable(false);
    		button.setContentAreaFilled(false);
    		button.setFont(new Font("Dialog", Font.PLAIN, 11));
    		button.setCursor(new Cursor(Cursor.HAND_CURSOR));
    		button.setForeground(Color.BLACK);
    		button.setBorder(new EmptyBorder(1, 1, 3, 1));
    		button.addMouseListener(new java.awt.event.MouseAdapter() {
    		    public void mouseEntered(java.awt.event.MouseEvent evt) {
    		    	button.setContentAreaFilled(true);
    		    	button.setBackground(Color.decode("0xd7e5f1"));
    		    }
    
    		    public void mouseExited(java.awt.event.MouseEvent evt) {
    		    	button.setBackground(UIManager.getColor("control"));
    		    	button.setContentAreaFilled(false);
    		    }
    		});
    		return button;
    	}
    
    	/**
    	 * Opens a URL in your default web browser
    	 * 
    	 * @param url
    	 *            The url of the website to open
    	 */
    	static void openURL(String url) {
    		Desktop d = Desktop.getDesktop();
    		try {
    			d.browse(new URI(url));
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    
    	/**
    	 * Resizes the frame when switching between modes
    	 * 
    	 * @param screenMode
    	 *            The {@link ScreenMode} your switching too
    	 */
    	public void resize(ScreenMode screenMode) {
    		try {
    			int width = screenMode == ScreenMode.FIXED ? REGULAR_WIDTH : RESIZABLE_WIDTH;
    			int height = screenMode == ScreenMode.FIXED ? REGULAR_HEIGHT : RESIZABLE_HEIGHT;
    			
    			Dimension dimension = new Dimension(width, height);
    
    			gamePanel.setPreferredSize(dimension);
    			
    			frame.setMinimumSize(dimension);
    			
    			Insets insets = frame.getInsets();
    			int widthModifier = 0 + insets.left;//6
    			int heightModifier = 0 + insets.top; // 60
    			frame.setBounds(0, 0, width + widthModifier, height + heightModifier);
    			
    			super.myWidth = width;
    			super.myHeight = height;
    
    			frame.setResizable(screenMode != ScreenMode.FIXED);
    			frame.setLocationRelativeTo(null);
    			frame.pack();
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    	
    	/**
    	 * Use this method to create a screenshot of the JFrame object argFrame.
    	 *
    	 * Author(s): Dejan Lekic License: Public Domain
    	 *
    	 * @param argFrame
    	 *            JFrame you want to make screenshot of.
    	 */
    	public final void makeScreenshot() {
    		try {
    			Window window = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
    			Point point = window.getLocationOnScreen();
    			Robot robot = new Robot(window.getGraphicsConfiguration().getDevice());
    			Rectangle rectangle = new Rectangle((int) point.getX(), (int) point.getY(), window.getWidth(),
    					window.getHeight());
    			BufferedImage img = robot.createScreenCapture(rectangle);
    			Path path = Paths.get(Signlink.getDataDirectory().getPath(), "screenshots");
    			if (!Files.exists(path)) {
    				Files.createDirectories(path);
    			}
    			DateFormat format = new SimpleDateFormat("MM-dd-yyyy hh-mm-ss a");
    			File file = new File(path.toFile(), format.format(new Date()) + ".png");
    			ImageIO.write(img, "png", file);
    			JOptionPane.showMessageDialog(null, "Successfully taken screenshot!", Constants.CLIENT_NAME, JOptionPane.NO_OPTION);
    		} catch (IOException | AWTException ioe) {
    			System.out.println(ioe.toString());
    		}
    	}
    
    	/**
    	 * The action listener for the menu panel buttons
    	 */
    	public void actionPerformed(ActionEvent evt) {
    		String cmd = evt.getActionCommand();
    		try {
    			if (cmd != null) {
    				switch (cmd) {
    				case "Home":
    					openURL("http://pk-realm.com");
    					break;
    				case "Forum":
    					openURL("http://pk-realm.com/forum/");
    					break;
    				case "Store":
    					openURL("http://pk-realm.com/store.html");
    					break;
    				case "Vote":
    					openURL("http://pk-realm.com/vote.html");
    					break;
    				case "Screenshot":
    					makeScreenshot();
    					break;
    				case "History":
    					Desktop.getDesktop().open(new File(Signlink.getDataDirectory(), "screenshots"));
    					break;
    				}
    				setBackground(UIManager.getColor("control"));
    				JButton button = (JButton) evt.getSource();
    				button.setContentAreaFilled(false);
    			}
    		} catch (Exception e) {
    		}
    	}
    
    	public void setCursor(byte[] data) {
    		try {
    			Image image = getGameComponent().getToolkit().createImage(data);
    			getGameComponent().setCursor(getGameComponent().getToolkit().createCustomCursor(image, new Point(0, 0), null));
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    
    	public void setCursor(int id) {
    		try {
    			String directory = Signlink.getWorkingDirectory().getAbsolutePath() + "/sprites/" + id + ".png";
    			Image image = getGameComponent().getToolkit().getImage(directory);
    			getGameComponent().setCursor(getGameComponent().getToolkit().createCustomCursor(image, new Point(0, 0), null));
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    
    	public JPanel getGamePanel() {
    		return gamePanel;
    	}
    
    	public void setGamePanel(JPanel gamePanel) {
    		this.gamePanel = gamePanel;
    	}
    
    	public JPanel getMenuPanel() {
    		return menuPanel;
    	}
    
    	public void setTitle(String title) {
    		frame.setTitle(title);
    	}
    }
    Code:
    package com.pkrealm.client;
    
    import java.awt.Image;
    import java.awt.Toolkit;
    import java.net.URL;
    
    public class ResourceLoader {
    
    	static ResourceLoader rl = new ResourceLoader();
    
    	public static Image loadImage(String imageName) {
    		URL url = null;
    		try {
    			url = rl.getClass().getResource("images/" + imageName);
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    		
    		if (url == null) {
    			return null;
    		}
    		return Toolkit.getDefaultToolkit().getImage(url);
    	}
    }
    Download these images and you'll need to place them in the packaging where the resource loader is in a folder called images.
    https://www.upload.ee/files/6621685/images.zip.html

    Client.java -> Add somewhere
    Code:
    public static ClientFrame clientFrame;
    Void main comment out createClientFrame and add in
    Code:
    clientFrame = new ClientFrame(args);
    You'll need to rework your resizable yourself, enjoy.
    Reply With Quote  
     

  2. #2  
    love

    scoob's Avatar
    Join Date
    Oct 2015
    Age
    25
    Posts
    1,642
    Thanks given
    367
    Thanks received
    640
    Rep Power
    1559
    Thanks for this! A cool navi bar : )
    Attached image
    Reply With Quote  
     

  3. #3  
    Donator

    Jason's Avatar
    Join Date
    Aug 2009
    Posts
    6,092
    Thanks given
    2,402
    Thanks received
    2,823
    Rep Power
    4550
    Not too shabby, would be nice to see more game-influenced images though.
    Reply With Quote  
     

  4. #4  
    Registered Member
    Zivik's Avatar
    Join Date
    Oct 2007
    Age
    28
    Posts
    4,421
    Thanks given
    891
    Thanks received
    1,527
    Rep Power
    3285
    Thanks for the share.
    Reply With Quote  
     

  5. #5  
    'Slutty McFur'

    Owain's Avatar
    Join Date
    Sep 2014
    Age
    26
    Posts
    2,894
    Thanks given
    2,360
    Thanks received
    2,200
    Rep Power
    5000
    Nice snippet.


    Spoiler for wat:
    Attached image
    Attached image

    Attached image


    Reply With Quote  
     

  6. #6  
    Donator

    Arithium's Avatar
    Join Date
    May 2010
    Age
    31
    Posts
    4,721
    Thanks given
    199
    Thanks received
    1,256
    Rep Power
    1114
    Quote Originally Posted by Jason View Post
    Not too shabby, would be nice to see more game-influenced images though.
    Not my images, it was made to replicate ikov. They are super easy to replace though.
    Reply With Quote  
     

  7. #7  
    Registered Member
    Lennard's Avatar
    Join Date
    Mar 2010
    Posts
    924
    Thanks given
    0
    Thanks received
    234
    Rep Power
    274
    Nice contribution
    Attached image
    The greatest upcoming OSRS PK server
    Reply With Quote  
     

  8. #8  
    Super Donator

    Chivvon's Avatar
    Join Date
    May 2016
    Posts
    487
    Thanks given
    69
    Thanks received
    142
    Rep Power
    285
    Not that bad, thanks for the contribution
    Reply With Quote  
     

  9. #9  
    Retired. Stop PMing me.


    Galkon's Avatar
    Join Date
    Nov 2007
    Age
    17
    Posts
    7,526
    Thanks given
    1,805
    Thanks received
    2,830
    Rep Power
    5000
    I'm 90% certain I wrote this for the Ikov client in 2015. It even uses the images I made for it. Maybe someone just ripped the images and rewrote it themselves.
    Attached image
    Reply With Quote  
     


  10. #10  
    Renown Programmer & Respected Member

    Ryley's Avatar
    Join Date
    Aug 2011
    Posts
    596
    Thanks given
    254
    Thanks received
    521
    Rep Power
    1332
    Quote Originally Posted by Galkon View Post
    I'm 90% certain I wrote this for the Ikov client in 2015. It even uses the images I made for it. Maybe someone just ripped the images and rewrote it themselves.
    v /mts

    Quote Originally Posted by Arithium View Post
    Not my images, it was made to replicate ikov. They are super easy to replace though.
    Reply With Quote  
     

Page 1 of 3 123 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Replies: 31
    Last Post: 11-12-2015, 05:26 PM
  2. Blood Thorn Client Frame!
    By chromehoundz in forum Graphics
    Replies: 30
    Last Post: 01-21-2009, 04:38 PM
  3. Can Someone Make me A Client Frame?
    By RuiN in forum Graphics
    Replies: 1
    Last Post: 11-10-2008, 12:23 AM
  4. First Client Frame(s)
    By Harvey in forum Graphics
    Replies: 6
    Last Post: 04-28-2008, 09:56 PM
  5. Future Client Frame , The Iron Client!
    By ~Legend Rene in forum Graphics
    Replies: 42
    Last Post: 11-11-2007, 03:03 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •