Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By Tolls

Thread: anonymous inner class

  1. #1
    harshit shah is offline Member
    Join Date
    Jan 2013
    Location
    Kolkata,India
    Posts
    86
    Rep Power
    0

    Post anonymous inner class

    Java Code:
    import javax.swing.*;//importing essential p[ackages
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.io.*;
    
    public class Admission
    {
        public static void main()
        {
            if(Login.success_of_login == 1) 
            {
                try//try-catch method
                {
                    Admission_2 frame=new Admission_2();
                    frame.setSize(1000,700);
                    frame.setLocation(250,100);
                    frame.setVisible(true);//showing frame
                }
                catch(Exception e)//exception handler
                {System.out.println("JAVA EXEPTION TRIGGERED.PLEASE CHECK FOR YOUR FAULTS");
                    System.out.println("FAULTS SUCH AS WRONG INPUTS, WRONG INPUT OR TYPE");
                }
            }
            else        System.out.println("PLEASE LOGIN");
        }
    }
    class Admission_2  extends JFrame 
    {
        JPanel panel;    JButton SUBMIT;//button for submitting data
        JLabel label1,label2,label3,label4,label5,label6,label7,label8,label9,label10,label11,label12,label13,label14,label15,label16,label17,label18,label19;
        JTextField  text2,text3,text4,text5,text6,text7,text8,text9,text10,text12,text13,text14,text15,text16,text17,text18,text19;
        public Admission_2()
        {
            label1 = new JLabel();
            label2 = new JLabel();
            label3 = new JLabel();
            label4 = new JLabel();
            label5 = new JLabel();
            label6 = new JLabel();
            label7 = new JLabel();
            label8 = new JLabel();
            label9 = new JLabel();
            label10 = new JLabel();
            label11 = new JLabel();
            label12 = new JLabel();
            label13 = new JLabel();
            label14 = new JLabel();
            label15 = new JLabel();
            label16 = new JLabel();
            label17 = new JLabel();
            label18 = new JLabel();
            label19 = new JLabel();
    
            label1.setText("DETAILS OF CHILD :");
            label1.setForeground(Color.red);
    
            label2.setText("Class in Which Admission Required");
            text2 = new JTextField(15);
    
            label3.setText("Student Name");
            text3 = new JTextField(50);
    
            label4.setText("Sex");
            text4 = new JTextField(6);
    
            label5.setText("Date of Birth");
            text5 = new JTextField(50);
    
            label6.setText("Nationality");
            text6 = new JTextField(50);
    
            label7.setText("Address");
            text7 = new JTextField(150);
    
            label8.setText("Mother Tongue");
            text8 = new JTextField(50);
    
            label9.setText("Identification Mark");
            text9 = new JTextField(500);
    
            label10.setText("Blood Group");
            text10 = new JTextField(3);
    
            label11.setText("PARENTAL DETAILS :");
            label11.setForeground(Color.red);
    
            label12.setText("Name");
            text12 = new JTextField(100);
    
            label13.setText("email");
            text13 = new JTextField(50);
    
            label14.setText("Qualification");
            text14 = new JTextField(100);
    
            label15.setText("Occupation");
            text15 = new JTextField(50);
    
            label16.setText("Income P/M");
            text16 = new JTextField(15);
    
            label17.setText("Office Address");
            text17 = new JTextField(150);
    
            label18.setText("Office Telephone No.");
            text18 = new JTextField(11);
    
            label19.setText("Religion");
            text19 = new JTextField(20);
    
            SUBMIT=new JButton("SUBMIT");
            panel=new JPanel(new GridLayout(38,2));
            panel.add(label1);
            panel.add(label2);
            panel.add(text2);
            panel.add(label3);
            panel.add(text3);
            panel.add(label4);
            panel.add(text4);
            panel.add(label5);
            panel.add(text5);
            panel.add(label6);
            panel.add(text6);
            panel.add(label7);
            panel.add(text7);
            panel.add(label8);
            panel.add(text8);
            panel.add(label9);
            panel.add(text9);
            panel.add(label10);
            panel.add(text10);
            panel.add(label11);
            panel.add(label12);
            panel.add(text12);
            panel.add(label13);
            panel.add(text13);
            panel.add(label14);
            panel.add(text14);
            panel.add(label15);
            panel.add(text15);
            panel.add(label16);
            panel.add(text16);
            panel.add(label17);
            panel.add(text17);
            panel.add(label18);
            panel.add(text18);
            panel.add(label19);
            panel.add(text19);
            panel.add(SUBMIT);
    
            SUBMIT.addActionListener(new ActionListener()
                {
                    public void actionPerformed(ActionEvent evt) 
                    {
                        JOptionPane.showMessageDialog(this,"login successful",
                            "SUCCESS!",JOptionPane.INFORMATION_MESSAGE);
                    }
                });
    
            add(panel,BorderLayout.CENTER); 
            panel.setVisible(true);
            panel.setBackground(Color.cyan);
            setTitle("ADMISSION FORM");
        }
    
    }
    I am using blueJ but it gives me an error message
    anonymous inner class-capture.jpg
    Can any body enlighten me on this topic.

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

    Default Re: anonymous inner class

    In your anonymous inner class 'this' refers to the ActionListener object, not the outer object.
    If you want the outer object (which I presume you do, as you need a Component or null) then you prefix it with the class name.
    Admission_2.this
    harshit shah likes this.
    Please do not ask for code as refusal often offends.

  3. #3
    harshit shah is offline Member
    Join Date
    Jan 2013
    Location
    Kolkata,India
    Posts
    86
    Rep Power
    0

    Default Re: anonymous inner class

    Quote Originally Posted by Tolls View Post
    In your anonymous inner class 'this' refers to the ActionListener object, not the outer object.
    If you want the outer object (which I presume you do, as you need a Component or null) then you prefix it with the class name.
    Admission_2.this
    thanks a lot.Can you please close this thread now.Reason=problem_solved

Similar Threads

  1. Replies: 15
    Last Post: 02-04-2012, 11:15 PM
  2. Issue in method anonymous class in GWT
    By ankit01 in forum GWT
    Replies: 0
    Last Post: 05-16-2011, 11:25 AM
  3. Replies: 2
    Last Post: 05-01-2010, 08:59 AM
  4. Name of Anonymous class
    By eva in forum New To Java
    Replies: 1
    Last Post: 12-31-2007, 01:07 PM
  5. Anonymous class
    By ravian in forum Advanced Java
    Replies: 3
    Last Post: 12-25-2007, 10:56 AM

Posting Permissions

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