Jump to content
  • Advertisement
Sign in to follow this  
ABCDEFG123

JLabels .. GUI junk

This topic is 4485 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey All, 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 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[j] = new JLabel(); pic[j].setText("A"); pic[j].setVisible(true); //pic[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[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"

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!