Results 1 to 8 of 8
  1. #1
    akritc is offline Member
    Join Date
    Jun 2010
    Posts
    4
    Rep Power
    0

    Default show Message Dialog

    i need to display this
    Java Code:
     JOptionPane.showMessageDialog(null, "Change " + com.openbravo.pos.payment.m_jChangeEuros.getText());
    when the ok button is pressed in da code below

    Java Code:
    package com.openbravo.beans;
    
    import java.awt.BorderLayout;
    import java.awt.Component;
    import java.awt.Container;
    import java.awt.Dialog;
    import java.awt.Frame;
    import java.awt.Window;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.Icon;
    import javax.swing.JDialog;
    import javax.swing.JOptionPane;
    import javax.swing.SwingUtilities;
    
    /**
     *
     * @author  adrian
     */
    public class JNumberDialog extends javax.swing.JDialog {
        
        private static LocaleResources m_resources;
        
        private Double m_value;
        
        /** Creates new form JNumberDialog */
        public JNumberDialog(java.awt.Frame parent, boolean modal) {
            super(parent, modal);
            init();
        }
        
        /** Creates new form JNumberDialog */
        public JNumberDialog(java.awt.Dialog parent, boolean modal) {
            super(parent, modal);
            init();
        }
        
        private void init() {
            
            if (m_resources == null) {
                m_resources = new LocaleResources();
                m_resources.addBundleName("beans_messages");
            }
            
            initComponents();        
            getRootPane().setDefaultButton(jcmdOK);
             
            
            m_jnumber.addEditorKeys(m_jKeys);
            m_jnumber.reset();
            m_jnumber.setDoubleValue(0.0);
            m_jnumber.activate();
            
            m_jPanelTitle.setBorder(RoundedBorder.createGradientBorder());
    
            m_value = null;
                 
        }
        
        private void setTitle(String title, String message, Icon icon) {
            setTitle(title);
            m_lblMessage.setText(message);
            m_lblMessage.setIcon(icon);
        }
        
        public static Double showEditNumber(Component parent, String title) {
            return showEditNumber(parent, title, null, null);
        }
        public static Double showEditNumber(Component parent, String title, String message) {
            return showEditNumber(parent, title, message, null);
        }
        public static Double showEditNumber(Component parent, String title, String message, Icon icon) {
            
            Window window = SwingUtilities.windowForComponent(parent);
            
            JNumberDialog myMsg;
            if (window instanceof Frame) { 
                myMsg = new JNumberDialog((Frame) window, true);
            } else {
                myMsg = new JNumberDialog((Dialog) window, true);
                 }
            
            myMsg.setTitle(title, message, icon);
            myMsg.setVisible(true);
            return myMsg.m_value;
        }
     
      
        /** 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.
         */
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {
    
            jOptionPane1 = new javax.swing.JOptionPane();
            jPanel1 = new javax.swing.JPanel();
            jcmdOK = new javax.swing.JButton();
            jcmdCancel = new javax.swing.JButton();
            jPanel2 = new javax.swing.JPanel();
            jPanelGrid = new javax.swing.JPanel();
            jPanel3 = new javax.swing.JPanel();
            m_jKeys = new com.openbravo.editor.JEditorKeys();
            jPanel4 = new javax.swing.JPanel();
            m_jnumber = new com.openbravo.editor.JEditorDoublePositive();
            m_jPanelTitle = new javax.swing.JPanel();
            m_lblMessage = new javax.swing.JLabel();
    
            setResizable(false);
            addWindowListener(new java.awt.event.WindowAdapter() {
                public void windowClosing(java.awt.event.WindowEvent evt) {
                    formWindowClosing(evt);
                }
            });
    
            jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
    
            jcmdOK.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/button_ok.png"))); // NOI18N
            jcmdOK.setText(m_resources.getString("button.ok")); // NOI18N
            jcmdOK.setMargin(new java.awt.Insets(8, 16, 8, 16));
            jcmdOK.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jcmdOKActionPerformed(evt);
                }
            });
            jPanel1.add(jcmdOK);
    
            jcmdCancel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/button_cancel.png"))); // NOI18N
            jcmdCancel.setText(m_resources.getString("button.cancel")); // NOI18N
            jcmdCancel.setMargin(new java.awt.Insets(8, 16, 8, 16));
            jcmdCancel.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jcmdCancelActionPerformed(evt);
                }
            });
            jPanel1.add(jcmdCancel);
    
            getContentPane().add(jPanel1, java.awt.BorderLayout.SOUTH);
    
            jPanel2.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
            jPanel2.setLayout(new java.awt.BorderLayout());
    
            jPanel3.setLayout(new javax.swing.BoxLayout(jPanel3, javax.swing.BoxLayout.Y_AXIS));
            jPanel3.add(m_jKeys);
    
            jPanel4.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
            jPanel4.setLayout(new java.awt.BorderLayout());
            jPanel4.add(m_jnumber, java.awt.BorderLayout.CENTER);
    
            jPanel3.add(jPanel4);
    
            jPanelGrid.add(jPanel3);
    
            jPanel2.add(jPanelGrid, java.awt.BorderLayout.CENTER);
    
            getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER);
    
            m_jPanelTitle.setLayout(new java.awt.BorderLayout());
    
            m_lblMessage.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createMatteBorder(0, 0, 1, 0, java.awt.Color.darkGray), javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5)));
            m_jPanelTitle.add(m_lblMessage, java.awt.BorderLayout.CENTER);
    
            getContentPane().add(m_jPanelTitle, java.awt.BorderLayout.NORTH);
    
            java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
            setBounds((screenSize.width-253)/2, (screenSize.height-433)/2, 253, 433);
        }// </editor-fold>                        
    
        private void jcmdOKActionPerformed(java.awt.event.ActionEvent evt) {                                       
    
            
         m_value = m_jnumber.getDoubleValue();
           
            setVisible(false);
            dispose();
           
    
    
           
        }                                      
    
        private void jcmdCancelActionPerformed(java.awt.event.ActionEvent evt) {                                           
    
            setVisible(false);
            dispose();
            
        }                                          
    
        private void formWindowClosing(java.awt.event.WindowEvent evt) {                                   
    
            setVisible(false);
            
            
        }                                  
        
        
        // Variables declaration - do not modify                     
        private javax.swing.JOptionPane jOptionPane1;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JPanel jPanel2;
        private javax.swing.JPanel jPanel3;
        private javax.swing.JPanel jPanel4;
        private javax.swing.JPanel jPanelGrid;
        private javax.swing.JButton jcmdCancel;
        public static javax.swing.JButton jcmdOK;
        private com.openbravo.editor.JEditorKeys m_jKeys;
        private javax.swing.JPanel m_jPanelTitle;
        private com.openbravo.editor.JEditorDoublePositive m_jnumber;
        private javax.swing.JLabel m_lblMessage;
        // End of variables declaration                   
        
    }

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

    Default

    Put the code you want to execute when the button is pressed in the ActionListener actionPerformed() method for that button.

  3. #3
    akritc is offline Member
    Join Date
    Jun 2010
    Posts
    4
    Rep Power
    0

    Default

    I cant find the action listener do i have to declare it

    below is the default actions performed by the button


    Java Code:
    private void jcmdOKActionPerformed(java.awt.event.ActionEvent evt) {                                       
    
            m_value = m_jnumber.getDoubleValue();
           
            setVisible(false);
            dispose();
    PS i m using net beans

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

    Default

    Look at where the button is created. Very near there is a call to the addActionListener(<action listener>) method. The value in parans is the name of your action listener.

    Sorry about your using net beans. IDEs are useful but hide too much for beginners.

  5. #5
    akritc is offline Member
    Join Date
    Jun 2010
    Posts
    4
    Rep Power
    0

    Default

    One last question

    i have found the following code
    Java Code:
      jcmdOK.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jcmdOKActionPerformed(evt);
                }
    but net beans is not letting me modify this, what would you recommend i do

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

    Default

    net beans is not letting me modify this
    Sorry I don't use net beans.

    What does: jcmdOKActionPerformed(evt) do?

  7. #7
    akritc is offline Member
    Join Date
    Jun 2010
    Posts
    4
    Rep Power
    0

    Default

    it does the following
    Java Code:
    private void jcmdOKActionPerformed(java.awt.event.ActionEvent evt) {                                       
    
            m_value = m_jnumber.getDoubleValue();
           
            setVisible(false);
            dispose();
    i tired putting my code in dea but that does not help

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

    Default

    tired putting my code in dea
    Not sure what that means.

    I asked the question about jcmdOKActionPerformed() because I wanted you to look at it and understand what it does in relation to the action listener code. You need a place to put your code. Where do you think you can put it?

Similar Threads

  1. Replies: 6
    Last Post: 06-04-2010, 09:43 PM
  2. Replies: 13
    Last Post: 03-20-2010, 02:03 AM
  3. Replies: 0
    Last Post: 03-05-2010, 05:21 AM
  4. show Confirm Perspective Switch dialog box
    By mostafa in forum Eclipse
    Replies: 0
    Last Post: 11-22-2008, 12:47 PM
  5. JOptionPane - message dialog
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-17-2007, 10: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
  •