473,397 Members | 2,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Loads of extra code!

176 100+
This is pretty stupid. You can create the same program one using this much code:
Expand|Select|Wrap|Line Numbers
  1. /*
  2.  * blah.java
  3.  *
  4.  * Created on May 26, 2008, 9:35 AM
  5.  */
  6.  
  7. package blah;
  8.  
  9. /**
  10.  *
  11.  * @author  Ned
  12.  */
  13. public class blah extends javax.swing.JFrame {
  14.  
  15.     /** Creates new form blah */
  16.     public blah() {
  17.         initComponents();
  18.     }
  19.  
  20.     /** This method is called from within the constructor to
  21.      * initialize the form.
  22.      * WARNING: Do NOT modify this code. The content of this method is
  23.      * always regenerated by the Form Editor.
  24.      */
  25.     @SuppressWarnings("unchecked")
  26.     // <editor-fold defaultstate="collapsed" desc="Generated Code">
  27.     private void initComponents() {
  28.  
  29.         jButton1 = new javax.swing.JButton();
  30.         jScrollPane1 = new javax.swing.JScrollPane();
  31.         jTextArea1 = new javax.swing.JTextArea();
  32.         jButton2 = new javax.swing.JButton();
  33.         num1 = new javax.swing.JTextField();
  34.         num2 = new javax.swing.JTextField();
  35.         calculate_average = new javax.swing.JButton();
  36.         average = new javax.swing.JLabel();
  37.  
  38.         jButton1.setText("jButton1");
  39.         jButton1.addActionListener(new java.awt.event.ActionListener() {
  40.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  41.                 jButton1ActionPerformed(evt);
  42.             }
  43.         });
  44.  
  45.         jTextArea1.setColumns(20);
  46.         jTextArea1.setRows(5);
  47.         jScrollPane1.setViewportView(jTextArea1);
  48.  
  49.         jButton2.setText("jButton2");
  50.         jButton2.addActionListener(new java.awt.event.ActionListener() {
  51.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  52.                 jButton2ActionPerformed(evt);
  53.             }
  54.         });
  55.  
  56.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  57.  
  58.         num1.setText("Number 1");
  59.         num1.addActionListener(new java.awt.event.ActionListener() {
  60.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  61.                 num1ActionPerformed(evt);
  62.             }
  63.         });
  64.  
  65.         num2.setText("Number 2");
  66.         num2.addActionListener(new java.awt.event.ActionListener() {
  67.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  68.                 num2ActionPerformed(evt);
  69.             }
  70.         });
  71.  
  72.         calculate_average.setText("Calculate Average");
  73.         calculate_average.addActionListener(new java.awt.event.ActionListener() {
  74.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  75.                 calculate_averageActionPerformed(evt);
  76.             }
  77.         });
  78.  
  79.         average.setText("Average");
  80.  
  81.         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
  82.         getContentPane().setLayout(layout);
  83.         layout.setHorizontalGroup(
  84.             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
  85.             .add(layout.createSequentialGroup()
  86.                 .add(45, 45, 45)
  87.                 .add(num1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
  88.                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
  89.                 .add(num2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
  90.                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
  91.                 .add(calculate_average)
  92.                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
  93.                 .add(average)
  94.                 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  95.         );
  96.         layout.setVerticalGroup(
  97.             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
  98.             .add(layout.createSequentialGroup()
  99.                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
  100.                     .add(num1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
  101.                     .add(num2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
  102.                     .add(calculate_average)
  103.                     .add(average))
  104.                 .addContainerGap(271, Short.MAX_VALUE))
  105.         );
  106.  
  107.         pack();
  108.     }// </editor-fold>
  109.  
  110. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
  111. // TODO add your handling code here:
  112.  
  113. }                                        
  114.  
  115. private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
  116. // TODO add your handling code here:
  117.  
  118. }                                        
  119.  
  120. private void num1ActionPerformed(java.awt.event.ActionEvent evt) {
  121. // TODO add your handling code here:
  122. }
  123.  
  124. private void num2ActionPerformed(java.awt.event.ActionEvent evt) {
  125. // TODO add your handling code here:
  126. }
  127.  
  128. private void calculate_averageActionPerformed(java.awt.event.ActionEvent evt) {
  129. // TODO add your handling code here:
  130.     int number1, number2, number_average;
  131.     number1 = (int)((Double.parseDouble(num1.getText())));
  132.     number2 = (int)((Double.parseDouble(num2.getText())));
  133.     number_average = number1 + number2 / 2;
  134.     average.setText("" + number_average);
  135. }
  136.  
  137.     /**
  138.     * @param args the command line arguments
  139.     */
  140.     public static void main(String args[]) {
  141.         java.awt.EventQueue.invokeLater(new Runnable() {
  142.             public void run() {
  143.                 new blah().setVisible(true);
  144.             }
  145.         });
  146.     }
  147.  
  148.     // Variables declaration - do not modify
  149.     private javax.swing.JLabel average;
  150.     private javax.swing.JButton calculate_average;
  151.     private javax.swing.JButton jButton1;
  152.     private javax.swing.JButton jButton2;
  153.     private javax.swing.JScrollPane jScrollPane1;
  154.     private javax.swing.JTextArea jTextArea1;
  155.     private javax.swing.JTextField num1;
  156.     private javax.swing.JTextField num2;
  157.     // End of variables declaration
  158.  
  159. }
  160.  
