Super must be first statement in a constructor problem

Closed
zlloyd1 Posts 10 Registration date Tuesday December 11, 2012 Status Member Last seen February 4, 2013 - Dec 14, 2012 at 10:13 PM
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 - Dec 16, 2012 at 09:49 AM
Hello,
I have a problem that seems to be rearing up relentlessly on any code I write. The issue is when I try to use super(); in my programs. I always get this error:
"super must be first statement in a constructor", and it freaks me out, because I feel that it IS the first statement.
In any case, here is my latest run in with this issue, in code:

package dq2;   

import java.awt.*;   
import java.awt.event.*;   
import javax.swing.*;   
public class Dq2 extends JFrame implements ActionListener {   
       private JLabel titleLabel;   
       private JLabel messageLabel;   
        //menus for application   
       private JMenuBar menu_Bar ;   
       private JMenu file, hotels, entertainment, clubs;   
       private JMenuItem exit, circuscircus, luxor, cirquedusoleil, garthbrooks, pure, tao;   
      public void dq2(){   
              //setting the title of the frame   
              super("Fabulous Las Vegas");   ////HERE IS THE PROBLEM!!   
              //closing action for this frame   
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);   
             //set the layout to BorderLayout   
              setLayout(new BorderLayout());   
              titleLabel = new JLabel ("Welcome to Fabulous Las Vegas");   
              titleLabel.setFont(new Font("vardana", Font.BOLD, 24));   
       titleLabel.setHorizontalAlignment(JLabel.CENTER);   
       messageLabel = new JLabel ("Click topics for menu");   
       messageLabel.setFont(new Font("", Font.ITALIC, 16));   
       messageLabel.setHorizontalAlignment(JLabel.CENTER);   
       JPanel pane = new JPanel();   
       pane.add(titleLabel);   
       pane.add(messageLabel);   
       getContentPane().add(pane);   
               // Window menu bar   
              menu_Bar = new JMenuBar();   
               // Create File menu   
              file = new JMenu("File");   
              //adding file menu items   
              exit = file.add("Exit");   
              // Add the file menu   
              menu_Bar.add(file);   
              // Create rooms menu   
              hotels = new JMenu("Hotels");   
              //adding dining menu items   
              circuscircus = hotels.add("Circus Circus");   
              luxor = hotels.add("Luxor");   
              // Add the rooms menu   
              menu_Bar.add(hotels);   
              // Create dining menu   
              entertainment = new JMenu("Entertainment");   
              //adding dining menu items   
              cirquedusoleil = entertainment.add("Cirque Du Soleil");   
              garthbrooks = entertainment.add("Garth Brooks");   
              // Add the dining menu   
              menu_Bar.add(entertainment);   
              // Create activity menu   
              clubs = new JMenu("Clubs");   
              //adding activity menu items   
              pure = clubs.add("Pure");   
              tao = clubs.add("Tao");   
              // Add the activity menu   
              menu_Bar.add(clubs);   
              // Add the menu bar to the main frame   
              setJMenuBar(menu_Bar);   
              exit.addActionListener(this);   
              circuscircus.addActionListener(this);   
              luxor.addActionListener(this);   
              cirquedusoleil.addActionListener(this);   
              garthbrooks.addActionListener(this);   
              pure.addActionListener(this);   
              tao.addActionListener(this);   
              //set size of the frame   
              setSize(535,300);   
              setVisible(true);}   
       public void actionPerformed(ActionEvent ae) {   
         if(ae.getSource() == exit){   
                     int confirm = JOptionPane.showConfirmDialog(this, "What happens in Vegas, stays in Vegas?", "Exit?",    
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);   
            if(confirm  == JOptionPane.YES_OPTION)   
                System.exit(0);   
            else   
                return; }   
              else   
                     if(ae.getSource() == circuscircus){   
                           messageLabel.setText(" Welcomes You To Vegas Rooms Start @ Only $23! Book Today");}   
                     else   

                           if(ae.getSource() == luxor){   
                                  messageLabel.setText("Stay in royal accommodations in the heart of the Las Vegas Strip");}   
                           else   
                                  if(ae.getSource() == cirquedusoleil){   
                                         messageLabel.setText("Be mystified by the award winning, high-flying acrobatics");}   
                                  else   
                                         if(ae.getSource() == garthbrooks){   
                                                messageLabel.setText("Prepare to be dazzled by world-class entertainment");}   
                                         else   
                                                if(ae.getSource() == pure){   
                                                       messageLabel.setText("PURE symbolizes a new standard in Las Vegas nightlife");}   
                                                else   
                                                       if(ae.getSource() == tao){   
                                                              messageLabel.setText("The hottest nightlife attraction in Vegas!"); }}   
       public static void main(String args[]){   
              new Dq2(); }}    


Can someone PLEASE explain to me why this is coughing up an error??

Related:

1 response

rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
Dec 16, 2012 at 09:49 AM
I dont think you need a super call at all.
0