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.

Page 2 of 2 FirstFirst 12
Results 26 to 34 of 34

Thread: Applet isn't showing up. Perhaps it's a browser fault.

  1. #26
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Applet isn't showing up. Perhaps it's a browser fault.

    I know that applet is extended from Panel. However, it had me confused when I went to test it on my IDE and it showed a window like thing in the test part.

    I'd never managed to get it in a browser until yesterday.

    However, considering that I might need nested classes, and that might mean several applets within applets opening. However, I can't have some of them in separate html files and applets. That wouldn't work.

  2. #27
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Applet isn't showing up. Perhaps it's a browser fault.

    Time for a redesign of the project.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #28
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Applet isn't showing up. Perhaps it's a browser fault.

    What happens if a JApplet calls a JFrame?

    Will it open the JFrame?

  4. #29
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Applet isn't showing up. Perhaps it's a browser fault.

    Try it and see what happens.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #30
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: Applet isn't showing up. Perhaps it's a browser fault.

    That's because you viewed the applet in an Applet Viewer, not embedded on an html page. Applet Viewers are strictly for debugging and testing purposes, not for actual deployment. Depending on your design, you could use a CardLayout, combine all of your Applets into one, and swap between them by putting them on separate Cards. That's always been my solution for "changing windows" in applets.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  6. #31
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Applet isn't showing up. Perhaps it's a browser fault.

    Almost would work, though I'd have to add lots of extra buttons to make it go back and forth. Also, I can't figure out how to work Card Layout. I tried it once and it kept throwing some weird exception.

    I thought that it wouldn't take much to change something from JFrame to JApplet.

    Also, can I have all of the applets on the page, very painful but doable, assuming that I guess I make them all public Applets, even the inner classes and stuff, and just call start() in their constructors as they are needed?

    I did have a brainwave that I could simply add other applets to other pages for when it was feasible to have a separate applet, and use the

    Desktop.getDesktop().browse() method to make the browser go to the applet page.

    The problem is where applets are passing data to each other, can I keep it like I had it when I was using JFrames and just pass it or do I need to add lots of new java and html code to make that continue to work?
    Last edited by javapenguin; May 14th, 2012 at 04:38 PM.

  7. #32
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: Applet isn't showing up. Perhaps it's a browser fault.

    CardLayout isn't that bad when you get used to it. Depending on your design, you may be able to create a sub-panel that contains the Cards, while your main panel contains buttons and whatnot to swap between the Cards (meaning you wouldn't have to put the buttons on each Card). Kinda like how html frames work (if you are familiar with how html frames work). The Applets that I've made that uses CardLayout usually has a navigation list on the left-hand side, some sort of general tools along the top, and then the Cards in its own panel in the middle taking up most of the applet window. It allows for a little bit of organized chaos (which we all know is the best kind of chaos).
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  8. #33
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Applet isn't showing up. Perhaps it's a browser fault.

    How do you word CardLayout? As I said, I tried it once and it wouldn't work. I'm going to try it again.

  9. #34
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: Applet isn't showing up. Perhaps it's a browser fault.

    Here is a small program I tossed together real quick. It should run perfectly. I added some comments so you can understand what is happening. As you will see, it is very simple. If you have any questions, feel free to ask.

    You can selected the Card using the JList on the left-hand side, or by using the Next and Previous buttons at the top.

    /**
     * @(#)CardLayoutExample.java
     *
     *
     * @author 
     * @version 1.00 2012/5/14
     */
     
    import javax.swing.*;
    import java.util.*;
    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.border.*;
    import javax.swing.event.*;
     
    public class CardLayoutExample extends JFrame {
     
        JList menuOptions;
        JButton next;
        JButton previous;
        Vector<ContentPanel> panels;
     
        //Create Card Holder Panel as global variable so you can use it inside listeners
        JPanel cardHolder;
     
        public CardLayoutExample() {
            super("Example");
            setSize(500,500);
            panels = new Vector<ContentPanel>();
     
            //Create x number of ContentPanels
            int number = 5;
            for(int i=0;i<number;i++) {
            	panels.add(new ContentPanel(i+1));
            }
     
            //Initialize Card Holder and send it a new CardLayout() as the constructor. Set the Preferred Size, and set the Border for clarity
            cardHolder = new JPanel(new CardLayout());
    		cardHolder.setPreferredSize(new Dimension(200,200));
    		cardHolder.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));
     
            //Initialize button that moves to the next Card
            next = new JButton("Next");
            next.addActionListener(new ActionListener() {
            	public void actionPerformed(ActionEvent e) {
            		//Call the next card method
            		((CardLayout)cardHolder.getLayout()).next(cardHolder);
            	}
            });
            //Initialize button that moves to the previous Card
            previous = new JButton("Previous");
            previous.addActionListener(new ActionListener() {
            	public void actionPerformed(ActionEvent e) {
            		//Call the next card method
            		((CardLayout)cardHolder.getLayout()).previous(cardHolder);
            	}
            });
     
            //Create Menu List that allows user to select the Card, set the size of the Menu List, and add a List Selection Listener
            menuOptions = new JList(panels);
            menuOptions.setPreferredSize(new Dimension(50,200));
            menuOptions.addListSelectionListener(new ListSelectionListener(){
    			public void valueChanged(ListSelectionEvent e)
    			{
    				//Return if Event is adjusting
    				if(e.getValueIsAdjusting())
    					return;
    				//Get the selected index and change Cards
    				int selectedIndex = menuOptions.getSelectedIndex();
    				((CardLayout)cardHolder.getLayout()).show(cardHolder,menuOptions.getSelectedValue().toString());
    			}
    		});
     
    		//Add all the Cards to the Card Holder
    		for(ContentPanel panel : panels) {
    			cardHolder.add(panel,panel.toString());
    		}
     
    		//Panel that holds the Next and Previous Buttons
    		JPanel top = new JPanel();
    		top.setPreferredSize(new Dimension(200,50));
    		top.add(next);
    		top.add(previous);
     
    		//Add Buttons, the Menu, and the Cards to the JFrame
    		getContentPane().add(top,BorderLayout.PAGE_START);
    		getContentPane().add(menuOptions,BorderLayout.LINE_START);
    		getContentPane().add(cardHolder,BorderLayout.CENTER);
     
    		setVisible(true);
        }
     
        public class ContentPanel extends JPanel {
        	JLabel label;
        	int num;
        	public ContentPanel(int n) {
        		super();
        		setPreferredSize(new Dimension(200,200));
        		num = n;
        		label = new JLabel("This is Panel "+n);
        		add(label);
        	}
     
        	public String toString() {
        		return "Panel "+num;
        	}
        }
     
        public static void main(String[] args) {
        	new CardLayoutExample();
        }
    }
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  10. The Following User Says Thank You to aussiemcgr For This Useful Post:

    javapenguin (May 14th, 2012)

Page 2 of 2 FirstFirst 12

Similar Threads

  1. [SOLVED] Why doesn't my Applet show up in my browser?
    By SendBorg in forum Java Applets
    Replies: 3
    Last Post: January 29th, 2012, 08:30 AM
  2. Java applet on web showing gray box
    By MyName in forum Java Applets
    Replies: 6
    Last Post: December 2nd, 2011, 03:53 PM
  3. How to run Applet with Ms Sql connectivity in browser
    By mayanksmart4 in forum Java Applets
    Replies: 1
    Last Post: November 22nd, 2011, 09:57 AM
  4. HELP! My applet won't run on a web browser....
    By coolidge in forum Java Applets
    Replies: 4
    Last Post: October 21st, 2011, 08:52 AM
  5. Soap With Attachment AXIS Fault
    By anoopasta in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 23rd, 2010, 11:09 AM