Page 2 of 2 FirstFirst 12
Results 21 to 22 of 22
  1. #21
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  2. #22
    Izuba is offline Member
    Join Date
    Oct 2010
    Posts
    16
    Rep Power
    0

    Default

    hello Fub!

    I thank you for your continuous helping

    coming back to the very first code i submitted, i have difficulty to break out of the loop in case the customer has not selected anything and print the message:"Please select something",could you please help me?i did nt include the break statement.
    here is the source code:







    Java Code:
    //***********Source code
    
    //file: DriveThrough.java
    import java.awt.*;
    import java.awt.event.*;
    
    import javax.swing.*;
    
    public class Drive extends JFrame
    {
    
    final JPanel condimentsPanel = new JPanel();
    JPanel orderPanel = new JPanel( );
    JButton orderButton = new JButton("Place Order");
    JCheckBox checkBox1 = new JCheckBox("Ketchup");
    JCheckBox checkBox2 = new JCheckBox("Mustard");
    JCheckBox checkBox3 = new JCheckBox("Pickles");
    
    
    public static void main(String args[])
    {
    Drive f = new Drive();
    f.setLocation(200,200);
    f.setSize(300,150);
    
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
    
    }
    
    public Drive()
    {
    super();
    Container content = getContentPane( );
    
    condimentsPanel.add(checkBox1);
    condimentsPanel.add(checkBox2);
    condimentsPanel.add(checkBox3);
    
    
    orderPanel.add(orderButton);
    
    
    content.setLayout(new GridLayout(2, 1));
    content.add(condimentsPanel);
    content.add(orderPanel);
    ButtonHandler handler = new ButtonHandler();
    orderButton.addActionListener(handler);
    
    }
    private class ButtonHandler implements ActionListener
    {
    Component[] components = condimentsPanel.getComponents( );
    JCheckBox cb = (JCheckBox)components[i];
    
    public void actionPerformed(ActionEvent event)
    {
    String resultString = new String();
    if (cb1.isSelected() )
    resultString +="with"+cb.getText() +"\n";
    }
    JOptionPane.showMessageDialog(null,"You have selected"+resultString);
    
    }
    Last edited by Izuba; 10-15-2010 at 09:50 AM. Reason: for putting code in between cod tags

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 5
    Last Post: 07-29-2009, 06:38 PM
  2. help with JOptionPane.showMessageDialog()
    By gmn1 in forum New To Java
    Replies: 8
    Last Post: 03-30-2009, 09:31 AM
  3. Replies: 1
    Last Post: 10-29-2008, 07:50 AM
  4. About JOptionPane.showMessageDialog
    By jhetfield18 in forum AWT / Swing
    Replies: 2
    Last Post: 11-02-2007, 10:45 PM
  5. About JOptionPane.showMessageDialog
    By jhetfield18 in forum Advanced Java
    Replies: 0
    Last Post: 11-02-2007, 10:56 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
  •