9 Replies - 4097 Views - Last Post: 03 December 2011 - 11:58 PM Rate Topic: -----

#1 west-wot  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 03-December 11

Need help with inheritance from a GUI in netbeans

Posted 03 December 2011 - 10:52 PM

Hi there i need help with being able to inhert data from my GUI into another class and i am not sure how to do this, i know my buttons are are private void and i have got code inside them, and i can not change the buttons from private to public as it will not help me, please help i am so stuck on this :(
Is This A Good Question/Topic? 0
  • +

Replies To: Need help with inheritance from a GUI in netbeans

#2 macosxnerd101  Icon User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12134
  • View blog
  • Posts: 45,117
  • Joined: 27-December 08

Re: Need help with inheritance from a GUI in netbeans

Posted 03 December 2011 - 10:58 PM

Please avoid using the NetBeans GUI builder. It produces horrid, unmaintainable code that we cannot read.

Also, your program state and data should be separate from the GUI. I would create a singleton StateManager class to manage the program state and data. Then have the GUI get/set the appropriate data from the StateManager.
Was This Post Helpful? 0
  • +
  • -

#3 jon.kiparsky  Icon User is online

  • Screw Trump (before he screws you)
  • member icon


Reputation: 10625
  • View blog
  • Posts: 18,185
  • Joined: 19-March 11

Re: Need help with inheritance from a GUI in netbeans

Posted 03 December 2011 - 10:59 PM

I can well believe that you're stuck; your question doesn't make a lot of sense - for a start, inheritance doesn't mean what you think it does. I suspect that you're trying to pass data acquired from the user from your GUI to a class that's going to do some work with it.
You'd do this by calling a method of the class that's going to do the work, and passing the data as a parameter to that method.

If you can post some code and say more explicitly what it is you're trying to do, you might get more useful help. However, you might want to browse through the tutorials first, the answers you want are probably in there.

EDIT: mac's right, though - if it's GUI builder code, there's not a lot anyone's going to be able to do for you. Better to write your GUI yourself, at least to the point where you understand what the builder is doing for you. After that point, if you want to switch to generated code, that's your funeral.

This post has been edited by jon.kiparsky: 03 December 2011 - 11:00 PM

Was This Post Helpful? 0
  • +
  • -

#4 west-wot  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 03-December 11

Re: Need help with inheritance from a GUI in netbeans

Posted 03 December 2011 - 11:06 PM

Ok thank you, sorry if the question id not make sense, i have created a GUI that allows me to input certain data such as length and width, and it outputs these and also works out area, now what i am trying to do is move these to another class
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pipesrus;

/**
 *
 * @author Richard
 */
public abstract class Type {
    
    
    protected int grade,colour,answer;
    protected boolean inner,outer,chemical;
    protected double price,costpipe;
    
    public Type(){
        
    }
    
    public Type(int grade, int colour, boolean inner, boolean outer){
       this.grade=grade;
       this.colour=colour;
       this.inner=inner;
       this.outer=outer; 
 
    }
    
    abstract int determinType();
    
    
    abstract double ExtraCost();
    
    
    
}





sorry that is the wrong code above, thats the code for the other class im trying to use, heres the code for the GUI


package pipesrus;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import java.io.*;    // you need this for the I/O
import java.util.*;   // you need this for the Scanner class
import java.text.NumberFormat;
import javax.swing.JOptionPane;

/**
 *
 * @author Richard Dennis
 */

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() {

        sizePanel = new javax.swing.JPanel();
        sizeTotalLabel = new javax.swing.JLabel();
        lengthLabel = new javax.swing.JLabel();
        diameterLabel = new javax.swing.JLabel();
        lengthText = new javax.swing.JTextField();
        diameterText = new javax.swing.JTextField();
        calculateButton = new javax.swing.JButton();
        exitButton = new javax.swing.JButton();
        gradePanel = new javax.swing.JPanel();
        gradeLabel = new javax.swing.JLabel();
        gradeSlider = new javax.swing.JSlider();
        gradeTitleLabel = new javax.swing.JLabel();
        coloursPanel = new javax.swing.JPanel();
        colourTitleLabel = new javax.swing.JLabel();
        colour1Label = new javax.swing.JLabel();
        colour2Label = new javax.swing.JLabel();
        coloursNumberPanel = new javax.swing.JPanel();
        coloursCombobox = new javax.swing.JComboBox();
        numberOfColoursLabel = new javax.swing.JLabel();
        colour2Text = new javax.swing.JTextField();
        colour1Text = new javax.swing.JTextField();
        optionsPanel = new javax.swing.JPanel();
        optionsTitleLabel = new javax.swing.JLabel();
        insulationCheckbox = new javax.swing.JCheckBox();
        reinforcementCheckbox = new javax.swing.JCheckBox();
        chemicalResistanceCheckbox = new javax.swing.JCheckBox();
        resetButton = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        quantityLabel = new javax.swing.JLabel();
        quantityText = new javax.swing.JTextField();
        PipesRUsLabel = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Pipes R Us Ordering");

        sizePanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        sizeTotalLabel.setFont(new java.awt.Font("Tahoma", 0, 18));
        sizeTotalLabel.setText("Size");

        lengthLabel.setText("Length (Meters)");

        diameterLabel.setText("Diameter (Inches)");

        lengthText.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                lengthTextActionPerformed(evt);
            }
        });

        diameterText.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                diameterTextActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout sizePanelLayout = new javax.swing.GroupLayout(sizePanel);
        sizePanel.setLayout(sizePanelLayout);
        sizePanelLayout.setHorizontalGroup(
            sizePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(sizePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(sizePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(sizePanelLayout.createSequentialGroup()
                        .addGroup(sizePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(diameterLabel)
                            .addComponent(lengthLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(sizePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lengthText, javax.swing.GroupLayout.DEFAULT_SIZE, 347, Short.MAX_VALUE)
                            .addComponent(diameterText, javax.swing.GroupLayout.DEFAULT_SIZE, 347, Short.MAX_VALUE))
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, sizePanelLayout.createSequentialGroup()
                        .addComponent(sizeTotalLabel)
                        .addGap(186, 186, 186))))
        );
        sizePanelLayout.setVerticalGroup(
            sizePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, sizePanelLayout.createSequentialGroup()
                .addComponent(sizeTotalLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(sizePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lengthLabel)
                    .addComponent(lengthText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(sizePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(diameterLabel)
                    .addComponent(diameterText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        calculateButton.setText("Calculate");
        calculateButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                calculateButtonActionPerformed(evt);
            }
        });

        exitButton.setText("Exit");
        exitButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitButtonActionPerformed(evt);
            }
        });

        gradePanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        gradeLabel.setText("Plastic Grade");

        gradeSlider.setMajorTickSpacing(1);
        gradeSlider.setMaximum(5);
        gradeSlider.setMinimum(1);
        gradeSlider.setPaintLabels(true);
        gradeSlider.setPaintTicks(true);
        gradeSlider.setValue(1);

        gradeTitleLabel.setFont(new java.awt.Font("Tahoma", 0, 14));
        gradeTitleLabel.setText("Grade");

        javax.swing.GroupLayout gradePanelLayout = new javax.swing.GroupLayout(gradePanel);
        gradePanel.setLayout(gradePanelLayout);
        gradePanelLayout.setHorizontalGroup(
            gradePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(gradePanelLayout.createSequentialGroup()
                .addGroup(gradePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(gradePanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(gradeLabel)
                        .addGap(18, 18, 18)
                        .addComponent(gradeSlider, javax.swing.GroupLayout.DEFAULT_SIZE, 127, Short.MAX_VALUE))
                    .addGroup(gradePanelLayout.createSequentialGroup()
                        .addGap(85, 85, 85)
                        .addComponent(gradeTitleLabel)))
                .addContainerGap())
        );
        gradePanelLayout.setVerticalGroup(
            gradePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(gradePanelLayout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(gradeTitleLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(gradeSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(33, 33, 33))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, gradePanelLayout.createSequentialGroup()
                .addContainerGap(55, Short.MAX_VALUE)
                .addComponent(gradeLabel)
                .addGap(51, 51, 51))
        );

        coloursPanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        coloursPanel.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        colourTitleLabel.setFont(new java.awt.Font("Tahoma", 0, 14));
        colourTitleLabel.setText("Colours");

        colour1Label.setText("Colour 1");

        colour2Label.setText("Colour 2");

        coloursNumberPanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        coloursCombobox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "0", "1", "2" }));
        coloursCombobox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                coloursComboboxActionPerformed(evt);
            }
        });

        numberOfColoursLabel.setText("Number");

        javax.swing.GroupLayout coloursNumberPanelLayout = new javax.swing.GroupLayout(coloursNumberPanel);
        coloursNumberPanel.setLayout(coloursNumberPanelLayout);
        coloursNumberPanelLayout.setHorizontalGroup(
            coloursNumberPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, coloursNumberPanelLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(numberOfColoursLabel)
                .addGap(10, 10, 10))
            .addGroup(coloursNumberPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(coloursCombobox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(16, Short.MAX_VALUE))
        );
        coloursNumberPanelLayout.setVerticalGroup(
            coloursNumberPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, coloursNumberPanelLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(numberOfColoursLabel)
                .addGap(18, 18, 18)
                .addComponent(coloursCombobox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        colour2Text.setEnabled(false);

        colour1Text.setEnabled(false);
        colour1Text.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                colour1TextActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout coloursPanelLayout = new javax.swing.GroupLayout(coloursPanel);
        coloursPanel.setLayout(coloursPanelLayout);
        coloursPanelLayout.setHorizontalGroup(
            coloursPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, coloursPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(coloursNumberPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(coloursPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(coloursPanelLayout.createSequentialGroup()
                        .addComponent(colour2Label)
                        .addGap(18, 18, 18)
                        .addComponent(colour2Text, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(coloursPanelLayout.createSequentialGroup()
                        .addComponent(colour1Label)
                        .addGap(18, 18, 18)
                        .addComponent(colour1Text)))
                .addGap(20, 20, 20))
            .addGroup(coloursPanelLayout.createSequentialGroup()
                .addGap(88, 88, 88)
                .addComponent(colourTitleLabel)
                .addContainerGap(92, Short.MAX_VALUE))
        );
        coloursPanelLayout.setVerticalGroup(
            coloursPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, coloursPanelLayout.createSequentialGroup()
                .addComponent(colourTitleLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(coloursPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(coloursNumberPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(coloursPanelLayout.createSequentialGroup()
                        .addGroup(coloursPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(colour1Label)
                            .addComponent(colour1Text, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(coloursPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(colour2Label)
                            .addComponent(colour2Text, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(28, 28, 28))
        );

        optionsPanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        optionsTitleLabel.setFont(new java.awt.Font("Tahoma", 0, 18));
        optionsTitleLabel.setText("Options");

        insulationCheckbox.setFont(new java.awt.Font("Tahoma", 0, 14));
        insulationCheckbox.setText("Inner Insulation");
        insulationCheckbox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                insulationCheckboxActionPerformed(evt);
            }
        });

        reinforcementCheckbox.setFont(new java.awt.Font("Tahoma", 0, 14));
        reinforcementCheckbox.setText("Outter Reinforcement");
        reinforcementCheckbox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                reinforcementCheckboxActionPerformed(evt);
            }
        });

        chemicalResistanceCheckbox.setFont(new java.awt.Font("Tahoma", 0, 14));
        chemicalResistanceCheckbox.setText("Chemical Resistance");
        chemicalResistanceCheckbox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chemicalResistanceCheckboxActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout optionsPanelLayout = new javax.swing.GroupLayout(optionsPanel);
        optionsPanel.setLayout(optionsPanelLayout);
        optionsPanelLayout.setHorizontalGroup(
            optionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(optionsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(optionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(optionsPanelLayout.createSequentialGroup()
                        .addGap(166, 166, 166)
                        .addComponent(optionsTitleLabel))
                    .addComponent(insulationCheckbox, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35, Short.MAX_VALUE)
                .addComponent(reinforcementCheckbox)
                .addGap(36, 36, 36))
            .addGroup(optionsPanelLayout.createSequentialGroup()
                .addGap(129, 129, 129)
                .addComponent(chemicalResistanceCheckbox)
                .addContainerGap(187, Short.MAX_VALUE))
        );
        optionsPanelLayout.setVerticalGroup(
            optionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(optionsPanelLayout.createSequentialGroup()
                .addGroup(optionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(optionsPanelLayout.createSequentialGroup()
                        .addGap(44, 44, 44)
                        .addComponent(insulationCheckbox))
                    .addGroup(optionsPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(optionsTitleLabel)
                        .addGap(8, 8, 8)
                        .addComponent(reinforcementCheckbox)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(chemicalResistanceCheckbox)
                .addContainerGap(12, Short.MAX_VALUE))
        );

        resetButton.setText("Reset");
        resetButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                resetButtonActionPerformed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        quantityLabel.setFont(new java.awt.Font("Tahoma", 0, 18));
        quantityLabel.setText("Quantity of pipes required :");

        quantityText.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                quantityTextActionPerformed(evt);
            }
        });

        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(20, 20, 20)
                .addComponent(quantityLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 114, Short.MAX_VALUE)
                .addComponent(quantityText, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(20, 20, 20))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(quantityLabel)
                    .addComponent(quantityText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        PipesRUsLabel.setFont(new java.awt.Font("Tahoma", 0, 36));
        PipesRUsLabel.setText("Pipes 'R' Us");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(sizePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(optionsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(gradePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(coloursPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(exitButton, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(resetButton, javax.swing.GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(calculateButton, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(136, 136, 136)
                        .addComponent(PipesRUsLabel)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(PipesRUsLabel)
                .addGap(33, 33, 33)
                .addComponent(sizePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(coloursPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(gradePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(optionsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(calculateButton)
                    .addComponent(resetButton)
                    .addComponent(exitButton))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>                        

    private void calculateButtonActionPerformed(java.awt.event.ActionEvent evt) {                                                
        // TODO add your handling code here:
        double length, diameter, quanity;
        boolean typeValidation;
        try {
            length = Double.parseDouble(this.lengthText.getText());
            if (length > 0.1 && length < 6.01) {
                System.out.println("Length " + length);
            } else {
                JOptionPane.showMessageDialog(this, "Sorry, We Can Only Produce Pipes Between 0.1 and 6 Meters Long", "Error", JOptionPane.ERROR_MESSAGE);
                return;
            }

        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Please Enter a Length In Numbers In Meters Between 0.1 and 6", "Error", JOptionPane.ERROR_MESSAGE);
            return;
        }
        try {
            diameter = Double.parseDouble(this.diameterText.getText());
            if (diameter > 0.1 && diameter < 20.01) {
                System.out.println("Diameter " + diameter);
            } else {
                JOptionPane.showMessageDialog(this, "Sorry, We Can Only Produce Pipes Between 0.1 and 20 Inches Wide", "Error", JOptionPane.ERROR_MESSAGE);
                return;
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Please Enter The Desired Diameter In Inches For Your Pipe In Numerals", "Error", JOptionPane.ERROR_MESSAGE);
            return;
        }
     
               
       		try{
                    BufferedReader br1 = new BufferedReader(new InputStreamReader(System.in));
		length = Double.parseDouble(this.lengthText.getText());		
				
                                
                               	diameter = Double.parseDouble(this.diameterText.getText());
				double outsidearea = Math.PI*diameter;
                                double innerarea = outsidearea/100*90;
                                double areaneeded = (outsidearea - innerarea);
                                double volume = ((length)*39.37) * areaneeded ;
                                NumberFormat nf = NumberFormat.getInstance();
        // here you can set the number of fractional digits
        nf.setMaximumFractionDigits(2);
               
                                System.out.println("Area of the  pipe in inches = "+ (nf.format(volume)));
			}
			catch(Exception e){
				System.out.println("Error : "+e);
			}   
        System.out.println("Grade: " + gradeSlider.getValue());
        int numberOfColours = Integer.parseInt(coloursCombobox.getSelectedItem().toString());
        System.out.println("The Number of Colours: " + numberOfColours);
        System.out.println("Colour 1: " + colour1Text.getText() + " Colour 2: " + colour2Text.getText());
        
        try {
            quanity = Double.parseDouble(this.quantityText.getText());
            if (quanity > 0 && quanity < 10000.01) {
                System.out.println("Quantity of pipes needed " + quanity);
            } else {
                JOptionPane.showMessageDialog(this, "Sorry, We can not have a negative number in quanity", "Error", JOptionPane.ERROR_MESSAGE);
                return;
            }

        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Please Enter a number of one or greater", "Error", JOptionPane.ERROR_MESSAGE);
            return;
        }
    }                                               

    private void resetButtonActionPerformed(java.awt.event.ActionEvent evt) {                                            
        // TODO add your handling code here:
        lengthText.setText("");
        diameterText.setText("");
        gradeSlider.setValue(1);
        coloursCombobox.setSelectedIndex(0);
        colour1Text.setText("");
        colour2Text.setText("");
        quantityText.setText("");
        reinforcementCheckbox.setSelected(false);
        chemicalResistanceCheckbox.setSelected(false);
        insulationCheckbox.setSelected(false);
    }                                           

    private void exitButtonActionPerformed(java.awt.event.ActionEvent evt) {                                           
        // TODO add your handling code here:
        System.exit(0);
    }                                          

    private void coloursComboboxActionPerformed(java.awt.event.ActionEvent evt) {                                                
        int numberOfColours = Integer.parseInt(coloursCombobox.getSelectedItem().toString());
        if (numberOfColours == 0) {
            colour1Text.setEnabled(false);
            colour2Text.setEnabled(false);
        } else if (numberOfColours == 1) {
            colour1Text.setEnabled(true);
            colour2Text.setEnabled(false);
        } else if (numberOfColours == 2) {
            colour1Text.setEnabled(true);
            colour2Text.setEnabled(true);
            
        }
    }                                               

    private void insulationCheckboxActionPerformed(java.awt.event.ActionEvent evt) {                                                   
        // TODO add your handling code here:
    }                                                  

    private void reinforcementCheckboxActionPerformed(java.awt.event.ActionEvent evt) {                                                      
        // TODO add your handling code here:
    }                                                     

    private void chemicalResistanceCheckboxActionPerformed(java.awt.event.ActionEvent evt) {                                                           
        // TODO add your handling code here:
    }                                                          

    private void colour1TextActionPerformed(java.awt.event.ActionEvent evt) {                                            
        // TODO add your handling code here:
    }                                           

    private void lengthTextActionPerformed(java.awt.event.ActionEvent evt) {                                           
        // TODO add your handling code here:
    }                                          

    private void quantityTextActionPerformed(java.awt.event.ActionEvent evt) {                                             
        // TODO add your handling code here:
    }                                            

    private void diameterTextActionPerformed(java.awt.event.ActionEvent evt) {                                             
        // TODO add your handling code here:
    }                                            

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new GUI().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify                     
    private javax.swing.JLabel PipesRUsLabel;
    private javax.swing.JButton calculateButton;
    private javax.swing.JCheckBox chemicalResistanceCheckbox;
    private javax.swing.JLabel colour1Label;
    private javax.swing.JTextField colour1Text;
    private javax.swing.JLabel colour2Label;
    private javax.swing.JTextField colour2Text;
    private javax.swing.JLabel colourTitleLabel;
    private javax.swing.JComboBox coloursCombobox;
    private javax.swing.JPanel coloursNumberPanel;
    private javax.swing.JPanel coloursPanel;
    private javax.swing.JLabel diameterLabel;
    private javax.swing.JTextField diameterText;
    private javax.swing.JButton exitButton;
    private javax.swing.JLabel gradeLabel;
    private javax.swing.JPanel gradePanel;
    private javax.swing.JSlider gradeSlider;
    private javax.swing.JLabel gradeTitleLabel;
    private javax.swing.JCheckBox insulationCheckbox;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel lengthLabel;
    private javax.swing.JTextField lengthText;
    private javax.swing.JLabel numberOfColoursLabel;
    private javax.swing.JPanel optionsPanel;
    private javax.swing.JLabel optionsTitleLabel;
    private javax.swing.JLabel quantityLabel;
    private javax.swing.JTextField quantityText;
    private javax.swing.JCheckBox reinforcementCheckbox;
    private javax.swing.JButton resetButton;
    private javax.swing.JPanel sizePanel;
    private javax.swing.JLabel sizeTotalLabel;
    // End of variables declaration                   
}



Was This Post Helpful? 0
  • +
  • -

#5 macosxnerd101  Icon User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12134
  • View blog
  • Posts: 45,117
  • Joined: 27-December 08

Re: Need help with inheritance from a GUI in netbeans

Posted 03 December 2011 - 11:08 PM

Move them how? I don't really understand what sort of help you are asking for, but it sounds like your confusion is regarding inheritance and abstraction. Let's work on making sure you have the concepts down first. Worry about the GUI later. And please avoid the NetBeans GUI Builder. We don't support it because the code is so horrid and unmaintainable.

Some tutorials you may find helpful:
Inheritance
Abstract classes vs. interfaces
Was This Post Helpful? 1
  • +
  • -

#6 west-wot  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 03-December 11

Re: Need help with inheritance from a GUI in netbeans

Posted 03 December 2011 - 11:16 PM

thank you for the links, sorry if i am confusing you:

i have a piece of work to do and i am required to ask the user to input some data, length, colour, extras, and grade, i have done this via the gui

however there are several "types" and i must use the data inputted to work out these types and i have been told "
How to determine the type?
You can use ‘brute force’ approach, for example, if (grade greater than 0) and (grade less than 4) and all others are not ordered, then the ordered pipe is of type I."

"designing appropriate hierarchy (data methods and data fields at the appropriate level of abstraction) will allow you to fully implement and use Java inheritance and polymorphism techniques in your application. "

so i am wondering how i would use the information collected in the GUI in the type1 class to know if it is type on as i would need to get the grade, colour etc from the gui to be able to create an IF statement in this class I hope this has made it less confusing
Was This Post Helpful? 0
  • +
  • -

#7 macosxnerd101  Icon User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12134
  • View blog
  • Posts: 45,117
  • Joined: 27-December 08

Re: Need help with inheritance from a GUI in netbeans

Posted 03 December 2011 - 11:22 PM

Honestly, I have no idea what your program is supposed to accomplish. What I got was a lot of buzzwords- inheritance, abstraction, polymorphism, and GUI.

Quote

however there are several "types" and i must use the data inputted to work out these types and i have been told "
How to determine the type?
You can use ‘brute force’ approach, for example, if (grade greater than 0) and (grade less than 4) and all others are not ordered, then the ordered pipe is of type I."

This is why you separate your business logic from your GUI. Since your class is named "Type" and you are populating a "Type" object from the GUI input, having various "Types" is a little confusing for us to follow.

I apologize if I come across as rude, but you need to sit down and really think out the logic some and better articulate what your program is supposed to do. Are you more comfortable with console programs? If so, stick with them. Forget the GUI. The GUI Builder is horrible, and I think using a GUI is confusing you at this point. Let's get the business logic working first with a console application.
Was This Post Helpful? 0
  • +
  • -

#8 jon.kiparsky  Icon User is online

  • Screw Trump (before he screws you)
  • member icon


Reputation: 10625
  • View blog
  • Posts: 18,185
  • Joined: 19-March 11

Re: Need help with inheritance from a GUI in netbeans

Posted 03 December 2011 - 11:32 PM

I hate to say it, but I think there's a lot of stuff that your instructor thinks you've learned, which you clearly haven't. I don't know whose fault that is, and I'm not that concerned with the answer, but it's stuff that you're going to have to learn before you can abide by the first rule here: you bring the code, we bring the help.

I may be wrong, but that's the sense I'm getting here. If that's the case, I can't help you - you need to read up on the material (those tutorials will help) and figure out how to at least ask questions that don't require me to write a small book to answer them, and questions that are specific enough that they can be answered at all.

For example:

Quote

however there are several "types" and i must use the data inputted to work out these types and i have been told "
How to determine the type?


How to determine the type? Do you mean a type as in int, double, float, etc? Or are you talking about different kinds of product, which of course are defined by your business logic, which is what you're here to implement. If it's the latter, you presumably have some input methods, and you need to evaluate the data you get from them.
Your questions don't tell me anything about what it is you want to know. That's a problem, and it's not one that I can help you with, other than by letting you know about it.
Was This Post Helpful? 2
  • +
  • -

#9 west-wot  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 03-December 11

Re: Need help with inheritance from a GUI in netbeans

Posted 03 December 2011 - 11:39 PM

I am sorry that i am not able to put the question across right,

Quote

How to determine the type? Do you mean a type as in int, double, float, etc? Or are you talking about different kinds of product, which of course are defined by your business logic, which is what you're here to implement. If it's the latter, you presumably have some input methods, and you need to evaluate the data you get from them.
Your questions don't tell me anything about what it is you want to know. That's a problem, and it's not one that I can help you with, other than by letting you know about it.


It is the latter, we are talking about different types of a product, i was trying to use the GUI as an input and simply use the information i entered in another class, i guess i will have to read up a lot more
Was This Post Helpful? 0
  • +
  • -

#10 jon.kiparsky  Icon User is online

  • Screw Trump (before he screws you)
  • member icon


Reputation: 10625
  • View blog
  • Posts: 18,185
  • Joined: 19-March 11

Re: Need help with inheritance from a GUI in netbeans

Posted 03 December 2011 - 11:58 PM

Quote

It is the latter, we are talking about different types of a product, i was trying to use the GUI as an input and simply use the information i entered in another class, i guess i will have to read up a lot more


Okay, the two things you need to work on are (obviously) your knowledge of the fundamentals and communicating more precisely what it is you're trying to do and what sort of help you need.


From this, I can only give you a general answer: if you're getting information from a GUI, that information typically comes from the values of the various input elements you define in that GUI. Check boxes, radio buttons, text fields, and all of the other input types, will all report their values by method calls. Check the documentation on each class to find out how to get that information.

Suppose the "type" of a pipe is defined by some set of facts. Let's suppose those are internal diameter and material. In that case, you'd have a method somewhere in the code that defines a Pipe, and that method would accept those facts as parameters, and in the body of that method you'd use those parameters to make whatever decisions you need to make. When someone hits your go button ("Submit" or whatever it's called for you) you'd call that method, and the return would be some useful data, possibly an object or a number or a String or whatever you need.

That's very vague, of course, but as I said, this is stuff you should already know. If this reminds you of something, go back and refresh your memory. If not, throw yourself on the mercy of your instructor. (possibly showing them this thread would be a good idea...)

I don't know that there's much more I can do here.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1