Results 1 to 7 of 7
  1. #1
    iminhell is offline Member
    Join Date
    Oct 2010
    Posts
    5
    Rep Power
    0

    Default Sharing information between tabbed jframe?

    Again, not sure how to describe what I'm looking for. New to all this and the proper terminology is my main issue I think. But I'll try to explain what I want best I can.


    I want to use the circled information from these first two pictures in a formula that will display a result on the last picture:








    The last pictures uses a total of 3 user inputs but for 2 other tabs. It's laid out in a order of events layout. First you complete the first tab, then the second and when you go to the third the result will already be there. It's there because when you push the button on tab two it calculates both the result for tab two and for tab three. Or at least that's what my goal is.

    I'm not sure if posting the code will aid in help at all, but if it does it's posted below. Red being what I thought should work but doesn't. The error returned reads:
    cannot find symbol
    symbol: variable pci
    location: class NewJFrame



    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    /*
     * NewJFrame.java
     *
     * Created on Oct 30, 2010, 2:10:36 PM
     */
    
    /**
     *
     * @author John
     */
    public class NewJFrame extends javax.swing.JFrame {
    
        /** Creates new form NewJFrame */
        public NewJFrame() {
            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() {
    
            jTabbedPane1 = new javax.swing.JTabbedPane();
            jPanel1 = new javax.swing.JPanel();
            jLabel1 = new javax.swing.JLabel();
            jLabel2 = new javax.swing.JLabel();
            temp = new javax.swing.JTextField();
            pres = new javax.swing.JTextField();
            jLabel3 = new javax.swing.JLabel();
            jLabel4 = new javax.swing.JLabel();
            jButton1 = new javax.swing.JButton();
            jLabel5 = new javax.swing.JLabel();
            jLabel6 = new javax.swing.JLabel();
            jLabel7 = new javax.swing.JLabel();
            jLabel8 = new javax.swing.JLabel();
            jPanel2 = new javax.swing.JPanel();
            jLabel9 = new javax.swing.JLabel();
            stroke = new javax.swing.JTextField();
            rpm = new javax.swing.JTextField();
            jLabel10 = new javax.swing.JLabel();
            jLabel11 = new javax.swing.JLabel();
            jLabel13 = new javax.swing.JLabel();
            jButton2 = new javax.swing.JButton();
            jLabel12 = new javax.swing.JLabel();
            jPanel3 = new javax.swing.JPanel();
            jLabel14 = new javax.swing.JLabel();
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    
            jPanel1.setBackground(new java.awt.Color(204, 204, 204));
    
            jLabel1.setText("Temperature");
    
            jLabel2.setText("Pressure");
    
            jLabel3.setText(" Fahrenheit");
    
            jLabel4.setText("Pounds per Square Inch");
    
            jButton1.setText("Calculate");
            jButton1.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(153, 153, 0), 1, true));
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton1ActionPerformed(evt);
                }
            });
    
            jLabel5.setText("********");
    
            jLabel6.setText("Pounds per Cubic Inch");
    
            jLabel7.setText("********");
    
            jLabel8.setText("Feet per Second");
    
            javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(47, 47, 47)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabel2)
                        .addComponent(jLabel1)
                        .addComponent(jLabel5)
                        .addComponent(jLabel7))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                        .addComponent(pres, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(temp, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel8)
                        .addComponent(jLabel3)
                        .addComponent(jLabel4)
                        .addComponent(jLabel6))
                    .addGap(237, 237, 237))
            );
    
            jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {pres, temp});
    
            jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(30, 30, 30)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                        .addComponent(temp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel1)
                        .addComponent(jLabel3))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(pres, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel2)
                        .addComponent(jLabel4))
                    .addGap(26, 26, 26)
                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 40, Short.MAX_VALUE)
                    .addGap(26, 26, 26)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel6)
                        .addComponent(jLabel5))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel8)
                        .addComponent(jLabel7))
                    .addGap(65, 65, 65))
            );
    
            jPanel1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {pres, temp});
    
            jTabbedPane1.addTab("Temp, PSI", jPanel1);
    
            jPanel2.setBackground(new java.awt.Color(204, 204, 204));
    
            jLabel9.setText("Stroke in Inches");
    
            jLabel10.setText("Revolutions per Minute");
    
            jLabel11.setText("Mean Piston Speed");
    
            jLabel13.setText("Feet per Minute");
    
            jButton2.setText("Calculate");
            jButton2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton2ActionPerformed(evt);
                }
            });
    
            jLabel12.setText("********");
    
            javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
            jPanel2.setLayout(jPanel2Layout);
            jPanel2Layout.setHorizontalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addContainerGap()
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel11, javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel10, javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel9, javax.swing.GroupLayout.Alignment.TRAILING))
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel2Layout.createSequentialGroup()
                                    .addGap(4, 4, 4)
                                    .addComponent(stroke, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel2Layout.createSequentialGroup()
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(rpm, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel2Layout.createSequentialGroup()
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jLabel12)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jLabel13))))
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addGap(112, 112, 112)
                            .addComponent(jButton2)))
                    .addContainerGap(119, Short.MAX_VALUE))
            );
    
            jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {rpm, stroke});
    
            jPanel2Layout.setVerticalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addGap(28, 28, 28)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel9)
                        .addComponent(stroke, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel10)
                        .addComponent(rpm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(jButton2)
                    .addGap(13, 13, 13)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel12)
                        .addComponent(jLabel13))
                    .addContainerGap(132, Short.MAX_VALUE))
            );
    
            jTabbedPane1.addTab("Mean Piston", jPanel2);
    
            jLabel14.setText("********");
    
            javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
            jPanel3.setLayout(jPanel3Layout);
            jPanel3Layout.setHorizontalGroup(
                jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup()
                    .addGap(142, 142, 142)
                    .addComponent(jLabel14)
                    .addContainerGap(185, Short.MAX_VALUE))
            );
            jPanel3Layout.setVerticalGroup(
                jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup()
                    .addGap(104, 104, 104)
                    .addComponent(jLabel14)
                    .addContainerGap(154, Short.MAX_VALUE))
            );
    
            jTabbedPane1.addTab("Wavelength", jPanel3);
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
            );
    
            pack();
        }// </editor-fold>
    
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
     float t, p, pci, fps;
    
    // Gets temperature from the text field, and then parses it to type float.
    t = Float.parseFloat(temp.getText());
    p = Float.parseFloat(pres.getText());
        
    //Simple statement for calculations
    
    pci =   (float) (1.325 * (2.036254 * p / (459.67 + t)));
    fps =   (float) Math.sqrt(1.4*1716*(t+459.67));
    
    //Writes the total
    jLabel5.setText(String.valueOf(pci));
    jLabel7.setText(String.valueOf(fps));
        }                                        
    
        private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    float mean, s, r,[COLOR="Red"]wave[/COLOR];
    
    // Gets Mean Piston Speed
    s = Float.parseFloat(stroke.getText());
    r = Float.parseFloat(rpm.getText());
    
    //Simple statement for calculations
            
    mean = r*s/6;
    [COLOR="Red"]wave = (float) (pci/(r/60)*12);[/COLOR]
    //Totals
    jLabel12.setText(String.valueOf(mean));
    [COLOR="Red"]jLabel14.setText(String.valueOf(wave));[/COLOR]
        }                                        
    
        /**
        * @param args the command line arguments
        */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new NewJFrame().setVisible(true);
                }
            });
        }
    
        // Variables declaration - do not modify
        private javax.swing.JButton jButton1;
        private javax.swing.JButton jButton2;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel10;
        private javax.swing.JLabel jLabel11;
        private javax.swing.JLabel jLabel12;
        private javax.swing.JLabel jLabel13;
        private javax.swing.JLabel jLabel14;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JLabel jLabel3;
        private javax.swing.JLabel jLabel4;
        private javax.swing.JLabel jLabel5;
        private javax.swing.JLabel jLabel6;
        private javax.swing.JLabel jLabel7;
        private javax.swing.JLabel jLabel8;
        private javax.swing.JLabel jLabel9;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JPanel jPanel2;
        private javax.swing.JPanel jPanel3;
        private javax.swing.JTabbedPane jTabbedPane1;
        private javax.swing.JTextField pres;
        private javax.swing.JTextField rpm;
        private javax.swing.JTextField stroke;
        private javax.swing.JTextField temp;
        // End of variables declaration
    
    }
    Last edited by iminhell; 10-31-2010 at 08:38 PM.

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

    Default

    Create a private method, something like:
    Java Code:
       private void calcGrandSum() {
    
          //.....
    
       }
    And inside of this method check if the other panels have completed their calculations by checking the appropriate JLabels (which should all be given names that make logical sense -- it will help debugging) have numeric text data. If so, do the calculation and display it in the third JPanel.

    Then call this method at the end of both jButton1ActionPerformed and jButton2ActionPerformed. That way if you go back and change any of your calculations, you'll see the change reflected in the third JPanel.

    Also, if you're going to use variables such as "pci" in other methods, then such variables need to have class scope -- need to be declared in the class, not in a method. Otherwise they're only visible from within the method.

    Much luck!

  3. #3
    iminhell is offline Member
    Join Date
    Oct 2010
    Posts
    5
    Rep Power
    0

    Default

    I didn't name the labels because for some reason doing so didn't work out right. Not sure why but to avoid roadblocks I left them as default. I know what is what, but I understand that someone else won't, or them trying to help may get confused.


    So I got it working, and looking at it now it seems very simple.

    went from this:

    Java Code:
        private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    float mean, s, r,wave;
    
    // Gets Mean Piston Speed
    s = Float.parseFloat(stroke.getText());
    r = Float.parseFloat(rpm.getText());
    
    //Simple statement for calculations
            
    mean = r*s/6;
    wave = (float) (pci/(r/60)*12);
    //Totals
    jLabel12.setText(String.valueOf(mean));
    jLabel14.setText(String.valueOf(wave));
        }

    To this:

    Java Code:
        private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    float mean, s, r,wave,f;
    
    // Gets Mean Piston Speed
    s = Float.parseFloat(stroke.getText());
    r = Float.parseFloat(rpm.getText());
    f = Float.parseFloat(jLabel7.getText());
    
    //Simple statement for calculations
            
    mean = r*s/6;
    
    //Totals
    jLabel12.setText(String.valueOf(mean));
    //Finds the wavelength
    wave = (f/(r/60)*12);
    jLabel14.setText(String.valueOf(wave));
    
        }

    It now works. But my result isn't quite correct. Wondering if that may have something to do with your statement yesterday about using the 'double' function instead of (or is it along with?) the float statement?

    How is that written? (float.double, float double and floatdouble don't seem to be correct)



    Also,
    a) I'm assuming statements like "//words on a post, this does that to get nowhere" are simply reminders of what is being done and not used by the program for anything. Meaning that if I wish to leave people in the dark, or myself, I can leave those things out and it won't effect the program at all?

    b) For an "if" statement, how do you word it so any number is acceptable?
    Tried something to the affect of "if (jLabel5>null)" and I got an error, can't recall what error, sorry. But "null" would mean a blank or no data, correct?

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

    Default

    Quote Originally Posted by iminhell View Post
    I didn't name the labels because for some reason doing so didn't work out right. Not sure why but to avoid roadblocks I left them as default. I know what is what, but I understand that someone else won't, or them trying to help may get confused.
    Once you do some serious programming, you'll find that when you come back to a program like this a few months from now, especially if it is a much larger program, you yourself will have trouble figuring out what each generic-named variable is. If you're using code-generation software, part of the problem may be in how you're using this. Most of them will allow you to change a variable's name, but you have to do it correctly and through the code-generation program itself.


    So I got it working, and looking at it now it seems very simple.
    Good deal.


    went from this:

    Java Code:
        private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    float mean, s, r,wave;
    
    // Gets Mean Piston Speed
    s = Float.parseFloat(stroke.getText());
    r = Float.parseFloat(rpm.getText());
    
    //Simple statement for calculations
            
    mean = r*s/6;
    wave = (float) (pci/(r/60)*12);
    //Totals
    jLabel12.setText(String.valueOf(mean));
    jLabel14.setText(String.valueOf(wave));
        }

    To this:

    Java Code:
        private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    float mean, s, r,wave,f;
    
    // Gets Mean Piston Speed
    s = Float.parseFloat(stroke.getText());
    r = Float.parseFloat(rpm.getText());
    f = Float.parseFloat(jLabel7.getText());
    
    //Simple statement for calculations
            
    mean = r*s/6;
    
    //Totals
    jLabel12.setText(String.valueOf(mean));
    //Finds the wavelength
    wave = (f/(r/60)*12);
    jLabel14.setText(String.valueOf(wave));
    
        }
    I've no idea if that's correct or not, mainly due to the variable names.


    It now works. But my result isn't quite correct. Wondering if that may have something to do with your statement yesterday about using the 'double' function instead of (or is it along with?) the float statement?
    Again, I'm not sure if your equations are correct. Changing from float to double will improve the accuracy of your calculations but shouldn't change the rough correctness of the number, if that makes sense. The result returned by float calculations should be pretty close to the true result.



    How is that written? (float.double, float double and floatdouble don't seem to be correct)
    Not sure what you're asking here.


    Also,
    a) I'm assuming statements like "//words on a post, this does that to get nowhere" are simply reminders of what is being done and not used by the program for anything. Meaning that if I wish to leave people in the dark, or myself, I can leave those things out and it won't effect the program at all?
    Yes, comments will be ignored by the compiler. I've seen sneaky exceptions however when unicode literals have been used, but ignore that for now.


    b) For an "if" statement, how do you word it so any number is acceptable?
    Tried something to the affect of "if (jLabel5>null)" and I got an error, can't recall what error, sorry. But "null" would mean a blank or no data, correct?
    Hm The JLabel's text shouldn't be null, I don't believe, but it can be empty. So something like

    Java Code:
    String text5 = jLabel5.getText().trim(); // These variable names make me cringe!
    if (!text5.isEmpty()) {
       // here you'll want to parse the number to double via Double.parseDouble, but
       // if it's a JTextField, do it within a try / catch (NumberFormatException) so as to trap for 
       // non-numeric data entry.
    }

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

    Default

    Also: This program looks like a good place to start considering model / view separation.

    For instance, your data model would be the numeric data entered and the results of calculation, and this would be extracted into its own class, a class that does not concern itself with GUI or any type of user interaction. Then the GUI uses an object of this class to do the calculations correctly.

  6. #6
    iminhell is offline Member
    Join Date
    Oct 2010
    Posts
    5
    Rep Power
    0

    Default

    Ok I think I got how most of this works then and I see what I'll have to do for an if statement when I get that far, isEmpty seems pretty self explanatory now that I see it, lol.

    Labels, right now this is just a rough draft/learning project. I will use parts of it later for a final draft and at that time I'll label things correct. Right now I just want to concentrate on seeing how things work. Going very well so far. I'm picking things up far quicker than I thought I would, blame some of that on NetBeans. Seems to be a great program and very straightforward.


    Quote Originally Posted by Fubarable View Post
    Also: This program looks like a good place to start considering model / view separation.

    For instance, your data model would be the numeric data entered and the results of calculation, and this would be extracted into its own class, a class that does not concern itself with GUI or any type of user interaction. Then the GUI uses an object of this class to do the calculations correctly.

    I've no clue what any of that means, lol. I'll search on it and see what I can find out. Sounds like it'd be something I should be doing.
    And I'm curious, (suppose I'll find out once I do some reading) can it record and fill in columns? Say someone enters a temp and a pressure and gets a result; if I have columns for temp, pressure and result would it make a list of all the inputs and outputs as they change?
    No clue how to make these columns, just thinking out loud basically. I'll have to read up on that too.
    Last edited by iminhell; 10-31-2010 at 10:33 PM.

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

    Default

    Quote Originally Posted by iminhell View Post
    Ok I think I got how most of this works then and I see what I'll have to do for an if statement when I get that far, isEmpty seems pretty self explanatory now that I see it, lol.
    Good deal.



    Labels, right now this is just a rough draft/learning project. I will use parts of it later for a final draft and at that time I'll label things correct. Right now I just want to concentrate on seeing how things work. Going very well so far. I'm picking things up far quicker than I thought I would, blame some of that on NetBeans. Seems to be a great program and very straightforward.
    I love NetBeans as an IDE but do not like its drag-and-drop code generation except as a prototyping tool. I see too many student programmers using it, not understanding what Swing is doing under the hood (because the by using this program, they don't have to), and then painting themselves in a corner any time the GUI has to be anything more than the most basic of GUIs.


    I've no clue what any of that means, lol. I'll search on it and see what I can find out. Sounds like it'd be something I should be doing.
    That's OK. If you keep progressing at your current rate, you'll understand this soon enough. But in a nutshell, you'd create a non-GUI class that would hold all of the variables and methods necessary to do your calculations:
    Java Code:
    public class DataModel {
       public static final double ABSOLUTE_ZERO_FAHRENHEIT = -459.67;
       public static final double GAMMA = 1.4;
       public static final int GAS_CONSTANT_R = 1716;
       private double tempFahrenheit = 0;
       private double pressurePSI = 0;
       
       public double getTempFahrenheit() {
          return tempFahrenheit;
       }
       public void setTempFahrenheit(double tempFahrenheit) {
          this.tempFahrenheit = tempFahrenheit;
       }
       public double getPressurePSI() {
          return pressurePSI;
       }
       public void setPressurePSI(double pressurePSI) {
          this.pressurePSI = pressurePSI;
       }
       
       public double calculatePoundsPerCubicInch() {
          double pci = 1.325 * (2.036254 * pressurePSI / (tempFahrenheit - ABSOLUTE_ZERO_FAHRENHEIT));
          
          return pci;
       }
       
       public double calculateFeetPerSecond() {
          double fps = Math.sqrt(GAMMA * GAS_CONSTANT_R * (459.67 - ABSOLUTE_ZERO_FAHRENHEIT));
          return fps;
       }
    }
    Then you'd have your GUI hold an instance of this class and use the methods to do the necessary calculations. Of course your data model class would be larger than this one above so that it could do the other calculations necessary for the other parts of your application.


    And I'm curious, (suppose I'll find out once I do some reading) can it record and fill in columns? Say someone enters a temp and a pressure and gets a result; if I have columns for temp, pressure and result would it make a list of all the inputs and outputs as they change?
    No clue how to make these columns, just thinking out loud basically. I'll have to read up on that too.
    Yes, it can do all that. Often you would use an ArrayList of objects that would hold these values as your model, either that or a DefaultTableModel object if you are displaying your data in a JTable.
    Last edited by Fubarable; 10-31-2010 at 11:17 PM.

Similar Threads

  1. Tabbed pane
    By sonal12 in forum AWT / Swing
    Replies: 13
    Last Post: 09-15-2010, 01:22 AM
  2. tabbed Pane .
    By programmer_007 in forum AWT / Swing
    Replies: 2
    Last Post: 09-03-2009, 09:52 PM
  3. JTree and Tabbed Pane
    By paluee in forum AWT / Swing
    Replies: 1
    Last Post: 03-30-2009, 07:03 AM
  4. Tabbed pane using struts 2.x......?
    By prabhurangan in forum Web Frameworks
    Replies: 1
    Last Post: 07-19-2008, 07:48 AM
  5. AWT can we make a Tabbed container?
    By Panchitopro in forum AWT / Swing
    Replies: 0
    Last Post: 05-15-2008, 11:31 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
  •