Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Other Java > Java GUI
|
Java GUI Discussions specific to programming Java GUI.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java GUI section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 5th, 2006, 11:28 PM
Registered User
 
Join Date: Apr 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default JLabels.. im so bad at GUIs

Hey All,
Yes this is a NUB of a question, I'm trying to make a GUI with a JPanel that will have a 10x10 grid layout, in that grid i want to place a 10x10 array of labels containing animated GIFs. Is there some reason that this won't work? if not please take a look at my code and tell me what Im doing wrong.


thanks
DanLatimer


Code:
package gameGUIView;
import java.applet.*;
import java.awt.*;
import java.net.*;

import javax.swing.*;
import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.GridLayout;
import javax.swing.JLabel;
import javax.swing.ImageIcon;

public class GameGUView extends JFrame {
  //  @jve:decl-index=0:visual-constraint="161,29"

    private JPanel gridPane = null;
    private JPanel canvas = null;
    private JPanel controlPanel = null;
    private JPanel framePane = null;
    private JLabel[][] pic = null;
    private JButton turnLeft = null;
    private JButton walkForword = null;
    private JButton turnRight = null;
    private JButton Sensor = null;
    public GameGUView() {



        this.setAlwaysOnTop(true);


        this.show();
        initialize();
        repaint();
        this.show();
    }




    /**
     * This method initializes this
     * 
     */
    private void initialize() {

        try {
            this.setSize(new java.awt.Dimension(400,550));
            this.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
            this.setContentPane(getFramePane());
            this.setTitle("Maze V.1b");
            this.setPreferredSize(new java.awt.Dimension(400,550));
            this.setResizable(false);
            this.setName("mainFrame");

        }
        catch (java.lang.Throwable e) {
            //  Do Something
        }
    }


    public void paint (Graphics g) {
        //g.drawImage (new ImageIcon("background.gif").getImage(), 0, 32, canvas); 
        //g.drawImage(new ImageIcon("MogFinger.gif").getImage(), 200,200, mainPanel);


    }




    /**
     * This method initializes jContentPane    
     *     
     * @return javax.swing.JPanel    
     */
    private JPanel getGridPane() {
        if (gridPane == null) {
            try {
                for(int i = 0; i < 10; i++) {
                    for(int j = 0; j < 10; j++) {
                        pic[i][j] = new JLabel();
                        pic[i][j].setText("A");
                        pic[i][j].setVisible(true);
                        //pic[i][j].setIcon(new ImageIcon(getClass().getResource("/MogFinger.gif")));
                    }
                }
                GridLayout gridLayout = new GridLayout();
                gridLayout.setRows(10);
                gridLayout.setColumns(10);
                gridPane = new JPanel();
                gridPane.setPreferredSize(new java.awt.Dimension(400,400));
                gridPane.setLayout(gridLayout);
                for(int i = 0; i < 10; i++) {
                    for(int j = 0; j < 10; j++) {
                        gridPane.add(pic[i][j], null);
                    }
                }
            } catch (java.lang.Throwable e) {
                // TODO: Something
            }
        }
        return gridPane;
    }




    /**
     * This method initializes canvas    
     *     
     * @return javax.swing.JPanel    
     */
    private JPanel getCanvas() {
        if (canvas == null) {
            try {
                canvas = new JPanel();
                canvas.add(getGridPane(), null);
            } catch (java.lang.Throwable e) {
                // TODO: Something
            }
        }
        return canvas;
    }




    /**
     * This method initializes controlPanel    
     *     
     * @return javax.swing.JPanel    
     */
    private JPanel getControlPanel() {
        if (controlPanel == null) {
            try {
                controlPanel = new JPanel();
                controlPanel.add(getTurnLeft(), null);
                controlPanel.add(getWalkForword(), null);
                controlPanel.add(getTurnRight(), null);
                controlPanel.add(getSensor(), null);
            } catch (java.lang.Throwable e) {
                // TODO: Something
            }
        }
        return controlPanel;
    }




    /**
     * This method initializes framePane    
     *     
     * @return javax.swing.JPanel    
     */
    private JPanel getFramePane() {
        if (framePane == null) {
            try {
                framePane = new JPanel();
                framePane.setLayout(new BorderLayout());
                framePane.add(getCanvas(), java.awt.BorderLayout.CENTER);
                framePane.add(getControlPanel(), java.awt.BorderLayout.SOUTH);
            } catch (java.lang.Throwable e) {
                // TODO: Something
            }
        }
        return framePane;
    }




    /**
     * This method initializes label    
     *     
     * @return javax.swing.JLabel    
     */


    /**
     * This method initializes turnLeft    
     *     
     * @return javax.swing.JButton    
     */
    private JButton getTurnLeft() {
        if (turnLeft == null) {
            try {
                turnLeft = new JButton();
                turnLeft.setName("");
                turnLeft.setText("Turn Left");
            } catch (java.lang.Throwable e) {
                // TODO: Something
            }
        }
        return turnLeft;
    }




    /**
     * This method initializes walkForword    
     *     
     * @return javax.swing.JButton    
     */
    private JButton getWalkForword() {
        if (walkForword == null) {
            try {
                walkForword = new JButton();
                walkForword.setText("Walk Forword");
            } catch (java.lang.Throwable e) {
                // TODO: Something
            }
        }
        return walkForword;
    }




    /**
     * This method initializes turnRight    
     *     
     * @return javax.swing.JButton    
     */
    private JButton getTurnRight() {
        if (turnRight == null) {
            try {
                turnRight = new JButton();
                turnRight.setText("Turn Right");
            } catch (java.lang.Throwable e) {
                // TODO: Something
            }
        }
        return turnRight;
    }




    /**
     * This method initializes Sensor    
     *     
     * @return javax.swing.JButton    
     */
    private JButton getSensor() {
        if (Sensor == null) {
            try {
                Sensor = new JButton();
                Sensor.setText("Sensor");
            } catch (java.lang.Throwable e) {
                // TODO: Something
            }
        }
        return Sensor;
    }

}  //  @jve:decl-index=0:visual-constraint="73,17"





Similar Threads
Thread Thread Starter Forum Replies Last Post
Im leanring a new language ironchef ASP.NET 1.0 and 1.1 Basics 1 December 3rd, 2007 09:39 AM
im new with c# i need help tunisiano C# 7 February 17th, 2007 04:54 AM
im new here and i need ur help.... momoi Beginning VB 6 2 January 30th, 2006 11:44 PM
Im having a BIG issue here! macupryk General .NET 1 October 10th, 2004 05:24 AM
Im new in P2PForum darkdog BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 2 June 20th, 2003 01:11 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.