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 7 of 7

Thread: Java applet on web showing gray box

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java applet on web showing gray box

    Hello, I'm working on my senior project where we are trying to make an online game. The game is finished but when we try to deploy the applet to an html file we get a gray screen. Spent a lot of time researching solutions with no luck, was hoping someone here could help us. This is the code for the method that calls the GUI:
    package testGUI;
     
    import GUI.GameInterface;
    import GUI.MapPanel;
    import GUI.gameGUI;
    import GUI.nodeGUI;
    import Game.Game;
    import GamePlay.Player;
    import Map.MakeMapOne;
    import java.applet.Applet;
    import java.awt.Color;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.Toolkit;
    import java.io.IOException;
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import java.util.logging.FileHandler;
    import java.util.logging.Level;
    import java.util.logging.LogManager;
    import java.util.logging.Logger;
    import java.util.logging.XMLFormatter;
     
    import javax.swing.JApplet;
    import javax.swing.SwingUtilities;
     
    public class testGUI extends JApplet {
        //Called when this applet is loaded into the browser.
     
        public void init() {
     
            try {
                LogManager lm = LogManager.getLogManager();
                final Logger logger;
                FileHandler fh = new FileHandler("log_test.txt");
                //Execute a job on the event-dispatching thread; creating this applet's GUI.
     
                logger = Logger.getLogger("GUI");
                lm.addLogger(logger);            
                fh.setFormatter(new XMLFormatter());
                logger.addHandler(fh);
                try {
                    SwingUtilities.invokeAndWait(new Runnable() {
     
                        public void run() {
                            createGUI();
                            logger.setLevel(Level.INFO);
                            logger.log(Level.INFO, "GUI created");
                        }
                    });
                } catch (Exception e) {
                    logger.setLevel(Level.WARNING);
                    logger.log(Level.WARNING, "createGUI didn't complete successfully " + e);
                    fh.close();
                }
            } catch (IOException ex) {
                Logger.getLogger(testGUI.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SecurityException ex) {
                Logger.getLogger(testGUI.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
     
        private void createGUI() {
            //Create and set up the content pane.
            for (int i = 0; i < 22; i++) {
                System.out.println((i % 3));
            }
            MapPanel p = new MapPanel(200, 200);
            System.out.println(p.getSize());
            p.setBackground(Color.red);
            //JFrame jf=new JFrame("Game");
            Toolkit tk = Toolkit.getDefaultToolkit();
            int xSize = ((int) tk.getScreenSize().getWidth());
            int ySize = ((int) tk.getScreenSize().getHeight());
            //jf.setSize(xSize,ySize);
            JPanel whole = new JPanel(new GridBagLayout());
            GridBagConstraints A = new GridBagConstraints();
            A.gridx = 1;
            A.gridy = 1;
            Player p1 = new Player("Stephen");
            Player p2 = new Player("Shayne");
            Game g = new Game(p1, p2, MakeMapOne.returnMap());
            gameGUI a = new gameGUI(g);
     
            whole.add(a);
            //JLabel l=new JLabel (new ImageIcon("Graphics/g1Background"));
            //jf.add(l);
            //l.setVisible(true);
            //jf.setExtendedState(jf.MAXIMIZED_BOTH);
            //jf.setBackground(Color.gray);
     
     
            //jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            //jf.setVisible(true);
            nodeGUI node1 = new nodeGUI(1);
            whole.setSize(xSize, ySize);
            whole.add(node1, A);
     
            a.setOpaque(true);
            setContentPane(a);
        }
    }

    This is the class that draws the GUI:
    package GUI;
     
    import Game.Game;
    import GamePlay.Player;
    import Map.MakeMapOne;
    import Node.Node;
    import java.awt.Graphics;
    import Map.Map;
    import java.awt.Color;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.List;
     
    /**
     *
     * 
     */
    public class gameGUI extends javax.swing.JPanel {
     
        private Game game;
        private boolean lfcard;//boolean for if they are looking for turn
        private boolean lfnode;
        private int columnnum;
        private int nodenum;
        /** Creates new form GameInterface */
        public gameGUI(Game g) {
            game=g;
            node=new nodeGUI[22];
            cardb=new cardButton[7];
            initComponents();
            setBackgroundTranslucent();
            setNodes(game.getMap());
            jLabel1.setText(game.getPlayers()[0].getUserName());
            jLabel2.setText(game.getPlayers()[1].getUserName());
            lfcard=false;
            lfnode=true;
            addActionListeners();
            setCards();
            repaint();
     
            //repaint();
        }
        public void addActionListeners(){
            for(int i=0;i<7;i++){
                final int ifinal=i;
                cardb[i].addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e)
                    {
                        if(lfcard==false){
                            System.out.println("not looking for card nigga "+ifinal);
                        }
                        else{
                            if(game.getTurn()==1||game.getTurn()==3){
                                if(game.verifyCard(game.getMap().getColumn(columnnum)[nodenum], ifinal)){
                                    game.move(game.getMap().getColumn(columnnum)[nodenum], ifinal);
                                     setNodes(game.getMap());
                                     setCards();
                                     repaint();
                                     lfnode=true;//looking for node
                                     lfcard=false;//not looking for card;
                                }
                            }
                            else{
     
                                 game.block(game.getMap().getColumn(columnnum)[nodenum], ifinal);
                                 setNodes(game.getMap());
                                 setCards();
                                 repaint();
                                 lfnode=true;//looking for node
                                 lfcard=false;//not looking for card;
     
                            }
                        }
                    }
                });
            }
            StartButton.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e)
                    {
     
                    }
                });
            for(int i=0;i<22;i++){
                final int ifinal=i;
                node[i].addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e)
                    {
                        int column=(int)(ifinal/3);
                        int node=ifinal%3;
                        if(lfnode==false){
                            System.out.println("not looking for node nigga "+ifinal);
                        }
                        else{
                            //turn = 1 or 3
                            if(game.getTurn()==3||game.getTurn()==1){
                                if(game.checkMove(game.getMap().getColumn(column)[node])){
                                    //prompt for card
                                    columnnum=column;//saving the column number for access later
                                    nodenum=node;//saving the node number for acces later
                                    lfnode=false;//not looking for node
                                    lfcard=true;//looking for card;
                                }
                            }
                            else{
                                if(game.isBlockable(game.getMap().getColumn(column)[node])){
                                    //prompt for card
                                    columnnum=column;//saving the column number for access later
                                    nodenum=node;//saving the node number for acces later
                                    lfnode=false;//not looking for node
                                    lfcard=true;//looking for card;
                                }
     
     
                            }
     
                            //turn = 2 or 4
     
                        }
                    }
                });
            }
        }
        public void setCards(){
            int player;
            System.out.println(game.getTurn());
            if(game.getTurn()<3)player=0;
            else player=1;
            int cards=game.getPlayers()[player].cardCount();
            Player p=game.getPlayers()[player];
            for(int i=0;i<7;i++){
                if(i<cards){
                    cardb[i].setsIcon(p.getCard(i).getGraphic());
                }
                else{
                    cardb[i].setsIcon("Graphics/emptyCard.jpg");
                }
     
            }
        }
        public void setNodes(Map m){
            Node test;
            Player[] ps;
     
     
            test=m.getStart();
            ps=game.getPlayers();
            if(ps[0].getPosition().equals(test)){
                if(ps[1].getPosition().equals(test)){
     
                     StartButton.setsIcon(test.getValue(),3);
                }
                else{
                     StartButton.setsIcon(test.getValue(),1);
                }
            }
            else{
                if(ps[1].getPosition().equals(test)){
                     StartButton.setsIcon(test.getValue(),2);
               }
                else{
                    StartButton.setsIcon(test.getValue());
                }
            }
     
            for(int i =0;i<7;i++){
                for(int j=0;j<3;j++){
                    test=m.getColumn(i)[j];
                    ps=game.getPlayers();
                    if(ps[0].getPosition().equals(test)){
                       if(ps[1].getPosition().equals(test)){
                             node[i*3+j].setsIcon(test.getValue(),3);
                       }
                       else{
                            node[i*3+j].setsIcon(test.getValue(),1);
                       }
                    }
                    else{
                        if(ps[1].getPosition().equals(test)){
                             node[i*3+j].setsIcon(test.getValue(),2);
                       }
                        else{
                            node[i*3+j].setsIcon(test.getValue());
                        }
                    }
     
                }
            }
     
     
            test=m.getColumn(7)[0];
            ps=game.getPlayers();
            if(ps[0].getPosition().equals(test)){
                if(ps[1].getPosition().equals(test)){
                     node[21].setsIcon(test.getValue(),3);
                }
                else{
                     node[21].setsIcon(test.getValue(),1);
                }
            }
            else{
                if(ps[1].getPosition().equals(test)){
                     node[21].setsIcon(test.getValue(),2);
               }
                else{
                    node[21].setsIcon(test.getValue());
                }
            }
     
        }
        public void setBackgroundTranslucent(){
            jPanel1.setOpaque(false);
            //jPanel1.setBackground(Color.red);
     
        }
        public Node[] forwardNodes(List l){
            Node[] n=new Node[3];
            for(int i=0;i<l.size();i++){
                n[i]=(Node)l.get(i);
            }
            return n;
        }
        public Graphics drawLines(Map m, Graphics g){
            Node[] first;
            Node[] second;
            int spot=0;
            int y=0;
            int y1=0;
            int x;
            for(int i=0;i<6;i++){
                x=75+i*150;
                first=m.getColumn(i);
                second=m.getColumn(i+1);
                for(int n=0;n<3;n++){
                    if(n==0)y1=167;
                    if(n==1)y1=285;
                    if(n==2)y1=390;
                    Node at=first[n];
                    List l=at.getForwardPaths();
                    for(int lines=0;lines<l.size();lines++){
                        for(int s=0;s<3;s++){
                            if(((Node)l.get(lines)).equals(second[s])){
                                spot=s;
                            }
                        }
                        if(spot==0)y=167;
                        if(spot==1)y=285;
                        if(spot==2)y=390;
                        g.drawLine(x+150, y1, x+300, y);
                    }
     
                }
            }
            return g;
        }
        public void paintComponent(Graphics page){
            super.paintComponent(page);
            page=drawLines(game.getMap(),page);
            page.drawLine(75, 285, 225,167 );
            page.drawLine(75, 285, 225, 285);
            page.drawLine(75, 285, 225, 390);
            page.drawLine(1125,167 , 1275, 285);
            page.drawLine(1125, 285, 1275,285);
            page.drawLine(1125,390 , 1275, 285);
     
            //page.fillRect(5,5,50,5);
        }
     
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
     
        public void initComponents() {
            java.awt.GridBagConstraints gridBagConstraints;
     
            jPanel1 = new javax.swing.JPanel();
            StartButton = new nodeGUI(1);
            node[0] = new nodeGUI(1);
            node[1] = new nodeGUI(1);
            node[2] = new nodeGUI(1);
            node[3] = new nodeGUI(1);
            node[4] = new nodeGUI(1);
            node[5] = new nodeGUI(1);
            node[6] = new nodeGUI(4);
            node[7] = new nodeGUI(4);
            node[8] = new nodeGUI(4);
            node[9] = new nodeGUI(1);
            node[10] = new nodeGUI(1);
            node[11] = new nodeGUI(4);
            node[12] = new nodeGUI(4);
            node[13] = new nodeGUI(4);
            node[14] = new nodeGUI(4);
            node[15] = new nodeGUI(4);
            node[16] = new nodeGUI(4);
            node[17] = new nodeGUI(4);
            node[18] = new nodeGUI(4);
            node[19] = new nodeGUI(4);
            node[20] = new nodeGUI(4);
            node[21] = new nodeGUI(4);
            jLabel3 = new javax.swing.JLabel();
            jLabel4 = new javax.swing.JLabel();
            jLabel1 = new javax.swing.JLabel();
            jLabel2 = new javax.swing.JLabel();
            jPanel2 = new javax.swing.JPanel();
            cardb[0] = new cardButton(game.getPlayers()[0].getCard(0).getGraphic());
            cardb[1] = new cardButton(game.getPlayers()[0].getCard(1).getGraphic());
            cardb[2] = new cardButton(game.getPlayers()[0].getCard(2).getGraphic());
            cardb[3] = new cardButton(game.getPlayers()[0].getCard(3).getGraphic());
            cardb[4] = new cardButton(game.getPlayers()[0].getCard(4).getGraphic());
            cardb[5] = new cardButton(game.getPlayers()[0].getCard(5).getGraphic());
            cardb[6] = new cardButton(game.getPlayers()[0].getCard(6).getGraphic());
            jButton1 = new javax.swing.JButton();
     
            jPanel1.setLayout(new java.awt.GridBagLayout());
     
            StartButton.setText(null);
            StartButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    StartButtonActionPerformed(evt);
                }
            });
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 0;
            gridBagConstraints.gridy = 2;
            gridBagConstraints.insets = new java.awt.Insets(50, 50, 50, 50);
            jPanel1.add(StartButton, gridBagConstraints);
     
            node[0].setText(null);
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 2;
            gridBagConstraints.gridy = 0;
            jPanel1.add(node[0], gridBagConstraints);
     
            node[1].setText(null);
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 2;
            gridBagConstraints.gridy = 2;
            gridBagConstraints.insets = new java.awt.Insets(50, 50, 50, 50);
            jPanel1.add(node[1], gridBagConstraints);
     
            node[2].setText(null);
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 2;
            gridBagConstraints.gridy = 4;
            jPanel1.add(node[2], gridBagConstraints);
     
            node[3].setText(null);
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 4;
            gridBagConstraints.gridy = 0;
            jPanel1.add(node[3], gridBagConstraints);
     
            node[4].setText(null);
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 4;
            gridBagConstraints.gridy = 2;
            gridBagConstraints.ipady = 5;
            gridBagConstraints.insets = new java.awt.Insets(50, 50, 50, 50);
            jPanel1.add(node[4], gridBagConstraints);
     
            node[5].setText(null);
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 4;
            gridBagConstraints.gridy = 4;
            jPanel1.add(node[5], gridBagConstraints);
     
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 6;
            gridBagConstraints.gridy = 0;
            jPanel1.add(node[6], gridBagConstraints);
     
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 6;
            gridBagConstraints.gridy = 2;
            gridBagConstraints.insets = new java.awt.Insets(50, 50, 50, 50);
            jPanel1.add(node[7], gridBagConstraints);
     
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 6;
            gridBagConstraints.gridy = 4;
            jPanel1.add(node[8], gridBagConstraints);
     
            node[9].setText(null);
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 8;
            gridBagConstraints.gridy = 0;
            jPanel1.add(node[9], gridBagConstraints);
     
            node[10].setText(null);
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 8;
            gridBagConstraints.gridy = 2;
            gridBagConstraints.insets = new java.awt.Insets(50, 50, 50, 50);
            jPanel1.add(node[10], gridBagConstraints);
     
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 8;
            gridBagConstraints.gridy = 4;
            jPanel1.add(node[11], gridBagConstraints);
     
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 10;
            gridBagConstraints.gridy = 0;
            jPanel1.add(node[12], gridBagConstraints);
     
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 10;
            gridBagConstraints.gridy = 2;
            gridBagConstraints.insets = new java.awt.Insets(50, 50, 50, 50);
            jPanel1.add(node[13], gridBagConstraints);
     
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 10;
            gridBagConstraints.gridy = 4;
            jPanel1.add(node[14], gridBagConstraints);
     
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 12;
            gridBagConstraints.gridy = 0;
            jPanel1.add(node[15], gridBagConstraints);
     
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 12;
            gridBagConstraints.gridy = 2;
            gridBagConstraints.insets = new java.awt.Insets(50, 50, 50, 50);
            jPanel1.add(node[16], gridBagConstraints);
     
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 12;
            gridBagConstraints.gridy = 4;
            jPanel1.add(node[17], gridBagConstraints);
     
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 14;
            gridBagConstraints.gridy = 0;
            jPanel1.add(node[18], gridBagConstraints);
     
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 14;
            gridBagConstraints.gridy = 2;
            gridBagConstraints.insets = new java.awt.Insets(50, 50, 50, 50);
            jPanel1.add(node[19], gridBagConstraints);
     
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 14;
            gridBagConstraints.gridy = 4;
            jPanel1.add(node[20], gridBagConstraints);
     
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 16;
            gridBagConstraints.gridy = 2;
            gridBagConstraints.insets = new java.awt.Insets(50, 50, 50, 50);
            jPanel1.add(node[21], gridBagConstraints);
     
            jLabel3.setText("Start Point");
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 0;
            gridBagConstraints.gridy = 1;
            jPanel1.add(jLabel3, gridBagConstraints);
     
            jLabel4.setText("Switch Point");
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 16;
            gridBagConstraints.gridy = 1;
            jPanel1.add(jLabel4, gridBagConstraints);
     
            jLabel1.setText("Player 1");//Player[0].getUserName());
     
        jLabel2.setText("Player2");//Player[1].getUserName());
     
        jPanel2.setLayout(new java.awt.GridBagLayout());
     
        cardb[0].setText("");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 5);
        jPanel2.add(cardb[0], gridBagConstraints);
     
        cardb[1].setText("");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 5);
        jPanel2.add(cardb[1], gridBagConstraints);
     
        cardb[2].setText("");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 5);
        jPanel2.add(cardb[2], gridBagConstraints);
     
        cardb[3].setText("");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 5);
        jPanel2.add(cardb[3], gridBagConstraints);
     
        cardb[4].setText("");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 5);
        jPanel2.add(cardb[4], gridBagConstraints);
     
        cardb[5].setText("");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 5;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 5);
        jPanel2.add(cardb[5], gridBagConstraints);
     
        cardb[6].setText("");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 6;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 5);
        jPanel2.add(cardb[6], gridBagConstraints);
     
        jButton1.setText("jButton1");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.insets = new java.awt.Insets(0, 75, 0, 0);
        jPanel2.add(jButton1, gridBagConstraints);
     
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 1773, Short.MAX_VALUE)
                .addComponent(jLabel2)
                .addGap(58, 58, 58))
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(1102, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(182, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2))
                .addGap(115, 115, 115)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE))
        );
        }// </editor-fold>
     
        public void StartButtonActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
        }
     
     
        public nodeGUI[] node;
        public nodeGUI StartButton;
        public cardButton[] cardb;
        public javax.swing.JButton jButton1;
        public javax.swing.JLabel jLabel1;
        public javax.swing.JLabel jLabel2;
        public javax.swing.JLabel jLabel3;
        public javax.swing.JLabel jLabel4;
        public javax.swing.JPanel jPanel1;
        public javax.swing.JPanel jPanel2;
        // End of variables declaration
     
    }
    The html followed by the jnlp file:
    <body>
        ....
        <script src="http://www.java.com/js/deployJava.js"></script>
        <script> 
            var attributes = { code:'testGUI.testGUI',  width:300, height:300} ; 
            var parameters = {jnlp_href: 'Game.jnlp'} ; 
            deployJava.runApplet(attributes, parameters, '1.6'); 
        </script>
        ....
    </body>
    <?xml version="1.0" encoding="UTF-8"?>
    <jnlp spec="1.0+" codebase="" href="">
        <information>
            <title>TBS</title>
            <vendor>TBS</vendor>
        </information>
        <resources>
            <!-- Application Resources -->
            <j2se version="1.6+"
                  href="http://java.sun.com/products/autodl/j2se"/>
            <jar href="Game.jar" main="true" />
     
        </resources>
        <applet-desc
             name="TBS"
             main-class="testGUI.testGUI"
             width="300"
             height="300">
         </applet-desc>
         <update check="background"/>
    </jnlp>
    There are more classes but those are the main ones responsible for drawing the GUI. Since we made the game and the web components at different times, my guess would be that something in the game code is not compatible with japplet browser capabilities. Any advice would be appreciated.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Java applet on web showing gray box

    Does it work if you view it through an IDE? Does your Java Console show any errors?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Dec 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java applet on web showing gray box

    Quote Originally Posted by KevinWorkman View Post
    Does it work if you view it through an IDE? Does your Java Console show any errors?
    It works fine through an IDE, no errors.

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Java applet on web showing gray box

    I meant, do you see any errors in the Java Console when you run it in a webpage? When you see the gray box, does your Java Console have any errors?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Junior Member
    Join Date
    Dec 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java applet on web showing gray box

    Quote Originally Posted by KevinWorkman View Post
    I meant, do you see any errors in the Java Console when you run it in a webpage? When you see the gray box, does your Java Console have any errors?
    Oh sorry, no just a blank gray box.

  6. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Java applet on web showing gray box

    Are you sure you're looking at the Java Console? It's not visible by default.

    If so, I'd recommend throwing in some print statements and looking at them in the Java Console to get to the bottom of your problem.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    Junior Member
    Join Date
    Dec 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java applet on web showing gray box

    Thanks that helped, I didn't even have it enabled. I'm getting a java.lang.reflect.InvocationTargetException, not sure what causes that since I don't have any duplicate classes. I have run into this problem before because of duplicate classes, not sure what its complaining about this time though.

    Edit: Making progress, created a project with no classes seems to have gotten rid of the exception. Thanks for telling me about the console, I had no idea that even existed. That probably should have been one the first things I learned in comp sci... oh well better late than never.
    Last edited by MyName; December 2nd, 2011 at 04:32 PM.

Similar Threads

  1. 2D Java Applet Games
    By bbr201 in forum Java Theory & Questions
    Replies: 26
    Last Post: August 27th, 2010, 09:12 AM
  2. Java Applet and MySQL
    By Terillius in forum JDBC & Databases
    Replies: 4
    Last Post: August 21st, 2010, 10:05 PM
  3. Applet using .mp3 control in java
    By ychopade in forum Java Applets
    Replies: 0
    Last Post: July 15th, 2010, 07:26 AM
  4. Need help with java applet game.
    By vlan in forum What's Wrong With My Code?
    Replies: 0
    Last Post: April 10th, 2010, 04:18 AM
  5. Help with 1st Java applet game!
    By Sneak in forum Java Applets
    Replies: 0
    Last Post: November 28th, 2009, 11:20 AM