Results 1 to 4 of 4
  1. #1
    javajim is offline Member
    Join Date
    Nov 2010
    Posts
    2
    Rep Power
    0

    Default netbeans/java help

    im using netbeans for my java course, i have made a basic pizza program, but want to make it better visually and funtionally(if thats a word) i was wondering if there was a way to enable a text area only if a certain check box has been selected -

    i want to make it so.... when a pizza delivery check box is selected, the address text field becomes enabled to input data

    would it be better to make it into radio buttons?

    any help would be great

    i was thinking to get my teacher to view the program and order a pizza, then actually call a pizza place to get one delivered - thats programming lol :D


    heres my code.....

    Java Code:
    private void btnexitActionPerformed(java.awt.event.Ac… evt) { 
    System.exit(0);
    } 
    
    private void btnsubmitActionPerformed(java.awt.event.… evt) { 
    String strname = "";
    String straddress = "";
    String strpizzatype = "";
    double cost = 0.0;
    double amount = 0.0;
    double delivery = 4.00;
    String strquantity = " ";
    double quantity = 0.0;
    double garlic = 1;
    
    
    
    strname = txtname.getText();
    straddress = addressfield.getText();
    strquantity = quanfield.getText();
    
    quantity = Double.parseDouble(strquantity);
    
    
    
    if (rdolarge.isSelected())
    { strpizzatype = "large";
    cost = 10.00;
    }
    
    if (rdomedium.isSelected())
    { strpizzatype = "medium";
    cost = 7.00;
    }
    
    if (rdosmall.isSelected())
    { strpizzatype = "small";
    cost = 5.00;
    }
    
    if (checkdel.isSelected())
    {
    quantity = cost * quantity + delivery;
    }
    
    if (checkup.isSelected())
    {
    quantity = cost * quantity;
    }
    
    if (chkgar.isSelected())
    {
    quantity = garlic + cost;
    }
    
    try{
    displaybox.append('\n' + "Your name : " + strname + '\n' + "Address : " + straddress + '\n' + "Pizza type : " + strpizzatype + '\n' + "Pizza cost: $ " + cost + '\n' + "Your total : $ " + quantity + '\n' + "Your Pizza will be ready in 15 minutes" );
    
    //create a file object
    File output = new File("c:\\Temp\\","app.txt");
    //create a file string that will write to a text file
    //on line at a time
    BufferedWriter outFile = new BufferedWriter(new FileWriter
    (output.getPath(), true));
    
    outFile.write('\n' + "Your name : " + strname + '\n' + "Pizza type : " + strpizzatype + '\n' + "Pizza cost: $ " + cost + '\n' + "Your total : $ " + quantity + '\n' + "Your Pizza will be ready in 15 minutes");
    //use the newLine() of the bufferedWriter class to force
    //a new line to be saved in the external file
    outFile.newLine();
    //close file stream
    outFile.close();
    JOptionPane.showMessageDialog(null, "A copy of the receipt has been saved to your hard drive", " RECEIPT SAVED", JOptionPane.WARNING_MESSAGE);
    
    
    }
    catch(Exception e)
    {
    JOptionPane.showMessageDialog(null, "A copy of the receipt was unable to save to Hard drive");
    }
    } 
    
    private void txtnameActionPerformed(java.awt.event.Ac… evt) { 
    // TODO add your handling code here:
    } 
    
    private void checkdelActionPerformed(java.awt.event.A… evt) { 
    // TODO add your handling code here:
    } 
    
    private void btnClearActionPerformed(java.awt.event.A… evt) { 
    displaybox.setText("");
    txtname.setText("");
    quanfield.setText("");
    buttonGroup2.clearSelection();
    buttonGroup1.clearSelection();
    buttonGroup3.clearSelection();
    } 
    
    private void jMenuItem2ActionPerformed(java.awt.event… evt) { 
    System.exit(0);
    } 
    
    private void jMenuItem1ActionPerformed(java.awt.event… evt) { 
    displaybox.setText("");
    txtname.setText("");
    quanfield.setText("");
    buttonGroup2.clearSelection();
    buttonGroup1.clearSelection();
    buttonGroup3.clearSelection();
    }
    Last edited by Eranga; 11-02-2010 at 06:59 AM. Reason: code tags added

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    i want to make it so.... when a pizza delivery check box is selected, the address text field becomes enabled to input data

    There is a setEnabled() method that all JComponent instances have (including JTextField). You could listen for events on the check box and use this method to enable/disable the text field.

  3. #3
    javajim is offline Member
    Join Date
    Nov 2010
    Posts
    2
    Rep Power
    0

    Default thank you

    thanks for that worked well, changed it to editable though

    just had in my delivery checkbox code addressfield.setEditable(true)
    and for the pickup addressfield.setEditable(false)

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

Similar Threads

  1. netBeans in java
    By venkatesansan in forum AWT / Swing
    Replies: 3
    Last Post: 10-27-2010, 03:42 PM
  2. ? Java Netbeans
    By pottsmgg in forum New To Java
    Replies: 1
    Last Post: 09-14-2010, 05:07 PM
  3. Using Netbeans for JAVA Web
    By Debojit1986 in forum New To Java
    Replies: 3
    Last Post: 03-15-2010, 06:01 PM
  4. About NetBeans(java)
    By tiger100plus in forum New To Java
    Replies: 1
    Last Post: 11-08-2008, 05:33 PM
  5. Java 3D In Netbeans
    By nvidia in forum NetBeans
    Replies: 1
    Last Post: 04-09-2008, 06:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •