Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 1 of 2 12 LastLast
Results 1 to 25 of 30

Thread: Help with elections program

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    15
    My Mood
    Inspired
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Help with elections program

    Hey guys..I am not able to find the solution of the problem in my applet. It displays the buttons for only one category and it is not going ahead with the program.
    Please help me find the problem and solution...
    My program is.....

    import java.awt.*;     //Basic hierarchy of packages for native GUI components
    import java.applet.*;    //Package for creating an applet
    import java.awt.event.*; 
    import java.awt.event.MouseListener;
    public  class App extends Applet implements MouseListener 
    {
        String HY="Head Boy";
        String HL="Head Girl";
        String SY="Sports Prefect Boy";
        String SL="Sports Prefect Girl";
        String CHC="Cheetah House Captain";
        String CHVC="Cheetah House Vice-Captain";
     
        String HB11="Arnav Kholkar";
        String HB12="Chinmay Patwardhan";
        String HB13="Ishan Joshi";
        String HB14="Sumedh Sontakke";
     
        String HG11="Avani Awasthee";
        String HG12="Chaiti Bhagwat";
        String HG13="Rucha Kalekar";
        String HG14="Smruti Pimplikar";
     
        String SPB11="Anuj Kankaria";
        String SPB12="Arnav Kholkar";
        String SPB13="Chinmay Patwardhan";
        String SPB14="Yogesh Sirvi";
     
        String SPG11="Disha Trivedi";
        String SPG12="Manasi Gokhale";
        String SPG13="Shivani Gupta";
        String SPG14="Shruti Jani";
     
        String C11="Shaunak Chitgopkar";
        String C12="Shivani Gupta";
        String C13="Smruti Pimplikar";
        String C14="Surinder Mathrani";
     
        String VC11="Arya Prabhudesai";
        String VC12="Atharva Mahajan";
        String VC13="Chinmay Kalluraya";
        String VC14="Manasi Deshpande";
     
        int HB1,HB2,HB3,HB4,HG1,HG2,HG3,HG4,SPB1,SPB2,SPB3,SPB4,SPG1,SPG2,SPG3,SPG4,C1,C2,C3,C4,VC1,VC2,VC3,VC4;
        int tie; //Variable that checks whether two or more candidates received the same number of votes. 
        Font font;   //Allows the message to be printed in a specific font 
        Button button,H1,H2,H3,H4; //The buttons used for selecting the choice    
        Label label,title,HB,HG;
        Panel P1,P2,P3,P4; // area where the buttons can be displayed
        public void init() //Initialising Method for Applet
        {
            addMouseListener(this);
            setLayout (new BorderLayout ());
            P1 = new Panel (new BorderLayout ());
            P2 = new Panel (); 
            P3 = new Panel ();
            P4 = new Panel ();
            font = new Font ("ComicSans", Font.BOLD, 17);
            setFont (font);
            this.setBackground(Color.yellow);
            label= new Label("Welcome to Vidya Valley School Elections");
            HB = new Label (HY);
            HG= new Label(HL);
            HB.addMouseListener (this);
            add (P1, "North");
            P1.add (P2, "North");
            P2.add (label);
            label.setBackground(Color.black);
            label.setForeground(Color.green);
            HB.setBackground(Color.white);
            HB.setForeground(Color.black);
            H1= new Button (HB11);
            H1.addMouseListener (this);
            H2= new Button (HB12);
            H2.addMouseListener (this);
            H3= new Button (HB13);
            H3.addMouseListener (this);
            H4= new Button (HB14);
            H4.addMouseListener (this);
            P1.add (P3,"West");
            P3.add (HB);
            P3.add (H1);
            P3.add (H2);
            P3.add (H3);
            P3.add (H4);
        }
     
        public void mouseClicked(MouseEvent e)
        {
            if(e.getSource () == H1)
            {
                P1.add(P4,"West");
                P4.add(HG);
            }
        }
        // methods used for applet installment and destruction
        public void start() 
        {
            System.out.println(" Applet Starting ");
        }
     
        public void stop() 
        {
            System.out.println(" Applet Stopping ");
        }
     
        public void destroy() 
        {
            System.out.println(" Applet Destroyed ");
        }
     
        //These are not used but are necessary for mouseListener
        public void mouseEntered (MouseEvent e)
        {
        }
     
        public void mouseExited (MouseEvent e)
        {
        }
     
        public void mousePressed (MouseEvent e)
        {
        }
     
        public void mouseReleased (MouseEvent e)
        {
        }
     
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Help with elections program

    it is not going ahead with the program.
    Please explain what happens when you execute the program.
    What do you do and what does the program do in response?
    What do you want the program to do differently?


    Please copy and paste here the full text of any error messages.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    15
    My Mood
    Inspired
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with elections program

    Quote Originally Posted by Norm View Post
    Please explain what happens when you execute the program.
    What do you do and what does the program do in response?
    What do you want the program to do differently?


    Please copy and paste here the full text of any error messages.
    When I execute..The Label Vidya Valley School Elections is displayed.
    The label Head Boy is also displayed and along with it 4 buttons are also displayed.
    If I click on the first button nothing happens...I have a given a condition in the method mouseClicked(MouseEvent e), I'm not sure if it is right
    The program doesn't execute anything further on clicking the buttons
    I want the program to display the next set of buttons for the label: Head Girl.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Help with elections program

    If I click on the first button nothing happens.
    Is the listener called when you click on the button? Add a call to println() in the listener method to print out a message when the listener is called. Then if the message is printed you'll know the listener was called.

    Normally you use an ActionListener with buttons to detect when they are clicked.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Dec 2012
    Posts
    15
    My Mood
    Inspired
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with elections program

    Quote Originally Posted by Norm View Post
    Is the listener called when you click on the button? Add a call to println() in the listener method to print out a message when the listener is called. Then if the message is printed you'll know the listener was called.

    Normally you use an ActionListener with buttons to detect when they are clicked.
    I have tried printing a message but nothing happens..I guess the listener is not being called.
    Should I convert it to ActionListener?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Help with elections program

    Where did you put the println() statement? In what methods? Where did move and click the mouse?

    Yes you should use ActionListeners with buttons.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Dec 2012
    Posts
    15
    My Mood
    Inspired
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with elections program

    Quote Originally Posted by Norm View Post
    Where did you put the println() statement? In what methods? Where did move and click the mouse?

    Yes you should use ActionListeners with buttons.
    I put the println() statement in mouseClicked method.
    I clicked the mouse on the buttons

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Help with elections program

    There should be something printed out when the mouse was clicked.
    What about all the other mouse listener methods? Did you add printlns there?

    Where did you look to see what was printed?

    Here is some of what I see when the code is executed and the mouse moved:

    Applet Starting
    mEn e=java.awt.event.MouseEvent[MOUSE_ENTERED,(58,197),absolute(66,247),button=0,c lickCount=0] on panel0
    mEx e=java.awt.event.MouseEvent[MOUSE_EXITED,(23,75),absolute(31,125),button=0,cli ckCount=0] on panel0
    mEn e=java.awt.event.MouseEvent[MOUSE_ENTERED,(16,27),absolute(29,120),button=0,cl ickCount=0] on label0
    mEx e=java.awt.event.MouseEvent[MOUSE_EXITED,(15,28),absolute(28,121),button=0,cli ckCount=0] on label0
    mEn e=java.awt.event.MouseEvent[MOUSE_ENTERED,(20,76),absolute(28,126),button=0,cl ickCount=0] on panel0
    mEx e=java.awt.event.MouseEvent[MOUSE_EXITED,(20,75),absolute(28,125),button=0,cli ckCount=0] on panel0
    mEn e=java.awt.event.MouseEvent[MOUSE_ENTERED,(15,27),absolute(28,120),button=0,cl ickCount=0] on label0
    mEx e=java.awt.event.MouseEvent[MOUSE_EXITED,(17,-1),absolute(30,92),button=0,clickCount=0] on label0
    mEn e=java.awt.event.MouseEvent[MOUSE_ENTERED,(23,0),absolute(36,93),button=0,clic kCount=0] on label0
    mEx e=java.awt.event.MouseEvent[MOUSE_EXITED,(25,28),absolute(38,121),button=0,cli ckCount=0] on label0
    mEn e=java.awt.event.MouseEvent[MOUSE_ENTERED,(31,76),absolute(39,126),button=0,cl ickCount=0] on panel0
    mEx e=java.awt.event.MouseEvent[MOUSE_EXITED,(38,74),absolute(46,124),button=0,cli ckCount=0] on panel0
    mEn e=java.awt.event.MouseEvent[MOUSE_ENTERED,(32,27),absolute(45,120),button=0,cl ickCount=0] on label0
    mEx e=java.awt.event.MouseEvent[MOUSE_EXITED,(30,-1),absolute(43,92),button=0,clickCount=0] on label0
    mEn e=java.awt.event.MouseEvent[MOUSE_ENTERED,(30,1),absolute(43,94),button=0,clic kCount=0] on label0
    mEx e=java.awt.event.MouseEvent[MOUSE_EXITED,(31,28),absolute(44,121),button=0,cli ckCount=0] on label0
    mEn e=java.awt.event.MouseEvent[MOUSE_ENTERED,(36,76),absolute(44,126),button=0,cl ickCount=0] on panel0
    mEx e=java.awt.event.MouseEvent[MOUSE_EXITED,(740,207),absolute(748,257),button=0, clickCount=0] on panel0
    mEn e=java.awt.event.MouseEvent[MOUSE_ENTERED,(741,196),absolute(749,246),button=0 ,clickCount=0] on panel0
    mEx e=java.awt.event.MouseEvent[MOUSE_EXITED,(43,74),absolute(51,124),button=0,cli ckCount=0] on panel0
    mEn e=java.awt.event.MouseEvent[MOUSE_ENTERED,(38,27),absolute(51,120),button=0,cl ickCount=0] on label0
    mEx e=java.awt.event.MouseEvent[MOUSE_EXITED,(102,6),absolute(115,99),button=0,cli ckCount=0] on label0
    mEn e=java.awt.event.MouseEvent[MOUSE_ENTERED,(7,6),absolute(115,99),button=0,clic kCount=0] on button0
    mEx e=java.awt.event.MouseEvent[MOUSE_EXITED,(104,-1),absolute(212,92),button=0,clickCount=0] on button0
    mEn e=java.awt.event.MouseEvent[MOUSE_ENTERED,(824,79),absolute(832,129),button=0, clickCount=0] on panel0
    mEx e=java.awt.event.MouseEvent[MOUSE_EXITED,(821,205),absolute(829,255),button=0, clickCount=0] on panel0
    mEn e=java.awt.event.MouseEvent[MOUSE_ENTERED,(800,199),absolute(808,249),button=0 ,clickCount=0] on panel0
    mEx e=java.awt.event.MouseEvent[MOUSE_EXITED,(786,202),absolute(794,252),button=0, clickCount=0] on panel0
    mEn e=java.awt.event.MouseEvent[MOUSE_ENTERED,(778,196),absolute(786,246),button=0 ,clickCount=0] on panel0
    mP e=java.awt.event.MouseEvent[MOUSE_PRESSED,(790,189),absolute(798,239),button=1 ,modifiers=Button1,extModifiers=Button1,clickCount =1] on panel0
    mEx e=java.awt.event.MouseEvent[MOUSE_EXITED,(714,200),absolute(722,250),button=0, clickCount=0] on panel0
    mEn e=java.awt.event.MouseEvent[MOUSE_ENTERED,(398,198),absolute(406,248),button=0 ,clickCount=0] on panel0
    mEx e=java.awt.event.MouseEvent[MOUSE_EXITED,(107,75),absolute(115,125),button=0,c lickCount=0] on panel0
    mEn e=java.awt.event.MouseEvent[MOUSE_ENTERED,(6,27),absolute(114,120),button=0,cl ickCount=0] on button0
    mEx e=java.awt.event.MouseEvent[MOUSE_EXITED,(128,20),absolute(236,113),button=0,c lickCount=0] on button0
    mEn e=java.awt.event.MouseEvent[MOUSE_ENTERED,(44,20),absolute(283,113),button=0,c lickCount=0] on button1
    mEx e=java.awt.event.MouseEvent[MOUSE_EXITED,(200,20),absolute(439,113),button=0,c lickCount=0] on button1
    mEn e=java.awt.event.MouseEvent[MOUSE_ENTERED,(14,20),absolute(439,113),button=0,c lickCount=0] on button2
    mEx e=java.awt.event.MouseEvent[MOUSE_EXITED,(108,20),absolute(533,113),button=0,c lickCount=0] on button2
    mEn e=java.awt.event.MouseEvent[MOUSE_ENTERED,(0,20),absolute(533,113),button=0,cl ickCount=0] on button3
    mEx e=java.awt.event.MouseEvent[MOUSE_EXITED,(166,31),absolute(699,124),button=0,c lickCount=0] on button3
    mEn e=java.awt.event.MouseEvent[MOUSE_ENTERED,(713,78),absolute(721,128),button=0, clickCount=0] on panel0
    mEx e=java.awt.event.MouseEvent[MOUSE_EXITED,(772,74),absolute(780,124),button=0,c lickCount=0] on panel0
    mEn e=java.awt.event.MouseEvent[MOUSE_ENTERED,(813,77),absolute(821,127),button=0, clickCount=0] on panel0
    mEx e=java.awt.event.MouseEvent[MOUSE_EXITED,(679,74),absolute(687,124),button=0,c lickCount=0] on panel0
    mEn e=java.awt.event.MouseEvent[MOUSE_ENTERED,(148,27),absolute(681,120),button=0, clickCount=0] on button3
    mEx e=java.awt.event.MouseEvent[MOUSE_EXITED,(116,29),absolute(649,122),button=0,c lickCount=0] on button3
    mEn e=java.awt.event.MouseEvent[MOUSE_ENTERED,(641,76),absolute(649,126),button=0, clickCount=0] on panel0
    mEx e=java.awt.event.MouseEvent[MOUSE_EXITED,(620,74),absolute(628,124),button=0,c lickCount=0] on panel0
    mEn e=java.awt.event.MouseEvent[MOUSE_ENTERED,(95,27),absolute(628,120),button=0,c lickCount=0] on button3
    mEx e=java.awt.event.MouseEvent[MOUSE_EXITED,(81,33),absolute(614,126),button=0,cl ickCount=0] on button3
    mEn e=java.awt.event.MouseEvent[MOUSE_ENTERED,(606,76),absolute(614,126),button=0, clickCount=0] on panel0
    mEx e=java.awt.event.MouseEvent[MOUSE_EXITED,(416,74),absolute(424,124),button=0,c lickCount=0] on panel0
    mEn e=java.awt.event.MouseEvent[MOUSE_ENTERED,(0,26),absolute(425,119),button=0,cl ickCount=0] on button2
    mEx e=java.awt.event.MouseEvent[MOUSE_EXITED,(19,31),absolute(444,124),button=0,cl ickCount=0] on button2
    mEn e=java.awt.event.MouseEvent[MOUSE_ENTERED,(434,81),absolute(442,131),button=0, clickCount=0] on panel0
    mEx e=java.awt.event.MouseEvent[MOUSE_EXITED,(357,75),absolute(365,125),button=0,c lickCount=0] on panel0
    mEn e=java.awt.event.MouseEvent[MOUSE_ENTERED,(125,26),absolute(364,119),button=0, clickCount=0] on button1
    mEx e=java.awt.event.MouseEvent[MOUSE_EXITED,(115,29),absolute(354,122),button=0,c lickCount=0] on button1
    mEn e=java.awt.event.MouseEvent[MOUSE_ENTERED,(344,77),absolute(352,127),button=0, clickCount=0] on panel0
    mEx e=java.awt.event.MouseEvent[MOUSE_EXITED,(344,75),absolute(352,125),button=0,c lickCount=0] on panel0
    mEn e=java.awt.event.MouseEvent[MOUSE_ENTERED,(114,25),absolute(353,118),button=0, clickCount=0] on button1
    mEx e=java.awt.event.MouseEvent[MOUSE_EXITED,(102,30),absolute(341,123),button=0,c lickCount=0] on button1
    mEn e=java.awt.event.MouseEvent[MOUSE_ENTERED,(328,79),absolute(336,129),button=0, clickCount=0] on panel0
    mEx e=java.awt.event.MouseEvent[MOUSE_EXITED,(143,75),absolute(151,125),button=0,c lickCount=0] on panel0
    mEn e=java.awt.event.MouseEvent[MOUSE_ENTERED,(43,26),absolute(151,119),button=0,c lickCount=0] on button0
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Dec 2012
    Posts
    15
    My Mood
    Inspired
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with elections program

    Quote Originally Posted by Norm View Post
    There should be something printed out when the mouse was clicked.
    What about all the other mouse listener methods? Did you add printlns there?

    Where did you look to see what was printed?

    Here is some of what I see when the code is executed and the mouse moved:
    Okay I have no idea what you did...but now I made a similar coded class with ActionListener
    It is pretty much the same just without the other methods that were there for mouseListener.
    Also..what did you do that got you this above code?

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Help with elections program

    what did you do that got you this above code?
    I added println statements to all the mouse listener methods.
    When I executed the program and moved the mouse over the window, the above messages were printed out.

    Do you see any of the messages that the program prints out? For example this one:
    Applet Starting

    If not, then you are not looking in the right place to see the print outs. In a browser, the print outs are shown in the browser's java console.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Dec 2012
    Posts
    15
    My Mood
    Inspired
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with elections program

    Quote Originally Posted by Norm View Post
    I added println statements to all the mouse listener methods.
    When I executed the program and moved the mouse over the window, the above messages were printed out.

    Do you see any of the messages that the program prints out? For example this one:
    Applet Starting

    If not, then you are not looking in the right place to see the print outs. In a browser, the print outs are shown in the browser's java console.
    I see the message Applet Starting in the terminal window. I am using the applet viewer.
    Now that I have made the program into ActionListener, what difference does it make and yet the buttons are not being clicked.

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Help with elections program

    Please post the current version of the code.
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Junior Member
    Join Date
    Dec 2012
    Posts
    15
    My Mood
    Inspired
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with elections program

    The updated version:

    import java.awt.*;     //Basic hierarchy of packages for native GUI components
    import java.applet.*;   //Package for creating an applet
    import javax.swing.*;
    import java.awt.event.*; 
    import java.awt.event.ActionListener;
    public  class App1 extends JApplet implements ActionListener 
    {
        String HY="Head Boy";
        String HL="Head Girl";
        String SY="Sports Prefect Boy";
        String SL="Sports Prefect Girl";
        String CHC="Cheetah House Captain";
        String CHVC="Cheetah House Vice-Captain";
     
        String HB11="Arnav Kholkar";
        String HB12="Chinmay Patwardhan";
        String HB13="Ishan Joshi";
        String HB14="Sumedh Sontakke";
     
        String HG11="Avani Awasthee";
        String HG12="Chaiti Bhagwat";
        String HG13="Rucha Kalekar";
        String HG14="Smruti Pimplikar";
     
        String SPB11="Anuj Kankaria";
        String SPB12="Arnav Kholkar";
        String SPB13="Chinmay Patwardhan";
        String SPB14="Yogesh Sirvi";
     
        String SPG11="Disha Trivedi";
        String SPG12="Manasi Gokhale";
        String SPG13="Shivani Gupta";
        String SPG14="Shruti Jani";
     
        String C11="Shaunak Chitgopkar";
        String C12="Shivani Gupta";
        String C13="Smruti Pimplikar";
        String C14="Surinder Mathrani";
     
        String VC11="Arya Prabhudesai";
        String VC12="Atharva Mahajan";
        String VC13="Chinmay Kalluraya";
        String VC14="Manasi Deshpande";
     
        int HB1,HB2,HB3,HB4,HG1,HG2,HG3,HG4,SPB1,SPB2,SPB3,SPB4,SPG1,SPG2,SPG3,SPG4,C1,C2,C3,C4,VC1,VC2,VC3,VC4;
        int tie; //Variable that checks whether two or more candidates received the same number of votes. 
        Font font;   //Allows the message to be printed in a specific font 
        JButton H1,H2,H3,H4; //The buttons used for selecting the choice    
        JLabel label,title,HB,HG;
        Panel P1,P2,P3,P4; // area where the buttons can be displayed
        public void init() //Initialising Method for Applet
        {
            setLayout (new BorderLayout ());
            P1 = new Panel (new BorderLayout ());
            P2 = new Panel (); 
            P3 = new Panel ();
            P4 = new Panel ();
            font = new Font ("ComicSans", Font.BOLD, 17);
            setFont (font);
            this.setBackground(Color.yellow);
            label= new JLabel("Welcome to Vidya Valley School Elections");
            HB = new JLabel (HY);
            HG= new JLabel(HL);
            add (P1, "North");
            P1.add (P2, "North");
            P2.add (label);
            label.setForeground(Color.black);
            HB.setBackground(Color.white);
            HB.setForeground(Color.black);
            H1= new JButton (HB11);
            H1.addActionListener (this);
            H2= new JButton (HB12);
            H2.addActionListener (this);
            H3= new JButton (HB13);
            H3.addActionListener (this);
            H4= new JButton (HB14);
            H4.addActionListener (this);
            P1.add (P3,"West");
            P3.add (HB);
            P3.add (H1);
            P3.add (H2);
            P3.add (H3);
            P3.add (H4);
        }
     
        public void actionPerformed(ActionEvent e)
        {
            if (e.getActionCommand().equals(HB11)) 
            {
                System.out.println("Button1 has been clicked");
            }
        }
        // methods used for applet installment and destruction
        public void start() 
        {
            System.out.println(" Applet Starting ");
        }
     
        public void stop() 
        {
            System.out.println(" Applet Stopping ");
        }
     
        public void destroy() 
        {
            System.out.println(" Applet Destroyed ");
        }
     
    }

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Help with elections program

    Your println in the listener will only be called if the if statement is true. You are assuming you have coded the if correctly.

    Add a println statement first thing in the listener method without any if statements to prevent it being executed.
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Junior Member
    Join Date
    Dec 2012
    Posts
    15
    My Mood
    Inspired
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with elections program

    Quote Originally Posted by Norm View Post
    Your println in the listener will only be called if the if statement is true. You are assuming you have coded the if correctly.

    Add a println statement first thing in the listener method without any if statements to prevent it being executed.
    I am pretty sure the if statement is correct...
    If I add a println statement in the listener method nothing happens.
    Is this because I am viewing it in applet viewer?

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Help with elections program

    I use appletviewer for testing and get this output:
    Running: D:\Java\jdk1.6.0_29\bin\Appletviewer.exe D:\JavaDevelopment\Testing\ForumQuestions8\App1.ja va

    Applet Starting
    aP e=java.awt.event.ActionEvent[ACTION_PERFORMED,cmd=Arnav Kholkar,when=1355576656920,modifiers=Button1] on javax.swing.JButton[,63,5,114x26,alignmentX=0.0,alignmentY=0.5,border= javax.swing.plaf.BorderUIResource$CompoundBorderUI Resource@209f4e,flags=296,maximumSize=,minimumSize =,preferredSize=,defaultIcon=,disabledIcon=,disabl edSelectedIcon=,margin=javax.swing.plaf.InsetsUIRe source[top=2,left=14,bottom=2,right=14],paintBorder=true,paintFocus=true,pressedIcon=,rol loverEnabled=true,rolloverIcon=,rolloverSelectedIc on=,selectedIcon=,text=Arnav Kholkar,defaultCapable=true]
    AC=Arnav Kholkar HB11=Arnav Kholkar
    Button1 has been clicked
    aP e=java.awt.event.ActionEvent[ACTION_PERFORMED,cmd=Chinmay Patwardhan,when=1355576659408,modifiers=Button1] on javax.swing.JButton[,182,5,155x26,alignmentX=0.0,alignmentY=0.5,border =javax.swing.plaf.BorderUIResource$CompoundBorderU IResource@209f4e,flags=296,maximumSize=,minimumSiz e=,preferredSize=,defaultIcon=,disabledIcon=,disab ledSelectedIcon=,margin=javax.swing.plaf.InsetsUIR esource[top=2,left=14,bottom=2,right=14],paintBorder=true,paintFocus=true,pressedIcon=,rol loverEnabled=true,rolloverIcon=,rolloverSelectedIc on=,selectedIcon=,text=Chinmay Patwardhan,defaultCapable=true]
    AC=Chinmay Patwardhan HB11=Arnav Kholkar
    Applet Stopping
    Applet Destroyed

    0 error(s)
    What is printed on the console when you execute the applet?
    If you don't understand my answer, don't ignore it, ask a question.

  17. #17
    Junior Member
    Join Date
    Dec 2012
    Posts
    15
    My Mood
    Inspired
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Re: Help with elections program

    Quote Originally Posted by Norm View Post
    I use appletviewer for testing and get this output:

    What is printed on the console when you execute the applet?
    I am unable to see the screen of the console, it opens and closes instantly .....
    Based on what you get as an output..what should I do?

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Help with elections program

    it opens and closes instantly
    You need to change the way you are testing so that the console screen remains open so you can see the debug output.
    How are you executing the program?
    If you don't understand my answer, don't ignore it, ask a question.

  19. #19
    Junior Member
    Join Date
    Dec 2012
    Posts
    15
    My Mood
    Inspired
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Re: Help with elections program

    Quote Originally Posted by Norm View Post
    You need to change the way you are testing so that the console screen remains open so you can see the debug output.
    How are you executing the program?
    I simply view the applet and try to change the syntax if the program is not running.
    How should I execute the program?

  20. #20
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Help with elections program

    How do you execute the program you use to execute the applet?
    Why does the "screen of the console, it opens and closes instantly"?
    Please explain what you do step by step.
    If you don't understand my answer, don't ignore it, ask a question.

  21. #21
    Junior Member
    Join Date
    Dec 2012
    Posts
    15
    My Mood
    Inspired
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with elections program

    Quote Originally Posted by Norm View Post
    How do you execute the program you use to execute the applet?
    Why does the "screen of the console, it opens and closes instantly"?
    Please explain what you do step by step.
    The screen of the console opens and closes immediately...no idea.
    After compiling the code I run the applet. I make a note of what is being displayed and what is not.
    I add a code to see if the button is being clicked.
    If it works I try to design the rest of the program.
    I am having a bit of trouble with the syntax.

  22. #22
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Help with elections program

    The screen of the console opens and closes immediately
    Please explain in detail what you do to open the console.

    I run the applet.
    Please explain in detail what you do to "run the applet".
    If you don't understand my answer, don't ignore it, ask a question.

  23. #23
    Junior Member
    Join Date
    Dec 2012
    Posts
    15
    My Mood
    Inspired
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with elections program

    Quote Originally Posted by Norm View Post
    Please explain in detail what you do to open the console.


    Please explain in detail what you do to "run the applet".
    I use BlueJ and after compiling I run the applet by right-clicking the class.
    I go to My Computer/Java/Jdk/Bin/Java.consoleto open the console

  24. #24
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Help with elections program

    To keep the console open, get out of BLuej.
    open a command prompt console, issues commands to change to the folder with the html file that executes the applet and enter:

    appletviewer TheHtmlThatExecutesTheApplet.html

    When the appletviewer exits the command prompt window will still be open and you will be able to read what is displayed there.
    If you don't understand my answer, don't ignore it, ask a question.

  25. #25
    Junior Member
    Join Date
    Dec 2012
    Posts
    15
    My Mood
    Inspired
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with elections program

    Quote Originally Posted by Norm View Post
    To keep the console open, get out of BLuej.
    open a command prompt console, issues commands to change to the folder with the html file that executes the applet and enter:

    appletviewer TheHtmlThatExecutesTheApplet.html

    When the appletviewer exits the command prompt window will still be open and you will be able to read what is displayed there.
    Still not working

Page 1 of 2 12 LastLast

Similar Threads

  1. Program goes into infinite compilation. University project - Library Program.
    By clarky2006 in forum What's Wrong With My Code?
    Replies: 35
    Last Post: November 10th, 2012, 03:56 PM
  2. Replies: 1
    Last Post: July 8th, 2012, 10:23 AM
  3. how to run a java program..when the program using jar
    By miriyalasrihari in forum Java Theory & Questions
    Replies: 2
    Last Post: May 17th, 2012, 10:04 AM
  4. Program to launch and mirror another program
    By hayate in forum Java Theory & Questions
    Replies: 13
    Last Post: March 9th, 2012, 12:47 AM
  5. Help with class program!!! STUCK! Program not doing what I Want!!!
    By sketch_flygirl in forum What's Wrong With My Code?
    Replies: 7
    Last Post: April 4th, 2011, 07:29 AM