Results 1 to 6 of 6

Thread: Basic GUI help

  1. #1
    vahshir is offline Member
    Join Date
    Aug 2010
    Posts
    10
    Rep Power
    0

    Default Basic GUI help

    Well im having pa problem with this GUI im trying to make when ever i run it, it comes up with nothing in the jButtons i have in the jPanel.

    here is code.

    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    /*
     * GUI.java
     *
     * Created on 11/10/2010, 11:59:34 AM
     */
    
    package ShapeViewer;
    
    /**
     *
     * @author Administrator
     */
    public class GUI extends javax.swing.JFrame {
    
        /** Creates new form GUI */
        public GUI() {
            initComponents();
        }
    
        /** 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.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
    
            jFrame1 = new javax.swing.JFrame();
            jPanel1 = new javax.swing.JPanel();
            circleButton = new javax.swing.JButton();
            rectangleButton = new javax.swing.JButton();
            triangleButton = new javax.swing.JButton();
            selectionBar = new javax.swing.JComboBox();
            jMenuBar1 = new javax.swing.JMenuBar();
            jMenu1 = new javax.swing.JMenu();
            jMenu2 = new javax.swing.JMenu();
    
            javax.swing.GroupLayout jFrame1Layout = new javax.swing.GroupLayout(jFrame1.getContentPane());
            jFrame1.getContentPane().setLayout(jFrame1Layout);
            jFrame1Layout.setHorizontalGroup(
                jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 400, Short.MAX_VALUE)
            );
            jFrame1Layout.setVerticalGroup(
                jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 300, Short.MAX_VALUE)
            );
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    
            jPanel1.setBackground(new java.awt.Color(204, 204, 204));
            jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
    
            if(selectionBar.getSelectedIndex() == 0)
            {
                circleButton.setText("Create Circle");
            }
            else if (selectionBar.getSelectedIndex() == 1)
            {
                circleButton.setText("Delete Circle");
            }
            circleButton.updateUI();
    
            if(selectionBar.getSelectedIndex() == 0)
            {
                rectangleButton.setText("Create Rectangle");
            }
            else if (selectionBar.getSelectedIndex() == 1)
            {
                rectangleButton.setText("Delete Rectangle");
            }
            rectangleButton.updateUI();
    
            if(selectionBar.getSelectedIndex() == 0)
            {
                triangleButton.setText("Create Triangle");
            }
            else if(selectionBar.getSelectedIndex() == 1)
            {
                triangleButton.setText("Delete Triangle");
            }
            triangleButton.updateUI();
    
            selectionBar.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Drawing Mode", "Selection Mode"}));
    
            javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(triangleButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE)
                        .addComponent(circleButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(rectangleButton, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE))
                    .addGap(92, 92, 92))
                .addComponent(selectionBar, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)
            );
            jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addComponent(selectionBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(32, 32, 32)
                    .addComponent(circleButton)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(rectangleButton)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(triangleButton)
                    .addContainerGap(337, Short.MAX_VALUE))
            );
    
            jMenu1.setText("File");
            jMenuBar1.add(jMenu1);
    
            jMenu2.setText("Edit");
            jMenuBar1.add(jMenu2);
    
            setJMenuBar(jMenuBar1);
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(406, Short.MAX_VALUE))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            );
    
            pack();
        }// </editor-fold>
    
        /**
        * @param args the command line arguments
        */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new GUI().setVisible(true);
                }
            });
        }
    
        // Variables declaration - do not modify
        private javax.swing.JButton circleButton;
        private javax.swing.JFrame jFrame1;
        private javax.swing.JMenu jMenu1;
        private javax.swing.JMenu jMenu2;
        private javax.swing.JMenuBar jMenuBar1;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JButton rectangleButton;
        private javax.swing.JComboBox selectionBar;
        private javax.swing.JButton triangleButton;
        // End of variables declaration
    
    }
    Thanks
    Last edited by vahshir; 10-11-2010 at 02:24 AM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    Your code does not compile.
    Please don't post code that does not compile with complaints about it not executing correctly.
    You're wasting everyones time if the code you post is NOT the code you are executing.

  3. #3
    vahshir is offline Member
    Join Date
    Aug 2010
    Posts
    10
    Rep Power
    0

    Default

    I have redone the code now and it does compile i know it does because i just compiled it and im using netbeans.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    OP, read up in the tutorials how to use action listeners since your code needs these to add these to your menu items to get the behavior you desire. The Oracle tutorials will show you the way. Oh and I second Norm's comment.

    Luck.

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    Does the code you just changed show the problem?
    with nothing in the jButtons i have in the jPanel.
    Please explain what your problem is?
    What is supposed to be "in the jButton"?

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Need really basic help!
    By anthonyalaan in forum New To Java
    Replies: 9
    Last Post: 09-12-2010, 02:43 PM
  2. Basic Help
    By robjames in forum New To Java
    Replies: 3
    Last Post: 02-09-2009, 03:58 AM
  3. Need some really basic help
    By Mayur in forum New To Java
    Replies: 6
    Last Post: 01-24-2009, 07:00 AM
  4. Basic Applet
    By jkswebsite in forum Java Applets
    Replies: 4
    Last Post: 01-13-2008, 10:14 PM
  5. help with basic example
    By fred in forum New To Java
    Replies: 1
    Last Post: 07-20-2007, 06:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •