Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

Thread: Tabbed Pane not showing up.

  1. #1
    Member
    Join Date
    Jul 2012
    Posts
    37
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Tabbed Pane not showing up.

    package oldschool.runescape.com;
     
    import java.applet.Applet;
    import java.applet.AppletContext;
    import java.applet.AppletStub;
    import java.awt.Dimension;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.BufferedReader;
    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.OutputStream;
    import java.net.URL;
    import java.net.URLConnection;
    import java.util.HashMap;
    import java.util.Hashtable;
    import java.util.zip.ZipEntry;
    import java.util.zip.ZipInputStream;
     
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JTabbedPane;
     
    /**
     * A loader for the oldschool version of RuneScape
     * 
     * @author Tyluur<itstyluur@gmail.com>
     * @author Netty
     */
    public final class RS2Loader extends ClassLoader implements AppletStub {
     
    	/** The URL of the oldschool client. */
    	private static URL oldscapeURL;
     
    	/** The instance of the frame. */
    	private static JFrame frame = new JFrame("RuneScape07");
     
    	/** The map of the parameters provided by the client. */
    	private static HashMap<String, String> params = new HashMap<String, String>();
     
    	/** The map of the client classes */
    	private static Hashtable<String, byte[]> classes = new Hashtable<String, byte[]>();
     
    	/** The instance of the ProgressBar class.*/
    	private static ProgressBar progress;
     
    	private static JTabbedPane tabbedPane;
    	private static JPanel contentPane;
     
    	/**
    	 * Starts up the class.
    	 * @param args
    	 * @throws Exception
    	 */
    	public static void main(String[] args) throws Exception {
    		oldscapeURL = new URL("http://oldschool1.runescape.com/");
    		parseParams();
    		loadClasses();
    		loadClient();
    	}
     
    	private static void parseParams() throws IOException {
    		System.out.println("Parsing parameters...");
    		try (BufferedReader br = new BufferedReader(new InputStreamReader(oldscapeURL.openStream()))) {
    			String line;
    			while ((line = br.readLine()) != null) {
    				int index;
    				if ((index = line.indexOf("archive=") + 8) > 8) {
    					params.put("initial_jar", line.substring(index, line.length() - 4));
    				} else if ((index = line.indexOf("param name=\"") + 12) > 12) {
    					int end = line.indexOf('"', index);
    					String key = line.substring(index, end);
    					String value = line.substring(end + 9, line.length() - 5);
    					params.put(key, value);
    				}
    			}
    		}
    	}
     
    	private static void loadClasses() throws IOException {
    		URL url = new URL(oldscapeURL, params.get("initial_jar"));
    		File f = new File(System.getProperty("user.home") + "/.jagex_cache_32/gamepack.jar");
    		if (f.exists()) {
    			url = f.toURI().toURL();
    			System.out.println("Reading gamepack...");
    		} else {
    			System.out.println("Downloading gamepack...");
    		}
    		URLConnection con = url.openConnection();
    		InputStream in = con.getInputStream();
    		ByteArrayOutputStream out = new ByteArrayOutputStream(con.getContentLength());
    		progress = new ProgressBar(0, con.getContentLength());
    		byte[] buffer = new byte[4096];
    		int read;
    		while ((read = in.read(buffer)) != -1) {
    			out.write(buffer, 0, read);
    			progress.updateProgress(out.size());
    		}
    		in.close();
    		if (!f.exists()) {
    			FileOutputStream fos = new FileOutputStream(f);
    			fos.write(out.toByteArray());
    			fos.close();
    		}
    		System.out.println("Unzipping gamepack...");
    		ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(out.toByteArray()));
    		ZipEntry ze;
    		while ((ze = zis.getNextEntry()) != null) {
    			if (ze.getName().endsWith(".class")) {
    				out.reset();
    				while ((read = zis.read(buffer)) != -1) {
    					out.write(buffer, 0, read);
    				}
    				classes.put(ze.getName().replace(".class", ""), out.toByteArray());
    			}
    		}
    	}
     
    	private static void loadClient() throws Exception {
    		System.out.println("Loading client...");
    		RS2Loader loader = new RS2Loader();
    		Applet a = null;
    		try {
    			a = (Applet) loader.loadClass("client").newInstance();
    			a.setPreferredSize(new Dimension(765, 503));
    			a.setStub(loader);
    			a.init();
    			a.start();
    		} catch (Exception e) {
    			new File(System.getProperty("user.home") + "/gamepack.jar").delete();
    			loadClient();
    			e.printStackTrace();
    			JOptionPane.showMessageDialog(null, "Error loading client - delete gamepack.jar in: " + System.getProperty("user.home") + "/.jagex_cache_32 and reload this applet.");
    		}
     
    		JMenuBar menuBar = new JMenuBar();
    		JMenu file = new JMenu("File");
    		JMenu tools = new JMenu("Tools");
    		JMenuItem exit = new JMenuItem("Exit");
    		JMenuItem calc = new JMenuItem("Combat Calculator");
     
    		calc.addActionListener(new ActionListener() {
     
    			@Override
    			public void actionPerformed(ActionEvent e) {
    				Calculator.main();
    			}
    		});
     
    		exit.addActionListener(new ActionListener() {
     
    			@Override
    			public void actionPerformed(ActionEvent e) {
    				System.out.println("Game client exited.");
    				System.exit(1);
    			}
    		});
     
    		file.add(exit);
    		tools.add(calc);
    		menuBar.add(file);
    		menuBar.add(tools);
     
    		if (!new File(System.getProperty("user.home") + "/.jagex_cache_32/icon.png").exists())
    			saveImage("http://images2.wikia.nocookie.net/__cb20111129224838/runescape/images/8/8e/Training_sword.png", System.getProperty("user.home") + "/.jagex_cache_32/icon.png");
     
    		getFrame().setIconImage(new ImageIcon(System.getProperty("user.home") + "/.jagex_cache_32/icon.png").getImage());  
    		getFrame().setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		getFrame().setContentPane(a);
    		getFrame().setResizable(false);
    		getFrame().setJMenuBar(menuBar);
    		getFrame().pack();
    		getFrame().setLocationRelativeTo(null);
     
    		tabbedPane = new JTabbedPane(JTabbedPane.TOP);
    		tabbedPane.setBounds(801, 0, 326, 597);
     
    		contentPane = new JPanel();
    		getFrame().setContentPane(contentPane);
    		contentPane.setLayout(null);
     
    		tabbedPane = new JTabbedPane(JTabbedPane.TOP);
    		tabbedPane.setBounds(801, 0, 326, 597);
    		contentPane.add(tabbedPane);
     
    		JPanel panelTools = new JPanel();
    		panelTools.setLayout(null);
    		tabbedPane.addTab("Tools", null, panelTools, null);
     
    		getFrame().setVisible(true);
    	}
     
    	public static void saveImage(String imageUrl, String destinationFile) throws IOException {
    		URL url = new URL(imageUrl);
    		InputStream is = url.openStream();
    		OutputStream os = new FileOutputStream(destinationFile);
     
    		byte[] b = new byte[2048];
    		int length;
     
    		while ((length = is.read(b)) != -1) {
    			os.write(b, 0, length);
    		}
     
    		is.close();
    		os.close();
    	}
     
    	@Override
    	public Class<?> loadClass(String name) throws ClassNotFoundException {
    		byte[] clazz = classes.get(name);
    		if (clazz != null) {
    			return defineClass(name, clazz, 0, clazz.length);
    		}
    		return super.loadClass(name);
    	}
     
    	@Override
    	public boolean isActive() {
    		return false;
    	}
     
    	@Override
    	public URL getDocumentBase() {
    		return oldscapeURL;
    	}
     
    	@Override
    	public URL getCodeBase() {
    		return oldscapeURL;
    	}
     
    	@Override
    	public String getParameter(String name) {
    		return params.get(name);
    	}
     
    	@Override
    	public AppletContext getAppletContext() {
    		return null;
    	}
     
    	@Override
    	public void appletResize(int width, int height) {
    	}
     
    	/**
    	 * @return the frame
    	 */
    	public static JFrame getFrame() {
    		return frame;
    	}
     
    	/**
    	 * @param frame the frame to set
    	 */
    	public static void setFrame(JFrame frame) {
    		RS2Loader.frame = frame;
    	}
     
    }

    The tabbed pane is not showing up, what am I doing wrong?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Tabbed Pane not showing up.

    The posted code does not compile without errors.

    Can you make a small simple complete program that compiles, executes and shows the problem?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Jul 2012
    Posts
    37
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Tabbed Pane not showing up.

    Quote Originally Posted by Norm View Post
    The posted code does not compile without errors. Can you fix the posted code or
    Can you make a small simple complete program that compiles, executes and shows the problem?
    It is missing the Calculator class and ProgressBar class.

    Calculator class:

    package oldschool.runescape.com; import java.awt.EventQueue; import java.awt.ev - Pastebin.com

    ProgressBar class:

    package oldschool.runescape.com; import java.awt.BorderLayout; import java.awt. - Pastebin.com

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Tabbed Pane not showing up.

    None of that has anything to do with using the JTabbedPane. 90% of the posted code is not relevant to the problem.

    Can you write a small, simple complete program that compiles, executes and shows the problem?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Jul 2012
    Posts
    37
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Tabbed Pane not showing up.

    Quote Originally Posted by Norm View Post
    None of that has anything to do with using the JTabbedPane. 90% of the posted code is not relevant to the problem.

    Can you write a small, simple complete program that compiles, executes and shows the problem?
    The main code I posed is using the JTabbedPane. In method loadClient().

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Tabbed Pane not showing up.

    Ok, copy it to a small testing program that compiles, executes and shows the problem and post that here.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Member
    Join Date
    Jul 2012
    Posts
    37
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Tabbed Pane not showing up.

    There's nothing being printed out, I have the code in an Eclipse project. It's just not showing the tabbed pane.

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Tabbed Pane not showing up.

    If you want someone to test the code to help you find the problem:
    write a small, simple complete program that compiles, executes and shows the problem
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Member
    Join Date
    Jul 2012
    Posts
    37
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Tabbed Pane not showing up.

    The class RS2Loader is the one that compiles and executes fine, you just have to put the classes I gave you into the right packages.

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Tabbed Pane not showing up.

    Sorry, I don't want to work with that huge mess of code that is not part of the problem.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. tabbed panes
    By sravanthi in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 7th, 2013, 02:07 PM
  2. Replies: 3
    Last Post: March 6th, 2012, 03:50 AM
  3. [SOLVED] Inserting scroll lists and text fields into tabbed panes
    By Ace Java 9000 in forum AWT / Java Swing
    Replies: 3
    Last Post: January 5th, 2012, 02:12 PM
  4. What exactly is a content pane?
    By TP-Oreilly in forum Java Theory & Questions
    Replies: 2
    Last Post: December 7th, 2011, 09:07 AM
  5. Reusing Panel code in each tabs on a tabbed pane
    By kurt-hardy in forum Object Oriented Programming
    Replies: 4
    Last Post: March 23rd, 2011, 08:21 AM