4 Replies - 2052 Views - Last Post: 09 August 2011 - 06:45 AM Rate Topic: -----

#1 trulysick   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 03-August 11

Set and Get GUI

Posted 06 August 2011 - 11:16 PM

Hey I cant figure out to get this to work.. The set and get method is completely new to me and i'm not sure how to go about setting it up yet alone add it to an On_click event.... Any help would be much appreciated and maybe a snippet to send me in the right direction... Thanks in advance! Here is my code so far.

public class PizzaUI extends javax.swing.JFrame {

    /** Creates new form PizzaUI */
    public PizzaUI() {
        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() {

        jLabel4 = new javax.swing.JLabel();
        btnExit = new javax.swing.JButton();
        btnProcess = new javax.swing.JButton();
        btnClear = new javax.swing.JButton();
        txtToppings = new javax.swing.JTextField();
        txtSize = new javax.swing.JTextField();
        txtPrice = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();

        jLabel4.setText("jLabel4");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

       

        btnProcess.setText("Process");
        btnProcess.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnProcessActionPerformed(evt);
            }
        });

        btnClear.setText("Clear");
        btnClear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnClearActionPerformed(evt);
            }
        });


    private void btnExitActionPerformed(java.awt.event.ActionEvent evt) {                                        
      System.exit(0); 
    }                                       

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

    private void btnProcessActionPerformed(java.awt.event.ActionEvent evt) {                                           
   



        double pizzaPrice = Double.parseDouble(txtPrice.getText());
       int    pizzaSize = Integer.parseInt(txtSize.getText());
       

    
    
   
    
  


          PizzaFunctions constX;
      constX = new PizzaFunctions();

       PizzaFunctions constX2;
       constX2 = new  PizzaFunctions();

       PizzaFunctions constX3;
      constX3 = new  PizzaFunctions();

      double pizza1;
       int size;
       double price1;
        

  pizza1 = constX.getPizza();
       size = constX.getSize();
       pizzaSize = size;

  pizza1 = constX2.getPizza();
      size = constX2.getSize();
      pizzaSize = size;



   pizza1 = constX3.getPizza();
       size =  constX2.getSize();
       pizzaSize = size;




here is the other class.... where my methods are.

package Pizza;

/**
 *
 * @author TrulySick
 */
public class PizzaFunctions {

    private double Pizza;
    private int size;
    private String topping;

    public void setsmallPizza(double Pizza, int size, String topping) {
        Pizza = 9.99;
        size = 10;
        topping = ("pepperoni");
    }

    public void setmediumPizza(double Pizza, int size, String topping) {
        Pizza = 12.99;
        size = 12;
        topping = ("Ham");
    }

    public void setlargePizze(double Pizza, int size, String topping) {
        Pizza = 15.99;
        size = 12;
        topping = ("Ham");
    }

    /**
     * @return the Pizza
     */
    public double getPizza() {
        return Pizza;
    }

    /**
     * @param Pizza the Pizza to set
     */
    public void setPizza(double Pizza) {
        this.Pizza = Pizza;
    }

    /**
     * @return the size
     */
    public int getSize() {
        return size;
    }

    /**
     * @param size the size to set
     */
    public void setSize(int size) {
        this.size = size;
    }

    /**
     * @return the topping
     */
    public String getTopping() {
        return topping;
    }

    /**
     * @param topping the topping to set
     */
    public void setTopping(String topping) {
        this.topping = topping;
    }




Basically i have to set this up to display a different pizza along with set topping, size, price, when Process is clicked.. any help is much appreciated

This post has been edited by trulysick: 06 August 2011 - 11:23 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Set and Get GUI

#2 blackcompe   User is offline

  • D.I.C Lover
  • member icon

Reputation: 1159
  • View blog
  • Posts: 2,547
  • Joined: 05-May 05

Re: Set and Get GUI

Posted 07 August 2011 - 12:15 AM

This code is incomplete. If possible, please post code that runs without compilation errors. After fixing it up and running it, nothing is displayed because you did add any components. See Adding Components for more info. See Pizza Processor code snippet.

This post has been edited by blackcompe: 07 August 2011 - 12:38 AM

Was This Post Helpful? 0
  • +
  • -

#3 macosxnerd101   User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12361
  • View blog
  • Posts: 45,476
  • Joined: 27-December 08

Re: Set and Get GUI

Posted 08 August 2011 - 07:39 AM

Also, you should really write your code by hand and not use the NetBeans GUI Builder. It produces horrid, unmaintainable code that humans cannot read. You will be able to write a cleaner GUI with fewer lines of code guaranteed. :)
Was This Post Helpful? 0
  • +
  • -

#4 trulysick   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 03-August 11

Re: Set and Get GUI

Posted 09 August 2011 - 05:18 AM

View Postmacosxnerd101, on 08 August 2011 - 07:39 AM, said:

Also, you should really write your code by hand and not use the NetBeans GUI Builder. It produces horrid, unmaintainable code that humans cannot read. You will be able to write a cleaner GUI with fewer lines of code guaranteed. :)


I ended up writing it by hand... it wasnt that hard at all. Adding the on_click event of the exit and clear button gave me some trouble as i didnt know the syntax for adding these. Thanks for the help people.
Was This Post Helpful? 0
  • +
  • -

#5 macosxnerd101   User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12361
  • View blog
  • Posts: 45,476
  • Joined: 27-December 08

Re: Set and Get GUI

Posted 09 August 2011 - 06:45 AM

Quote

Adding the on_click event of the exit and clear button gave me some trouble as i didnt know the syntax for adding these.

myButton.addActionListener(someActionListener);



Happy coding. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1