and one using this much code:
Expand|Select|Wrap|Line Numbers
  1. package NumberAverager;
  2.  
  3. import javax.swing.JFrame;
  4. import javax.swing.JButton;
  5. import javax.swing.JTextField;
  6. import javax.swing.JLabel;
  7. import java.awt.Container;
  8. import java.awt.FlowLayout;
  9. import java.awt.event.ActionListener;
  10. import java.awt.event.ActionEvent;
  11.  
  12. abstract class NumberAverager implements ActionListener
  13. {
  14.     public static void main(String[] args)
  15.     {
  16.         //create and set the title for a new frame
  17.         JFrame frame = new JFrame();
  18.         frame.setTitle("Number Averager");
  19.  
  20.         //create a container
  21.         Container contentPane = frame.getContentPane();
  22.  
  23.         //create a layout and apply it to the contentPane
  24.         FlowLayout layout = new FlowLayout();
  25.         frame.setLayout(layout);
  26.  
  27.         //create components
  28.         final JTextField num1 = new JTextField("Number 1");
  29.         final JTextField num2 = new JTextField("Number 2");
  30.  
  31.         JButton calculate_average = new JButton("Calculate average");
  32.  
  33.         final JLabel average = new JLabel("Average");
  34.  
  35.         //add the components
  36.         contentPane.add(num1);
  37.         contentPane.add(num2);
  38.  
  39.         contentPane.add(calculate_average);
  40.  
  41.         contentPane.add(average);
  42.  
  43.         //frame settings
  44.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  45.         frame.pack();
  46.         frame.setVisible(true);
  47.  
  48.         //actions performed
  49.         calculate_average.addActionListener(new ActionListener() 
  50.             {
  51.                 public void actionPerformed(ActionEvent e) 
  52.                 {
  53.                     int number1, number2, number_average;
  54.                     number1 = (int)((Double.parseDouble(num1.getText())));
  55.                     number2 = (int)((Double.parseDouble(num2.getText())));
  56.                     number_average = number1 + number2 / 2;
  57.                     average.setText("" + number_average);
  58.                 }
  59.             });
  60.         }
  61.     }
They have the same output but one is wwwwwwwwwwwwwwwwwwwwwwwwwaaaaaaaaaaaaaaaaaaaaaaaaa aayyyyyyyyyyyyy longer.
May 28 '08 #1
6 1443
JosAH
11,448 Expert 8TB
And your question is?

kind regards,

Jos
May 28 '08 #2
Kid Programmer
176 100+
And your question is?

kind regards,

Jos
My question is why would someone bother to write down the first code in the previous post when you could have a lot less to write in the second listing.
May 28 '08 #3
BigDaddyLH
1,216 Expert 1GB
My question is why would someone bother to write down the first code in the previous post when you could have a lot less to write in the second listing.
I haven't looked at the code closely, but the first version uses GroupLayout, which suggest the code was made using a tool.
May 28 '08 #4
Laharl
849 Expert 512MB
Yeah, the top one looks to have been generated by Netbeans.
May 28 '08 #5
Kid Programmer
176 100+
Yeah, the top one looks to have been generated by Netbeans.
Yes it has been. But what is the point of it. They could make it so much simpler.
May 28 '08 #6
BigDaddyLH
1,216 Expert 1GB
Yes it has been. But what is the point of it. They could make it so much simpler.
Some GUI layout tools allow you to select the LayoutManager for a given container, but it seems that the default preference is for absolute positioning.

In any case, people who care about their code eschew those tools.
May 28 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

17
by: abs | last post by:
My element: <span onclick="alert('test')" id="mySpan">test</span> Let's say that I don't know what is in this span's onclick event. Is it possible to add another action to this element's onclick...
2
by: TD | last post by:
This should be simple but I can't figure it out! I have a form bound to a query. On this form is a combo box that is bound to the same query. When the form loads the combo box is blank. If you...
9
by: Neil Ginsberg | last post by:
I have a strange situation using Access to automate a Word mail merge. Using Access 2000 and Word 2000, the code opens Word, opens the document in Word, sets a table in the calling Access...
1
by: mark | last post by:
Hi I am trying to count the number of times a page loads. When I hit the submit button I can get the page to count once using ispostback to check . I am trying to incriment a variable everytime...
16
by: whyyyy | last post by:
The script below works fine if the form is filled out and submitted. But a (blank) e-mail is sent whenever the page loads, even when the form is not submitted. I would like to receive the e-mail...
11
by: cdkorzen | last post by:
I'm sorry if this is a rehash, but all I see is the same info. Here's my debacle: I CAN get the PATH_INFO to work. With ANYTHING but ASP. Python, Perl, Cmd files... works fine. ASP can't...
2
by: abcd | last post by:
I have the following code which is sent over the wire as a string... from time import time class Foo: def go(self): print "Time:", time() I get this code and store it as, "data"
8
by: dancer | last post by:
Using ASP.net 1.1 to create user input form. When I put a RequiredFieldValidator I have extra space at the bottom of the cell, as if I had put a <br>. When I comment out the...
0
by: tullyrob | last post by:
If you run the following simple line of code in IE the webpage loads a default page but the same code run in Mozilla loads fine. --- <html> <iframe name=stbbox...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.