Page 1 of 2 12 LastLast
Results 1 to 20 of 26
  1. #1
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,062
    Rep Power
    8

    Default I get this enormous error message....

    When trying to make a swing component invisible, dialog1.setVisible(false);
    I get this enormous error message....
    Can somebody please give me a clou were to look into?


    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at studyrooms.CalenderDialog$DialogListener.actionPer formed(CalenderDialog.java:449)
    at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:2028)
    at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2351)
    at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:242)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:236)
    at java.awt.Component.processMouseEvent(Component.jav a:6382)
    at javax.swing.JComponent.processMouseEvent(JComponen t.java:3275)
    at java.awt.Component.processEvent(Component.java:614 7)
    at java.awt.Container.processEvent(Container.java:208 3)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4744)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2141)
    at java.awt.Component.dispatchEvent(Component.java:45 72)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4619)
    at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:4280)
    at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:4210)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2127)
    at java.awt.Window.dispatchEventImpl(Window.java:2489 )
    at java.awt.Component.dispatchEvent(Component.java:45 72)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.j ava:710)
    at java.awt.EventQueue.access$400(EventQueue.java:82)
    at java.awt.EventQueue$2.run(EventQueue.java:669)
    at java.awt.EventQueue$2.run(EventQueue.java:667)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:87)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:98)
    at java.awt.EventQueue$3.run(EventQueue.java:683)
    at java.awt.EventQueue$3.run(EventQueue.java:681)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:87)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 680)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:296)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:211)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:205)
    at java.awt.Dialog$1.run(Dialog.java:1049)
    at java.awt.Dialog$3.run(Dialog.java:1101)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.awt.Dialog.show(Dialog.java:1099)
    at java.awt.Component.show(Component.java:1591)
    at java.awt.Component.setVisible(Component.java:1543)
    at java.awt.Window.setVisible(Window.java:843)
    at java.awt.Dialog.setVisible(Dialog.java:984)
    at studyrooms.CalenderDialog$DialogListener.actionPer formed(CalenderDialog.java:435)
    at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:2028)
    at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2351)
    at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:242)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:236)
    at java.awt.Component.processMouseEvent(Component.jav a:6382)
    at javax.swing.JComponent.processMouseEvent(JComponen t.java:3275)
    at java.awt.Component.processEvent(Component.java:614 7)
    at java.awt.Container.processEvent(Container.java:208 3)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4744)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2141)
    at java.awt.Component.dispatchEvent(Component.java:45 72)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4619)
    at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:4280)
    at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:4210)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2127)
    at java.awt.Window.dispatchEventImpl(Window.java:2489 )
    at java.awt.Component.dispatchEvent(Component.java:45 72)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.j ava:710)
    at java.awt.EventQueue.access$400(EventQueue.java:82)
    at java.awt.EventQueue$2.run(EventQueue.java:669)
    at java.awt.EventQueue$2.run(EventQueue.java:667)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:87)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:98)
    at java.awt.EventQueue$3.run(EventQueue.java:683)
    at java.awt.EventQueue$3.run(EventQueue.java:681)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:87)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 680)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:296)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:211)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:205)
    at java.awt.Dialog$1.run(Dialog.java:1049)
    at java.awt.event.InvocationEvent.dispatch(Invocation Event.java:209)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.j ava:708)
    at java.awt.EventQueue.access$400(EventQueue.java:82)
    at java.awt.EventQueue$2.run(EventQueue.java:669)
    at java.awt.EventQueue$2.run(EventQueue.java:667)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:87)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:98)
    at java.awt.EventQueue$3.run(EventQueue.java:683)
    at java.awt.EventQueue$3.run(EventQueue.java:681)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:87)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 680)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:296)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:211)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:196)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:188)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:122)
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at studyrooms.CalenderDialog.CheckDialogInput(Calende rDialog.java:267)
    at studyrooms.CalenderDialog.access$400(CalenderDialo g.java:31)
    at studyrooms.CalenderDialog$DialogListener.actionPer formed(CalenderDialog.java:442)
    at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:2028)
    at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2351)
    at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:242)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:236)
    at java.awt.Component.processMouseEvent(Component.jav a:6382)
    at javax.swing.JComponent.processMouseEvent(JComponen t.java:3275)
    at java.awt.Component.processEvent(Component.java:614 7)
    at java.awt.Container.processEvent(Container.java:208 3)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4744)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2141)
    at java.awt.Component.dispatchEvent(Component.java:45 72)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4619)
    at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:4280)
    at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:4210)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2127)
    at java.awt.Window.dispatchEventImpl(Window.java:2489 )
    at java.awt.Component.dispatchEvent(Component.java:45 72)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.j ava:710)
    at java.awt.EventQueue.access$400(EventQueue.java:82)
    at java.awt.EventQueue$2.run(EventQueue.java:669)
    at java.awt.EventQueue$2.run(EventQueue.java:667)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:87)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:98)
    at java.awt.EventQueue$3.run(EventQueue.java:683)
    at java.awt.EventQueue$3.run(EventQueue.java:681)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:87)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 680)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:296)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:211)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:205)
    at java.awt.Dialog$1.run(Dialog.java:1049)
    at java.awt.event.InvocationEvent.dispatch(Invocation Event.java:209)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.j ava:708)
    at java.awt.EventQueue.access$400(EventQueue.java:82)
    at java.awt.EventQueue$2.run(EventQueue.java:669)
    at java.awt.EventQueue$2.run(EventQueue.java:667)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:87)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:98)
    at java.awt.EventQueue$3.run(EventQueue.java:683)
    at java.awt.EventQueue$3.run(EventQueue.java:681)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:87)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 680)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:296)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:211)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:196)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:188)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:122)

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: I get this enormous error message....

    Something is null on line 449 in a class named CalenderDialog. Add some println's to figure it out, or throw your code into a debugger and stop on that line to inspect, or post an SSCCE that clearly demonstrates the problem.

  3. #3
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,062
    Rep Power
    8

    Default Re: I get this enormous error message....

    doWhile I do not get it look this after closing the dialog window:
    (probably some stupid thing I am overseeing......)

    run:
    print string first null
    print string second info of vacation etc
    print string first null
    print string second typed in new text at textfield
    print string first null
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at studyrooms.CalenderDialog.CheckDialogInput(Calende rDialog.java:259)
    at studyrooms.CalenderDialog.access$500(CalenderDialo g.java:31)
    at studyrooms.CalenderDialog$DialogListener.actionPer formed(CalenderDialog.java:433)
    at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:2028)
    at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2351)
    at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:242)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:236)
    at java.awt.Component.processMouseEvent(Component.jav a:6382)
    at javax.swing.JComponent.processMouseEvent(JComponen t.java:3275)
    at java.awt.Component.processEvent(Component.java:614 7)
    at java.awt.Container.processEvent(Container.java:208 3)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4744)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2141)
    at java.awt.Component.dispatchEvent(Component.java:45 72)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4619)
    at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:4280)
    at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:4210)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2127)
    at java.awt.Window.dispatchEventImpl(Window.java:2489 )
    at java.awt.Component.dispatchEvent(Component.java:45 72)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.j ava:710)
    at java.awt.EventQueue.access$400(EventQueue.java:82)
    at java.awt.EventQueue$2.run(EventQueue.java:669)
    at java.awt.EventQueue$2.run(EventQueue.java:667)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:87)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:98)
    at java.awt.EventQueue$3.run(EventQueue.java:683)
    at java.awt.EventQueue$3.run(EventQueue.java:681)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:87)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 680)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:296)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:211)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:205)
    at java.awt.Dialog$1.run(Dialog.java:1049)
    at java.awt.event.InvocationEvent.dispatch(Invocation Event.java:209)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.j ava:708)
    at java.awt.EventQueue.access$400(EventQueue.java:82)
    at java.awt.EventQueue$2.run(EventQueue.java:669)
    at java.awt.EventQueue$2.run(EventQueue.java:667)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:87)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:98)
    at java.awt.EventQueue$3.run(EventQueue.java:683)
    at java.awt.EventQueue$3.run(EventQueue.java:681)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:87)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 680)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:296)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:211)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:196)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:188)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:122)
    Last edited by willemjav; 05-22-2013 at 07:33 PM.

  4. #4
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,062
    Rep Power
    8

    Default Re: I get this enormous error message....

    here is the complete code:

    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package studyrooms;
    
    /**
     *
     * @author willem
     */
    
    
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Container;
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import java.awt.Font;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.ItemEvent;
    import java.awt.event.ItemListener;
    import javax.swing.*;
    
    
    /**
     *
     * 
     */
    public class CalenderDialog extends JDialog{
        private ImageIcon icon;
        private ActionListener DListener;
        private ItemListener clistener;
        private JCheckBox selectbox;
        private JComboBox comboA1, comboA2, comboB1, comboB2;
        private JTextField infoField;
        private JTextArea infoarea;
        private JButton okb, chancelb, resetb;
        private ComponentRef[] compref;
        private String[] hourlist, minlist, monthlist, daylist;
        private int count;
        private static String flag;
        private CalenderDialog dialog2;
        private static CalenderDialog dialog1;
        private CalenderPanel calenderpanel;
    
        public static void main(String[] args) {
           
           dialog1 = new CalenderDialog("DIALOG1");
           dialog1.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
           dialog1.setBounds(300, 300, 520, 350);
           dialog1.setVisible(true);
        }
    
        public CalenderDialog(String flg) {
            icon = createImageIcon("images/lic2.gif");
            setTitle("Calender Dialog");
            setModal(true);
            setResizable(false);
            flag = flg;
         //   System.out.println("the flag is " + flag);
            
    
            hourlist = new String[] {"7", "8", "9", "10", "11", "12", "13",
                                 "14", "15", "16", "17", "18", "19", "20",
                                  "21", "22", "23"};
            minlist = new String[] {"00", "30"};
    
            monthlist = new String[] {"enero", "febrero", "marzo", "abril", "mayo",
                                   "junio", "julio", "augusto", "septiembro",
                                   "octobre", "noviembre", "deciembre"};
    
            daylist = new String[] {"1", "2", "3", "4", "5", "6", "7", "8", "9",
                                "10", "11", "12", "13","14", "15", "16", "17",
                                "18", "19", "20", "21", "22", "23", "24", "25",
                                "26", "27", "28", "29", "30", "31"};
    
            DListener = new DialogListener();
            clistener = new ComboListener();
    
            compref = new ComponentRef[Fieldnumber(flag)]; // initiate the class that holds
                for (int i = 0; i < compref.length; i++)  // the refferences of the boxes
                        compref[i] = new ComponentRef();
    
            Container contentPane = getContentPane();
            contentPane.add(createDialogPanel());
        }
    
    
         private JPanel createDialogPanel()  {
    
            JPanel panel = new JPanel(new BorderLayout());
            JPanel iconpanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 30, 10));
            JPanel buttonpanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
            JLabel iconlabel = new JLabel(icon);
            iconpanel.add(iconlabel);
    
            panel.setBackground(Color.WHITE);
            iconpanel.setBackground(Color.WHITE);
            buttonpanel.setBackground(Color.WHITE);
    
            infoarea = new JTextArea(3,25);
            infoarea.setPreferredSize(new Dimension(20,20));
            infoarea.setFont(new Font("Serif", Font.ITALIC, 16));
            infoarea.setEditable(false);
            if (flag == "DIALOG1") { // first and second dialog text
                infoarea.setText("Set the schedule of the week days\n"
                             + "when active, check the box and\n"
                             + "and enter the duration");
            }
            if (flag == "DIALOG2")  {
                infoarea.setText("Set several vacations and\n"
                             + "class free periods by checking\n"
                             + "the box and typing a short info");
            }
            iconpanel.add(infoarea);
    
            okb = new JButton("OK");
            okb.setActionCommand("OK");
            okb.addActionListener(DListener);
    
            chancelb = new JButton("CHANCEL");
            chancelb.setActionCommand("CH");
            chancelb.addActionListener(DListener);
    
            resetb = new JButton("RESET");
            resetb.setActionCommand("RS");
            resetb.addActionListener(DListener);
    
            buttonpanel.add(resetb);
            buttonpanel.add(okb);
            buttonpanel.add(chancelb);
    
            JPanel comppanel = new JPanel();
            comppanel.setBackground(Color.WHITE);
            comppanel.setLayout(new BoxLayout(comppanel,
                    BoxLayout.LINE_AXIS));
    
            Box bh = Box.createHorizontalBox();
            Box bv = Box.createVerticalBox();
    
            if (flag == "DIALOG1") {
                bv.add(createSinglePanel("lunes    "));
                bv.add(createSinglePanel("martes   "));
                bv.add(createSinglePanel("miercoles"));
                bv.add(createSinglePanel("jueves   "));
                bv.add(createSinglePanel("viernes  "));
                bv.add(createSinglePanel("sabado   "));
                bv.add(createSinglePanel("domingo  "));
            }
            if (flag == "DIALOG2")  {
                 for (int i = 0; i <  Fieldnumber(flag); i++)
                     bv.add(createSinglePanel((i+1) + " "));
            }
    
            comppanel.add(bv);
    
            panel.add(iconpanel, BorderLayout.NORTH);
            panel.add(comppanel, BorderLayout.CENTER);
            panel.add(buttonpanel, BorderLayout.SOUTH);
            return panel;
         }
    
    
    
         private Box createSinglePanel(String label)  {
            String[] list1 = null;
            String[] list2 = null;
    
            if (flag == "DIALOG1")  { // first dialog
                list1 = hourlist;
                list2 = minlist;
    
            }
            if (flag == "DIALOG2")  {  // second dialog
                list1 = monthlist;
                list2 = daylist;
            }
    
            JLabel lb = new JLabel(" until ");
            Box bx = Box.createHorizontalBox();
    
            selectbox = new JCheckBox(label);
            selectbox.setActionCommand("SELECT");
            selectbox.setSelected(false);
            selectbox.addActionListener(DListener);
            compref[count].setboxref(selectbox);
    
            comboA1 = new JComboBox(list1);
            comboA2 = new JComboBox(list2);
            comboB1 = new JComboBox(list1);
            comboB2 = new JComboBox(list2);
            lb.setLabelFor(comboB1);
    
            comboA1.setSelectedIndex(0);
            comboA2.setSelectedIndex(0);
            comboB1.setSelectedIndex(0);
            comboB2.setSelectedIndex(0);
    
            comboA1.addItemListener(clistener);
            comboA2.addItemListener(clistener);
        //    comboB1.addItemListener(clistener);
        //    comboB2.addItemListener(clistener);
    
            compref[count].setcomboA1(comboA1);
            compref[count].setcomboA2(comboA2);
            compref[count].setcomboB1(comboB1);
            compref[count].setcomboB2(comboB2);
            comboA1.setEnabled(false);
            comboA2.setEnabled(false);
            comboB1.setEnabled(false);
            comboB2.setEnabled(false);
    
            infoField = null;
            if (flag == "DIALOG2")  {// in case of second dialog
                    infoField = new JTextField(23);
                    infoField.setMaximumSize(infoField.getPreferredSize());
                    infoField.setText("info of vacation etc");
                    infoField.setEnabled(false);
                    compref[count].settextfieldref(infoField);
            }
    
            bx.add(selectbox);
            if (flag == "DIALOG2") bx.add(infoField);
            bx.add(Box.createHorizontalGlue());
            bx.add(comboA1);
            bx.add(comboA2);
            bx.add(lb);
            bx.add(comboB1);
            bx.add(comboB2);
    
            count++;
            return bx;
        }
    
        
    
    
        private boolean CheckDialogInput() {
           
            boolean bln = true;
            String s = null;
            for (int i = 0; i < Fieldnumber(flag) ; i++) {
                if (compref[i].getboxref().isSelected()) {
                    if (compref[i].getcomboA1().getSelectedIndex() >
                        compref[i].getcomboB1().getSelectedIndex()) {
                        bln = false;
                    }
    
                    if (compref[i].getcomboA1().getSelectedIndex() ==
                        compref[i].getcomboB1().getSelectedIndex() &&
                        compref[i].getcomboA2().getSelectedIndex() >=
                        compref[i].getcomboB2().getSelectedIndex()) {
                        bln = false;
                    }
                    if (flag == "DIALOG2")  {
                        System.out.println("print string first " + s);
                        s = compref[i].gettextfieldref().getText();
                        System.out.println("print string second " + s);
                        if ( s.equals("") || s.equals("info of vacation etc"))  
                            bln = false;
                    }
                }
            }
            return bln;
        }
    
        private int Fieldnumber(String flg)  {
            if (flg == "DIALOG1")
                 return 7;
            else return 10;
        }
    
    
        class ComponentRef {
           private JCheckBox boxref;
           private JComboBox comborefA1, comborefA2, comborefB1, comborefB2;
           private JTextField textfieldref;
    
           public void setboxref(JCheckBox br)  {
                    boxref = br;
           }
           public JCheckBox getboxref()  {
                    return boxref;
           }
    
           public void setcomboA1(JComboBox cb)  {
                   comborefA1 = cb;
           }
           public JComboBox getcomboA1()  {
                    return comborefA1;
           }
    
           public void setcomboA2(JComboBox cb)  {
                   comborefA2 = cb;
           }
           public JComboBox getcomboA2()  {
                    return comborefA2;
           }
    
           public void setcomboB1(JComboBox cb)  {
                   comborefB1 = cb;
           }
           public JComboBox getcomboB1()  {
                    return comborefB1;
           }
    
           public void setcomboB2(JComboBox cb)  {
                   comborefB2 = cb;
           }
           public JComboBox getcomboB2()  {
                    return comborefB2;
           }
    
           public void settextfieldref(JTextField tf)  {
                   textfieldref = tf;
           }
           public JTextField gettextfieldref()  {
                    return textfieldref;
           }
    
        }
    
        private class ComboListener implements ItemListener {
    
            public void itemStateChanged(ItemEvent ie) {
    
                    int x = Fieldnumber(flag);
                    for (int i = 0; i < x ; i++) {
                        if (compref[i].getboxref().isSelected()) {
                            System.out.println("Source: " + ie.getItem());
                            x = compref[i].getcomboA1().getSelectedIndex();
                            compref[i].getcomboB1().setSelectedIndex(x);
                            for (int ii = 0; ii < x ; ii++) {
                              //  compref[i].getcomboB1().removeItemAt(ii+1);
    
                            }
                        }
                    }
    
                    for (int i = 0; i < x ; i++) {
                        if (compref[i].getboxref().isSelected()) {
                            x = compref[i].getcomboA2().getSelectedIndex();
                            compref[i].getcomboB2().setSelectedIndex(x);
                            for (int ii = 0; ii < x ; ii++) {
                              //  compref[i].getcomboB2().removeItemAt(ii+1);
    
                            }
                        }
                    }
            }
        }
    
        private class DialogListener implements ActionListener {
            public void actionPerformed(ActionEvent e)  {
                String cmd = e.getActionCommand();
    
                 if (cmd.equals("SELECT")) {
                    for (int i = 0; i < Fieldnumber(flag) ; i++) { //comboref.length
                        if (compref[i].getboxref().isSelected())  {
                                compref[i].getcomboA1().setEnabled(true);
                                compref[i].getcomboA2().setEnabled(true);
                                compref[i].getcomboB1().setEnabled(true);
                                compref[i].getcomboB2().setEnabled(true);
                                if (flag == "DIALOG2") // when second dialog selected
                                    compref[i].gettextfieldref().setEnabled(true);
                        }
                        else {
                            compref[i].getcomboA1().setEnabled(false);
                            compref[i].getcomboA2().setEnabled(false);
                            compref[i].getcomboB1().setEnabled(false);
                            compref[i].getcomboB2().setEnabled(false);
                            compref[i].getcomboA1().setSelectedIndex(0);
                            compref[i].getcomboA2().setSelectedIndex(0);
                            compref[i].getcomboB1().setSelectedIndex(0);
                            compref[i].getcomboB2().setSelectedIndex(0);
                            if (flag == "DIALOG2")
                                compref[i].gettextfieldref().setEnabled(false);
                        }
                   }
                }
    
    
    
                if (cmd.equals("RS")) {
                    for (int i = 0; i < Fieldnumber(flag) ; i++) { //comboref.length
    
                            compref[i].getboxref().setSelected(false);
                            compref[i].getcomboA1().setEnabled(false);
                            compref[i].getcomboA2().setEnabled(false);
                            compref[i].getcomboB1().setEnabled(false);
                            compref[i].getcomboB2().setEnabled(false);
                            compref[i].getcomboA1().setSelectedIndex(0);
                            compref[i].getcomboA2().setSelectedIndex(0);
                            compref[i].getcomboB1().setSelectedIndex(0);
                            compref[i].getcomboB2().setSelectedIndex(0);
                       if (flag == "DIALOG2")  {
                           compref[i].gettextfieldref().setText("info of vacation etc");
                           compref[i].gettextfieldref().setEnabled(false);
                       }
                   }
                }
    
                if (cmd.equals("CH")) {
                  System.out.println("CHANCEL");
                  setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                }
                
                if (cmd.equals("OK")) {  
    
                    if (flag == "DIALOG1")  {
    
                        if (!CheckDialogInput()) {
                                JOptionPane.showMessageDialog(null,
                                    "Please check the hour and minutes\n" +
                                    "fields and correct the entry/ies.\n");
                        } else {
                             
                             dialog1.setVisible(false);
                             dialog2 = new CalenderDialog("DIALOG2");
                             dialog2.setBounds(300, 300, 760, 520);
                             dialog2.setVisible(true);
                             dialog2.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
                        }
                    }
    
                    if (flag == "DIALOG2")  {
    
                        if (!CheckDialogInput()) {
                                JOptionPane.showMessageDialog(null,
                                    "Please check the month and day\n" +
                                    "fields and correct the entry/ies.\n" +
                                    "The info field should be filled out too.\n");
                        } else {
                         //   dialog2.setVisible(false);
                         //   calenderpanel = new  CalenderPanel();
                         //   calenderpanel.setBounds(30, 30, 1700, 900);
                         //   calenderpanel.setTitle("Calendar Window");
                          //  calenderpanel.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
                          //  calenderpanel.setVisible(true);
                           // flag = "DIALOG3";
                        }
                    }
                }
            }
        }
    
    
        protected static ImageIcon createImageIcon(String path) { // loads the icons
            java.net.URL imgURL = CalenderPanel.class.getResource(path);
            if (imgURL != null) {
                return new ImageIcon(imgURL);
            } else {
                System.err.println("Couldn't find file: " + path);
                return null;
            }
       }
    
    
    
    }

  5. #5
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,379
    Rep Power
    5

    Default Re: I get this enormous error message....

    Well, one thing you are doing wrong is using == to compare strings (e.g. flag == "DIALOG1"). I doubt that will every be true. You should use equals to compare strings.

    Regards,
    Jim
    Last edited by jim829; 05-22-2013 at 09:49 PM.
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  6. #6
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,062
    Rep Power
    8

    Default Re: I get this enormous error message....

    you'r right, I knew that one. but forgot it again, thanks.
    I'll repair that one, but there might be an issue with:
    line 59, setModal(true);
    which I moved to the main block as
    DIALOG1.setModal(true);
    (which is maybe still wrong?

  7. #7
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,062
    Rep Power
    8

    Default Re: I get this enormous error message....

    OK what I am observing, but not understanding is the following:

    The main method creates the firs dialog like this (the class extends JDialog):

    Java Code:
    public static void main(String[] args) {
           
           dialog1 = new CalenderDialog("DIALOG1");
           dialog1.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
           dialog1.setBounds(300, 300, 520, 350);
           dialog1.setVisible(true);
           dialog1.setModal(true);
        }
    Than I create (by setting the "flag") the second dialog by pushing
    a OK button:

    Java Code:
    if (cmd.equals("OK")) {  
    
                    if (flag.equals("DIALOG1"))  {
    
                        if (!CheckDialogInput()) {
                                JOptionPane.showMessageDialog(null,
                                    "Please check the hour and minutes\n" +
                                    "fields and correct the entry/ies.\n");
                        } else {
                             
                             dialog1.setVisible(false);
                             dialog2 = new CalenderDialog("DIALOG2");
                             dialog2.setBounds(300, 300, 760, 520);
                             dialog2.setModal(true);
                             dialog2.setVisible(true);
                             dialog2.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
                        }
                    }
    
                    if (flag.equals("DIALOG2"))  {
    
                        if (!CheckDialogInput()) {
                                JOptionPane.showMessageDialog(null,
                                    "Please check the month and day\n" +
                                    "fields and correct the entry/ies.\n" +
                                    "The info field should be filled out too.\n");
                        } else {
                          //  dialog2.setVisible(false);
                            calenderpanel = new  CalenderPanel();
                            calenderpanel.setBounds(30, 30, 1700, 900);
                            calenderpanel.setTitle("Calendar Window");
                            calenderpanel.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
                            calenderpanel.setVisible(true);
                            flag = "DIALOG3";
                        }
                    }
    
                    if (flag.equals("DIALOG3"))  {
                        System.out.println("DIALOG3");
                    }
                }
    So my observation is:

    when I put the line (28 second code block) active:
    dialog2.setVisible(false);
    I GET THE LONG-NOT-UNDERSTANDABLE ERROR!

  8. #8
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,379
    Rep Power
    5

    Default Re: I get this enormous error message....

    Then on line 28, you should determine if dialog2 == null (println?). If so, then you have a logic error somewhere. You may want to put a print statement in line 10 to make certain dialog2 is being initialized.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  9. #9
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,062
    Rep Power
    8

    Default Re: I get this enormous error message....

    That's weird, the dialog appears on screen, so it should have been initialized!
    But when I do: System.out.println("CHANCEL " + dialog2); just before: dialog2.setVisible(false);
    it prints null, wow!

  10. #10
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,062
    Rep Power
    8

    Default Re: I get this enormous error message....

    something happens down the road, jim!
    (the DIALOG2 object is not null)
    It does not print ok3, why?

    Java Code:
     if (cmd.equals("OK")) {  
    
                    if (flag.equals("DIALOG1"))  {
                        System.out.println("OK1 ");
                        if (!CheckDialogInput()) {
                                JOptionPane.showMessageDialog(null,
                                    "Please check the hour and minutes\n" +
                                    "fields and correct the entry/ies.\n");
                        } else {
                             
                             dialog1.setVisible(false);
                             dialog2 = new CalenderDialog("DIALOG2");
                             System.out.println("OK2 " + dialog2);
                             dialog2.setBounds(300, 300, 760, 520);
                             dialog2.setModal(true);
                             dialog2.setVisible(true);
                             dialog2.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
                             System.out.println("OK3 " + dialog2);
                             
                        }
                    }

  11. #11
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,062
    Rep Power
    8

    Default Re: I get this enormous error message....

    after taking this out dialog2.setModal(true);
    I get the following...


    OK1
    OK2 studyrooms.CalenderDialog[dialog1,0,22,0x0,invalid,hidden,layout=java.awt.Bo rderLayout,MODELESS,title=Calender Dialog,defaultCloseOperation=HIDE_ON_CLOSE,rootPan e=javax.swing.JRootPane[,0,0,0x0,invalid,layout=javax.swing.JRootPane$Root Layout,alignmentX=0.0,alignmentY=0.0,border=,flags =16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    OK3 studyrooms.CalenderDialog[dialog1,300,300,760x520,layout=java.awt.BorderLayo ut,MODELESS,title=Calender Dialog,defaultCloseOperation=HIDE_ON_CLOSE,rootPan e=javax.swing.JRootPane[,0,22,760x498,layout=javax.swing.JRootPane$RootLay out,alignmentX=0.0,alignmentY=0.0,border=,flags=16 777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]
    print string first null
    at studyrooms.CalenderDialog.CheckDialogInput(Calende rDialog.java:274)
    at studyrooms.CalenderDialog.access$600(CalenderDialo g.java:31)
    at studyrooms.CalenderDialog$DialogListener.actionPer formed(CalenderDialog.java:452)
    at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:2028)
    at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2351)
    at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:242)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:236)
    at java.awt.Component.processMouseEvent(Component.jav a:6382)
    at javax.swing.JComponent.processMouseEvent(JComponen t.java:3275)
    at java.awt.Component.processEvent(Component.java:614 7)
    at java.awt.Container.processEvent(Container.java:208 3)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4744)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2141)
    at java.awt.Component.dispatchEvent(Component.java:45 72)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4619)
    at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:4280)
    at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:4210)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2127)
    at java.awt.Window.dispatchEventImpl(Window.java:2489 )
    at java.awt.Component.dispatchEvent(Component.java:45 72)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.j ava:710)
    at java.awt.EventQueue.access$400(EventQueue.java:82)
    at java.awt.EventQueue$2.run(EventQueue.java:669)
    at java.awt.EventQueue$2.run(EventQueue.java:667)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:87)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:98)
    at java.awt.EventQueue$3.run(EventQueue.java:683)
    at java.awt.EventQueue$3.run(EventQueue.java:681)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:87)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 680)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:296)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:211)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:205)
    at java.awt.Dialog$1.run(Dialog.java:1049)
    at java.awt.event.InvocationEvent.dispatch(Invocation Event.java:209)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.j ava:708)
    at java.awt.EventQueue.access$400(EventQueue.java:82)
    at java.awt.EventQueue$2.run(EventQueue.java:669)
    at java.awt.EventQueue$2.run(EventQueue.java:667)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:87)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:98)
    at java.awt.EventQueue$3.run(EventQueue.java:683)
    at java.awt.EventQueue$3.run(EventQueue.java:681)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:87)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 680)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:296)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:211)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:196)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:188)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:122)

  12. #12
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,062
    Rep Power
    8

    Default Re: I get this enormous error message....

    it makes me dizzy, I go to sleep for now, thanks Jim

  13. #13
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,062
    Rep Power
    8

    Default Re: I get this enormous error message....

    here is the whole freak'n code

    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package studyrooms;
    
    /**
     *
     * @author willem
     */
    
    
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Container;
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import java.awt.Font;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.ItemEvent;
    import java.awt.event.ItemListener;
    import javax.swing.*;
    
    
    /**
     *
     * 
     */
    public class CalenderDialog extends JDialog{
        private ImageIcon icon;
        private ActionListener DListener;
        private ItemListener clistener;
        private JCheckBox selectbox;
        private JComboBox comboA1, comboA2, comboB1, comboB2;
        private JTextField infoField;
        private JTextArea infoarea;
        private JButton okb, chancelb, resetb;
        private ComponentRef[] compref;
        private String[] hourlist, minlist, monthlist, daylist;
        private int count;
        private static String flag;
        private CalenderDialog dialog2;
        private static CalenderDialog dialog1;
        private static CalenderPanel calenderpanel;
    
        public static void main(String[] args) {
           calenderpanel = new  CalenderPanel();
           calenderpanel.setBounds(30, 30, 1700, 900);
           calenderpanel.setTitle("Calendar Window"); 
           calenderpanel.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
           dialog1 = new CalenderDialog("DIALOG1");
           dialog1.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
           dialog1.setBounds(300, 300, 520, 350);
           
           dialog1.setModal(true);
           calenderpanel.setVisible(true);
           dialog1.setVisible(true);
                
        }
    
        public CalenderDialog(String flg) {
            icon = createImageIcon("images/lic2.gif");
            setTitle("Calender Dialog");
            
            setResizable(false);
            flag = flg;
         //   System.out.println("the flag is " + flag);
            
    
            hourlist = new String[] {"7", "8", "9", "10", "11", "12", "13",
                                 "14", "15", "16", "17", "18", "19", "20",
                                  "21", "22", "23"};
            minlist = new String[] {"00", "30"};
    
            monthlist = new String[] {"enero", "febrero", "marzo", "abril", "mayo",
                                   "junio", "julio", "augusto", "septiembro",
                                   "octobre", "noviembre", "deciembre"};
    
            daylist = new String[] {"1", "2", "3", "4", "5", "6", "7", "8", "9",
                                "10", "11", "12", "13","14", "15", "16", "17",
                                "18", "19", "20", "21", "22", "23", "24", "25",
                                "26", "27", "28", "29", "30", "31"};
    
            DListener = new DialogListener();
            clistener = new ComboListener();
    
            compref = new ComponentRef[Fieldnumber(flag)]; // initiate the class that holds
                for (int i = 0; i < compref.length; i++)  // the refferences of the boxes
                        compref[i] = new ComponentRef();
    
           // createDialogPanel();
            
    
            Container contentPane = getContentPane();
            contentPane.add(createDialogPanel());
          //  contentPane.add(dialog1);
            
          //  
            
            
        }
    
    
         private JPanel createDialogPanel()  {
    
            JPanel panel = new JPanel(new BorderLayout());
            JPanel iconpanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 30, 10));
            JPanel buttonpanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
            JLabel iconlabel = new JLabel(icon);
            iconpanel.add(iconlabel);
    
            panel.setBackground(Color.WHITE);
            iconpanel.setBackground(Color.WHITE);
            buttonpanel.setBackground(Color.WHITE);
    
            infoarea = new JTextArea(3,25);
            infoarea.setPreferredSize(new Dimension(20,20));
            infoarea.setFont(new Font("Serif", Font.ITALIC, 16));
            infoarea.setEditable(false);
            if (flag.equals("DIALOG1")) { // first and second dialog text
                infoarea.setText("Set the schedule of the week days\n"
                             + "when active, check the box and\n"
                             + "and enter the duration");
            }
            if (flag.equals("DIALOG2"))  {
                infoarea.setText("Set several vacations and\n"
                             + "class free periods by checking\n"
                             + "the box and typing a short info");
            }
            iconpanel.add(infoarea);
    
            okb = new JButton("OK");
            okb.setActionCommand("OK");
            okb.addActionListener(DListener);
    
            chancelb = new JButton("CHANCEL");
            chancelb.setActionCommand("CH");
            chancelb.addActionListener(DListener);
    
            resetb = new JButton("RESET");
            resetb.setActionCommand("RS");
            resetb.addActionListener(DListener);
    
            buttonpanel.add(resetb);
            buttonpanel.add(okb);
            buttonpanel.add(chancelb);
    
            JPanel comppanel = new JPanel();
            comppanel.setBackground(Color.WHITE);
            comppanel.setLayout(new BoxLayout(comppanel,
                    BoxLayout.LINE_AXIS));
    
            Box bh = Box.createHorizontalBox();
            Box bv = Box.createVerticalBox();
    
            if (flag.equals("DIALOG1")) {
                bv.add(createSinglePanel("lunes    "));
                bv.add(createSinglePanel("martes   "));
                bv.add(createSinglePanel("miercoles"));
                bv.add(createSinglePanel("jueves   "));
                bv.add(createSinglePanel("viernes  "));
                bv.add(createSinglePanel("sabado   "));
                bv.add(createSinglePanel("domingo  "));
            }
            if (flag.equals("DIALOG2"))  {
                 for (int i = 0; i <  Fieldnumber(flag); i++)
                     bv.add(createSinglePanel((i+1) + " "));
            }
    
            comppanel.add(bv);
    
            panel.add(iconpanel, BorderLayout.NORTH);
            panel.add(comppanel, BorderLayout.CENTER);
            panel.add(buttonpanel, BorderLayout.SOUTH);
            return panel;
         }
    
    
    
         private Box createSinglePanel(String label)  {
            String[] list1 = null;
            String[] list2 = null;
    
            if (flag.equals("DIALOG1"))  { // first dialog
                list1 = hourlist;
                list2 = minlist;
    
            }
            if (flag.equals("DIALOG2"))  {  // second dialog
                list1 = monthlist;
                list2 = daylist;
            }
    
            JLabel lb = new JLabel(" until ");
            Box bx = Box.createHorizontalBox();
    
            selectbox = new JCheckBox(label);
            selectbox.setActionCommand("SELECT");
            selectbox.setSelected(false);
            selectbox.addActionListener(DListener);
            compref[count].setboxref(selectbox);
    
            comboA1 = new JComboBox(list1);
            comboA2 = new JComboBox(list2);
            comboB1 = new JComboBox(list1);
            comboB2 = new JComboBox(list2);
            lb.setLabelFor(comboB1);
    
            comboA1.setSelectedIndex(0);
            comboA2.setSelectedIndex(0);
            comboB1.setSelectedIndex(0);
            comboB2.setSelectedIndex(0);
    
            comboA1.addItemListener(clistener);
            comboA2.addItemListener(clistener);
        //    comboB1.addItemListener(clistener);
        //    comboB2.addItemListener(clistener);
    
            compref[count].setcomboA1(comboA1);
            compref[count].setcomboA2(comboA2);
            compref[count].setcomboB1(comboB1);
            compref[count].setcomboB2(comboB2);
            comboA1.setEnabled(false);
            comboA2.setEnabled(false);
            comboB1.setEnabled(false);
            comboB2.setEnabled(false);
    
            infoField = null;
            if (flag.equals("DIALOG2"))  {// in case of second dialog
                    infoField = new JTextField(23);
                    infoField.setMaximumSize(infoField.getPreferredSize());
                    infoField.setText("info of vacation etc");
                    infoField.setEnabled(false);
                    compref[count].settextfieldref(infoField);
            }
    
            bx.add(selectbox);
            if (flag.equals("DIALOG2")) bx.add(infoField);
            bx.add(Box.createHorizontalGlue());
            bx.add(comboA1);
            bx.add(comboA2);
            bx.add(lb);
            bx.add(comboB1);
            bx.add(comboB2);
    
            count++;
            return bx;
        }
    
        
    
    
        private boolean CheckDialogInput() {
           
            boolean bln = true;
            String s = null;
            for (int i = 0; i < Fieldnumber(flag) ; i++) {
                if (compref[i].getboxref().isSelected()) {
                    if (compref[i].getcomboA1().getSelectedIndex() >
                        compref[i].getcomboB1().getSelectedIndex()) {
                        bln = false;
                    }
    
                    if (compref[i].getcomboA1().getSelectedIndex() ==
                        compref[i].getcomboB1().getSelectedIndex() &&
                        compref[i].getcomboA2().getSelectedIndex() >=
                        compref[i].getcomboB2().getSelectedIndex()) {
                        bln = false;
                    }
                    if (flag.equals("DIALOG2"))  {
                        System.out.println("print string first " + s);
                        s = compref[i].gettextfieldref().getText();
                        System.out.println("print string second " + s);
                        if ( s.equals("") || s.equals("info of vacation etc"))  
                            bln = false;
                    }
                }
            }
            return bln;
        }
    
        private int Fieldnumber(String flg)  {
            if (flag.equals("DIALOG1"))
                 return 7;
            else
                 return 10;
        }
    
    
        class ComponentRef {
           private JCheckBox boxref;
           private JComboBox comborefA1, comborefA2, comborefB1, comborefB2;
           private JTextField textfieldref;
    
           public void setboxref(JCheckBox br)  {
                    boxref = br;
           }
           public JCheckBox getboxref()  {
                    return boxref;
           }
    
           public void setcomboA1(JComboBox cb)  {
                   comborefA1 = cb;
           }
           public JComboBox getcomboA1()  {
                    return comborefA1;
           }
    
           public void setcomboA2(JComboBox cb)  {
                   comborefA2 = cb;
           }
           public JComboBox getcomboA2()  {
                    return comborefA2;
           }
    
           public void setcomboB1(JComboBox cb)  {
                   comborefB1 = cb;
           }
           public JComboBox getcomboB1()  {
                    return comborefB1;
           }
    
           public void setcomboB2(JComboBox cb)  {
                   comborefB2 = cb;
           }
           public JComboBox getcomboB2()  {
                    return comborefB2;
           }
    
           public void settextfieldref(JTextField tf)  {
                   textfieldref = tf;
           }
           public JTextField gettextfieldref()  {
                    return textfieldref;
           }
    
        }
    
        private class ComboListener implements ItemListener {
    
            public void itemStateChanged(ItemEvent ie) {
    
                    int x = Fieldnumber(flag);
                    for (int i = 0; i < x ; i++) {
                        if (compref[i].getboxref().isSelected()) {
                            System.out.println("Source: " + ie.getItem());
                            x = compref[i].getcomboA1().getSelectedIndex();
                            compref[i].getcomboB1().setSelectedIndex(x);
                            for (int ii = 0; ii < x ; ii++) {
                              //  compref[i].getcomboB1().removeItemAt(ii+1);
    
                            }
                        }
                    }
    
                    for (int i = 0; i < x ; i++) {
                        if (compref[i].getboxref().isSelected()) {
                            x = compref[i].getcomboA2().getSelectedIndex();
                            compref[i].getcomboB2().setSelectedIndex(x);
                            for (int ii = 0; ii < x ; ii++) {
                              //  compref[i].getcomboB2().removeItemAt(ii+1);
    
                            }
                        }
                    }
            }
        }
    
        private class DialogListener implements ActionListener {
            public void actionPerformed(ActionEvent e)  {
                String cmd = e.getActionCommand();
    
                 if (cmd.equals("SELECT")) {
                    for (int i = 0; i < Fieldnumber(flag) ; i++) { //comboref.length
                        if (compref[i].getboxref().isSelected())  {
                                compref[i].getcomboA1().setEnabled(true);
                                compref[i].getcomboA2().setEnabled(true);
                                compref[i].getcomboB1().setEnabled(true);
                                compref[i].getcomboB2().setEnabled(true);
                                if (flag.equals("DIALOG2")) // when second dialog selected
                                    compref[i].gettextfieldref().setEnabled(true);
                        }
                        else {
                            compref[i].getcomboA1().setEnabled(false);
                            compref[i].getcomboA2().setEnabled(false);
                            compref[i].getcomboB1().setEnabled(false);
                            compref[i].getcomboB2().setEnabled(false);
                            compref[i].getcomboA1().setSelectedIndex(0);
                            compref[i].getcomboA2().setSelectedIndex(0);
                            compref[i].getcomboB1().setSelectedIndex(0);
                            compref[i].getcomboB2().setSelectedIndex(0);
                            if (flag.equals("DIALOG2"))
                                compref[i].gettextfieldref().setEnabled(false);
                        }
                   }
                }
    
    
    
                if (cmd.equals("RS")) { //reset button
                    for (int i = 0; i < Fieldnumber(flag) ; i++) { 
    
                            compref[i].getboxref().setSelected(false);
                            compref[i].getcomboA1().setEnabled(false);
                            compref[i].getcomboA2().setEnabled(false);
                            compref[i].getcomboB1().setEnabled(false);
                            compref[i].getcomboB2().setEnabled(false);
                            compref[i].getcomboA1().setSelectedIndex(0);
                            compref[i].getcomboA2().setSelectedIndex(0);
                            compref[i].getcomboB1().setSelectedIndex(0);
                            compref[i].getcomboB2().setSelectedIndex(0);
                       if (flag.equals("DIALOG2"))  {
                           compref[i].gettextfieldref().setText("info of vacation etc");
                           compref[i].gettextfieldref().setEnabled(false);
                       }
                   }
                }
    
                if (cmd.equals("CH")) {
                  System.out.println("CHANCEL " + dialog2);
                  dialog2.setVisible(false);
                 // setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                }
                
                if (cmd.equals("OK")) {  
    
                    if (flag.equals("DIALOG1"))  {
                        System.out.println("OK1 ");
                        if (!CheckDialogInput()) {
                    //    if (false) {
                                JOptionPane.showMessageDialog(null,
                                    "Please check the hour and minutes\n" +
                                    "fields and correct the entry/ies.\n");
                        } else {
                             
                             dialog1.setVisible(false);
                             dialog2 = new CalenderDialog("DIALOG2");
                             System.out.println("OK2 " + dialog2);
                             dialog2.setBounds(300, 300, 760, 520);
                             dialog2.setModal(true);
                             dialog2.setVisible(true);
                             dialog2.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
                             System.out.println("OK3 " + dialog2);
                             
                        }
                    }
    
                    if (flag.equals("DIALOG2"))  {
    
                        if (!CheckDialogInput()) {
                                JOptionPane.showMessageDialog(null,
                                    "Please check the month and day\n" +
                                    "fields and correct the entry/ies.\n" +
                                    "The info field should be filled out too.\n");
                        } else {
                            
                           
                            
                            flag = "DIALOG2";
                        }
                    }
    
                    if (flag.equals("DIALOG3"))  {
                        System.out.println("DIALOG3");
                    }
                }
            }
        }
    
    
        protected static ImageIcon createImageIcon(String path) { // loads the icons
            java.net.URL imgURL = CalenderPanel.class.getResource(path);
            if (imgURL != null) {
                return new ImageIcon(imgURL);
            } else {
                System.err.println("Couldn't find file: " + path);
                return null;
            }
       }
    
    
    
    }

  14. #14
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,062
    Rep Power
    8

    Default Re: I get this enormous error message....

    and the other class (so you get dizzy as well)

    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package studyrooms;
    
    /**
     *
     * @author willem
     */
    
    
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    
    
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Container;
    import java.awt.FlowLayout;
    import java.awt.Font;
    import java.awt.GridLayout;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.util.Calendar;
    import java.util.Locale;
    import javax.swing.*;
    import javax.swing.border.Border;
    
    /**
     *
     * @author willem
     */
    public class CalenderPanel extends JFrame {
    
        private Font theFont, smallFont;
        private Color bluecolor, blackcolor;
        private Calendar cal, calprint;
        private MouseHandler Mhandler;
        private PanelData paneldata[];
        private String monthlabel[], days[];
        private int monthCons[];
        private int daycount, thisyear, maxvacationfields;
    
    
    
        CalenderPanel()  {
            cal = Calendar.getInstance(Locale.GERMANY);
            calprint = Calendar.getInstance(Locale.GERMANY);
            setBounds(30, 30, 1700, 900);
            setTitle("Calendar Window");
    
            bluecolor = Color.BLUE;
            blackcolor = Color.BLACK;
            theFont = new Font("SansSerif", Font.PLAIN, 14);
            smallFont = new Font("SansSerif", Font.PLAIN, 11);
    
            monthlabel = new String[] {"SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER",
            "JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST"};
    
            days = new String[]  {"lunes", "martes", "miércoles", "jueves",
                "viernes", "sábado", "domingo"};
    
            monthCons = new int[] {Calendar.SEPTEMBER, Calendar.OCTOBER,
            Calendar.NOVEMBER, Calendar.DECEMBER, Calendar.JANUARY,
            Calendar.FEBRUARY, Calendar.MARCH, Calendar.APRIL,
            Calendar.MAY, Calendar.JUNE, Calendar.JULY,
            Calendar.AUGUST};
    
            Mhandler = new MouseHandler(); // mousehandler for the panels
    
            paneldata = new PanelData[370]; // initialize panel data array
                for (int i = 0; i < paneldata.length; i++) {
                        paneldata[i] = new PanelData();
                }
    
    
            daycount = 0; // this counts the days of the year for the panels
            // set the actual year as acedemic year year or year-1
            thisyear = cal.get(Calendar.YEAR);
            thisyear = thisyear-1;
            Container contentPane = getContentPane();
            contentPane.add(setupYearCalenderPanel(thisyear));
    
         //   System.out.println(" first year day (sunday=1) " + resetFirstLastDay(thisyear, 0));
         //   int maxday = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
         //   int firstday = cal.getActualMinimum(Calendar.DAY_OF_MONTH);
         //   System.out.println(" max day of that month " + maxday);
         //   System.out.println(" first day of that month " + firstday);
        }
    
        public static void main(String[] args) {
            CalenderPanel frame = new CalenderPanel();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
        }
    
        public JPanel setupYearCalenderPanel(int year)  {
                // the 12 month of the year
                JPanel yearPanel = new JPanel(new GridLayout(3,4,2,2));
                yearPanel.setBackground(Color.WHITE);
                for (int i = 0; i < 12; i++) { // set the month cicle
                    if (i == 4) year = year +1; // shift for the acedemic year
                    yearPanel.add(setupSingleCalenderPanel(resetFirstLastDay(year, i), year, i));
                }
    
                return yearPanel;
        }
    
        public int resetFirstLastDay(int year, int month){ // month 0-11
            // the acedemic year runs from sept to sept
            // one year shift for the leap-year of the month feb
            year=year-1;
            
            calprint.set(year, monthCons[month], 1);
            int weekday = calprint.get(Calendar.DAY_OF_WEEK);
            int maxday = calprint.getActualMaximum(Calendar.DAY_OF_MONTH);
    
           // scaling for the calendar graph
            weekday = weekday + 5;
            if (weekday > 6) weekday = weekday - 7;
           // System.out.println(" year >" + year + " month number >" + month +
           //         " day of the week sunday=1 >" + weekday);
           // System.out.println("the mont " + month + " daynumber " + weekday +
           //         " last day of the month " + maxday);
            return weekday; // the first day of the month 0 = monday until 6
    
    
        }
    
         public int CalcDaynumber(int year, int month)  {
             int maxday = 0;
             month = month + 4; // shift for the acedemic year sept-sept
             if (month >= 11) month = month - 11;
             for (int i = 0; i < month; i++) {
                resetFirstLastDay(year, i); // this sets a particular date
                // this gives the max days of that particular month
                int x = calprint.getActualMaximum(Calendar.DAY_OF_MONTH);
                maxday = maxday + x;
            //    System.out.println(" number of tdays per month " + (i+1) + " > " + maxday);
             }
    
             return maxday;
         }
    
    
        public JPanel setupSingleCalenderPanel(int day, int year, int month)  {
            // for layout it is important that all of the grids get filled
            JPanel mainPanel = new JPanel(new BorderLayout());
            mainPanel.setBackground(Color.WHITE);
            JPanel monthPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
            monthPanel.setBackground(Color.WHITE);
    
            
            // first row, set the text of that particular month
            JLabel monthLabel = new JLabel(year + "/ " + monthlabel[month]);
            monthPanel.add(monthLabel);
            JPanel daysPanel = new JPanel(new GridLayout(7, 7, 1, 1));
            daysPanel.setBackground(Color.WHITE);
            JPanel dPanel;
            JLabel dayLabel;
                // sets the second row that contains the week days
            for (int i = 0; i < 7; i++) {
                
                dPanel = new JPanel(new GridLayout(1, 1));
                dPanel.setBackground(Color.WHITE);
             //   dPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
                dayLabel = new JLabel("", SwingConstants.CENTER);
                dayLabel.setBackground(Color.WHITE);
                dayLabel.setFont(smallFont);
              //  dayLabel.setVerticalTextPosition(JLabel.BOTTOM);
                dayLabel.setVerticalAlignment(SwingConstants.BOTTOM);
                dayLabel.setText("" + days[i]);
    
    
                dPanel.add(dayLabel);
                daysPanel.add(dPanel);
            }
    
                // the first empty month day panels
            for (int i = 0; i < day; i++) {
                dPanel = new JPanel();
                dPanel.setBackground(Color.WHITE);
                daysPanel.add(dPanel);
            }
                // set the actual month for getting the max day of that month
                // calculate the day panels and the rest panels to the fill the month
                // month 0-11, days 1-31 days of the week 1-7 sunday is 1
            resetFirstLastDay(year, month); // this sets a particular date
            // this gives the max days of that particular month
            int maxday = calprint.getActualMaximum(Calendar.DAY_OF_MONTH);
            int restday = 31 - maxday;
    
                // setup the actual daypanels of the month
            for (int i = 0; i < maxday; i++) {
                dPanel = new JPanel();
    
                dPanel.setBackground(Color.WHITE);
                daysPanel.add(dPanel);
                JLabel dateLabel = new JLabel("" + (i+1));
                dPanel.add(dateLabel);
                dPanel.addMouseListener(Mhandler);
                paneldata[daycount].setPanelRef(dPanel);
                paneldata[daycount].setDateString(monthlabel[month]
                                                        + "/ " + (i+1));
                daycount++;
                Border etched = BorderFactory.createEtchedBorder(blackcolor,
                                                    blackcolor);
                dPanel.setBorder(etched);
            }
    
            for (int i = 0; i < 11-day+restday; i++) {
                dPanel = new JPanel();
                dPanel.setBackground(Color.WHITE);
                daysPanel.add(dPanel);
    
            }
    
            mainPanel.add(monthPanel, BorderLayout.NORTH);
            mainPanel.add(daysPanel, BorderLayout.CENTER);
            Border etched = BorderFactory.createEtchedBorder(blackcolor,
                                                    blackcolor);
            mainPanel.setBorder(etched);
    
            return mainPanel;
        }
    
    
    
        
    
        private class PanelData { // the year array for each day
            private boolean dayset;
            private JPanel panelreference;
            private String datestring;
    
            public void setDayAvailable(boolean dt)  {
                    dayset = dt;
                }
            public boolean getDayAvailable()  {
                    return dayset;
                }
    
            public void setDateString(String st)  {
                    datestring = st;
                }
            public String getDateString()  {
                    return datestring;
                }
    
            public void setPanelRef(JPanel pr)  {
                    panelreference = pr;
                }
            public JPanel getPanelRef()  {
                    return panelreference;
                }
    
        }
    
    
    
    
        public class MouseHandler implements MouseListener {
    
            public void mousePressed(MouseEvent e) {
            }
    
            public void mouseReleased(MouseEvent e) {
            }
    
            public void mouseEntered(MouseEvent e) {
            }
    
            public void mouseExited(MouseEvent e) {
            }
    
            public void mouseClicked(MouseEvent e) {
                int indx = 0;
                if (e.getClickCount() >= 2) {
                    // roominfopanrl array
                    for (int i = 0; i < paneldata.length; i++) {
                       if (paneldata[i].getDayAvailable()) {
                          indx = i;
    
                       }
                       else {
                          indx = i;
                       }
    
                       if (e.getSource() == paneldata[i].getPanelRef()) {
                                System.out.println(paneldata[i].getDateString() +
                                        " day number " + i);
                       }
                    }
                    System.out.println(paneldata[indx].getDateString());
                }
            }
    
       }
    
    
    
    }

  15. #15
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,062
    Rep Power
    8

    Default Re: I get this enormous error message....

    good night for now

  16. #16
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,062
    Rep Power
    8

    Default Re: I get this enormous error message....

    Is there a way to block this?

  17. #17
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,798
    Rep Power
    19

    Default Re: I get this enormous error message....

    Killed the lady-spam...:)

    Right, 'dialog1' is a static attribute of your main class.
    'dialog2' is a non-static attribute of CalenderDialog.

    You have a listener on the 'OK' button.
    That listener closes 'dialog1' and then (in the object representing dialog1) creates a dialog2.
    That dialog2 has its own 'dialog2' attribute...that is not initialised.

    Your best bet is to break out the controller aspect into its own class (including the main method).
    Remove the dialog attributes from the CalenderDialog entirely.
    Have the actionPerformed pass on the button click to the new main class which will control which dialog to show.
    The dialogs should not be controlling each other like this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  18. #18
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,379
    Rep Power
    5

    Default Re: I get this enormous error message....

    Quote Originally Posted by Tolls View Post
    Killed the lady-spam...:)
    Actually, that was the best spam I had seen in quite a while.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  19. #19
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,798
    Rep Power
    19

    Default Re: I get this enormous error message....

    Not the best if you're in an office...:)
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  20. #20
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,062
    Rep Power
    8

    Default Re: I get this enormous error message....

    I prefer to meet you two (jim and tolls) at this blog and
    those ladies at a bar (not the other way around please....)
    thanks will look into your comment tolls

Page 1 of 2 12 LastLast

Similar Threads

  1. help me with this error message
    By joel7 in forum New To Java
    Replies: 1
    Last Post: 11-27-2012, 08:10 AM
  2. Need help with error message!
    By cstampar in forum New To Java
    Replies: 2
    Last Post: 12-04-2011, 07:52 PM
  3. Error Message
    By Bimz in forum New To Java
    Replies: 2
    Last Post: 09-11-2011, 01:01 PM
  4. Error Message????
    By Cubba27 in forum New To Java
    Replies: 11
    Last Post: 11-21-2009, 02:46 PM

Posting Permissions

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