Results 1 to 6 of 6
Thread: Basic GUI help
- 10-11-2010, 12:49 AM #1
Member
- Join Date
- Aug 2010
- Posts
- 10
- Rep Power
- 0
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.
ThanksJava 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 }Last edited by vahshir; 10-11-2010 at 01:24 AM.
- 10-11-2010, 01:20 AM #2
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.
- 10-11-2010, 01:25 AM #3
Member
- Join Date
- Aug 2010
- Posts
- 10
- Rep Power
- 0
I have redone the code now and it does compile i know it does because i just compiled it and im using netbeans.
-
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.
- 10-11-2010, 01:31 AM #5
Does the code you just changed show the problem?
Please explain what your problem is?with nothing in the jButtons i have in the jPanel.
What is supposed to be "in the jButton"?
-
Similar Threads
-
Need really basic help!
By anthonyalaan in forum New To JavaReplies: 9Last Post: 09-12-2010, 01:43 PM -
Basic Help
By robjames in forum New To JavaReplies: 3Last Post: 02-09-2009, 02:58 AM -
Need some really basic help
By Mayur in forum New To JavaReplies: 6Last Post: 01-24-2009, 06:00 AM -
Basic Applet
By jkswebsite in forum Java AppletsReplies: 4Last Post: 01-13-2008, 09:14 PM -
help with basic example
By fred in forum New To JavaReplies: 1Last Post: 07-20-2007, 05:45 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks