Results 1 to 5 of 5
Thread: Gui Swing Creator
- 10-01-2008, 05:07 AM #1
Member
- Join Date
- Sep 2008
- Posts
- 31
- Rep Power
- 0
Gui Swing Creator
I was fooling around with the gui swing creator in netbeans. when i try to run it, the app doesnt show. any ideas why?
Java Code:/* * NewJPanel.java * * Created on September 30, 2008, 9:20 PM */ /** * * @author Isaac */ public class NewJPanel extends javax.swing.JPanel { /** Creates new form NewJPanel */ public NewJPanel() { 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() { jMenuBar1 = new javax.swing.JMenuBar(); jMenu1 = new javax.swing.JMenu(); jMenu2 = new javax.swing.JMenu(); jFrame1 = new javax.swing.JFrame(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); jButton4 = new javax.swing.JButton(); jButton5 = new javax.swing.JButton(); jButton6 = new javax.swing.JButton(); jButton7 = new javax.swing.JButton(); jButton8 = new javax.swing.JButton(); jButton9 = new javax.swing.JButton(); jTextField1 = new javax.swing.JTextField(); jButton10 = new javax.swing.JButton(); jButton11 = new javax.swing.JButton(); jButton12 = new javax.swing.JButton(); jButton13 = new javax.swing.JButton(); jButton14 = new javax.swing.JButton(); jButton15 = new javax.swing.JButton(); jButton16 = new javax.swing.JButton(); jMenu1.setText("File"); jMenuBar1.add(jMenu1); jMenu2.setText("Edit"); jMenuBar1.add(jMenu2); 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) ); jButton1.setText("9"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jButton2.setText("8"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); jButton3.setText("7"); jButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton3ActionPerformed(evt); } }); jButton4.setText("6"); jButton4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton4ActionPerformed(evt); } }); jButton5.setText("5"); jButton5.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton5ActionPerformed(evt); } }); jButton6.setText("4"); jButton6.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton6ActionPerformed(evt); } }); jButton7.setText("3"); jButton7.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton7ActionPerformed(evt); } }); jButton8.setText("2"); jButton8.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton8ActionPerformed(evt); } }); jButton9.setText("1"); jButton9.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton9ActionPerformed(evt); } }); jTextField1.setText("jTextField1"); jButton10.setText("/"); jButton10.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton10ActionPerformed(evt); } }); jButton11.setText("*"); jButton11.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton11ActionPerformed(evt); } }); jButton12.setText("-"); jButton12.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton12ActionPerformed(evt); } }); jButton13.setText("0"); jButton13.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton13ActionPerformed(evt); } }); jButton14.setText("."); jButton14.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton14ActionPerformed(evt); } }); jButton15.setText("="); jButton15.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton15ActionPerformed(evt); } }); jButton16.setText("+"); jButton16.setDebugGraphicsOptions(javax.swing.DebugGraphics.NONE_OPTION); jButton16.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton16ActionPerformed(evt); } }); 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() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(jTextField1, javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(jButton13, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton9, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jButton14, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton8, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 39, Short.MAX_VALUE) .addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGap(6, 6, 6) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jButton7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, 40, Short.MAX_VALUE) .addComponent(jButton15, 0, 0, Short.MAX_VALUE) .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jButton10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton12, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton16, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton3) .addComponent(jButton2) .addComponent(jButton1) .addComponent(jButton10)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton6) .addComponent(jButton5) .addComponent(jButton4) .addComponent(jButton11)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton9) .addComponent(jButton8) .addComponent(jButton7) .addComponent(jButton12)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton13) .addComponent(jButton14) .addComponent(jButton15) .addComponent(jButton16)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); }// </editor-fold> private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { //8 String num = jTextField1.getText(); jTextField1.setText(num + '8'); } private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) { //7 String num = jTextField1.getText(); jTextField1.setText(num + '8'); } private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { //9 String num = jTextField1.getText(); jTextField1.setText(num + '8'); } private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) { //divide } private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) { // four String num = jTextField1.getText(); jTextField1.setText(num + '8'); } private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) { //five String num = jTextField1.getText(); jTextField1.setText(num + '8'); } private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) { //six String num = jTextField1.getText(); jTextField1.setText(num + '8'); } private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) { // multiply } private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) { // one String num = jTextField1.getText(); jTextField1.setText(num + '8'); } private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) { //two String num = jTextField1.getText(); jTextField1.setText(num + '8'); } private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) { // three String num = jTextField1.getText(); jTextField1.setText(num + '8'); } private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) { //minus } private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) { // zero String num = jTextField1.getText(); jTextField1.setText(num + '8'); } private void jButton14ActionPerformed(java.awt.event.ActionEvent evt) { //decmal } private void jButton15ActionPerformed(java.awt.event.ActionEvent evt) { // equals } private void jButton16ActionPerformed(java.awt.event.ActionEvent evt) { //plus } // Variables declaration - do not modify private javax.swing.JButton jButton1; private javax.swing.JButton jButton10; private javax.swing.JButton jButton11; private javax.swing.JButton jButton12; private javax.swing.JButton jButton13; private javax.swing.JButton jButton14; private javax.swing.JButton jButton15; private javax.swing.JButton jButton16; private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; private javax.swing.JButton jButton4; private javax.swing.JButton jButton5; private javax.swing.JButton jButton6; private javax.swing.JButton jButton7; private javax.swing.JButton jButton8; private javax.swing.JButton jButton9; private javax.swing.JFrame jFrame1; private javax.swing.JMenu jMenu1; private javax.swing.JMenu jMenu2; private javax.swing.JMenuBar jMenuBar1; private javax.swing.JTextField jTextField1; // End of variables declaration }
-
NetBeans creates a class that compiles, but nothing runs without a main method, something this class doesn't have. Also, you'll have to put this JPanel into a JFrame, something that can be done in the main method, and then set the JFrame visible for this to display anything.
But having said that, I will strongly recommend that you don't use the NetBeans code-generating machinery until you know how to code in Swing. If you use NetBeans without first knowing Swing, the tool will hinder your Swing education by months, trust me.
- 10-01-2008, 10:31 AM #3
I second Fubarable's recommendation. And speaking from my own albeit limited experience, I'd say that once you learn to code Swing GUIs manually (which takes less time and effort than you might initially expect), you won't even want to go back to IDE generated layouts.
db
- 10-02-2008, 12:34 AM #4
Member
- Join Date
- Sep 2008
- Posts
- 31
- Rep Power
- 0
how would i add a main method to this?
-
Just as you would add any main method. Have you done this before? Created a class with a main method? If not, then hit the tutorials starting from the beginning. If so, then you'll need to ask a somewhat better question, first of all specifying exactly what you don't understand.
Also, you have some unanswered replies your ActionListener thread in the Swing section.
Similar Threads
-
MVC and swing
By jurka in forum AWT / SwingReplies: 1Last Post: 09-15-2008, 02:32 PM -
Java Studio Creator - Bd Alterar
By wagnerbarbos in forum JCreatorReplies: 0Last Post: 06-09-2008, 06:19 PM -
What is next to Swing
By javaplus in forum AWT / SwingReplies: 1Last Post: 01-13-2008, 11:16 PM -
map javax.swing.text.Element to javax.swing.text.View
By elizabeth in forum New To JavaReplies: 1Last Post: 07-30-2007, 08:02 PM -
swing?? why use it
By javaforme44a in forum AWT / SwingReplies: 3Last Post: 07-18-2007, 08:51 AM
Bookmarks