Results 1 to 5 of 5
  1. #1
    r.srimathi is offline Member
    Join Date
    Jan 2009
    Posts
    4
    Rep Power
    0

    Default interface in swings

    Thank you
    i know interface concept but the interface is not working while it is used in swings .That is my doubt.
    If i used in java its working. But in my program its throwing arrayindexoutofbounds exception.
    I have quoted the important things in red please see this and clear my doubt

    This is my where i am declaring a method which going to be called b using interface conceptimport java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.*;
    import java.lang.*;

    public class test extends JFrame implements ActionListener,iest
    {

    private static final long serialVersionUID = 1L;
    JButton b,b1,b2,b3;
    JLabel l[],l1,l3,l4,l5,l6,l7;
    Font f,f1;
    JTextField t[],t1[],t2[],t3[],t4[],t5[],t6;
    Container c;
    int row[],col[],i,col1[];
    float m,k,z[] ;
    float n,p,q,r,s;
    int d;
    int ver,hor;
    JScrollPane bar;

    public test(int a)
    {
    super("AREA OF THE POOJA ROOM");

    b=new JButton("OK");
    b.addActionListener(this);
    b.setBounds(100, 500, 80, 30);
    b1=new JButton("CLEAR DATA");
    b1.addActionListener(this);
    b1.setBounds(210, 500, 120, 30);
    b2=new JButton("BACK");
    b2.addActionListener(this);
    b2.setBounds(340, 500, 80, 30);


    f=new Font("CopperBlack",Font.BOLD,13);
    f1=new Font("CopperBlack",Font.BOLD,11);
    l1=new JLabel("LENGTH (in SFT)");
    l1.setFont(f);
    l3=new JLabel("BREADTH (in SFT)");
    l3.setFont(f);
    l4=new JLabel("AREA (in SFT)");
    l4.setFont(f);
    l5=new JLabel("FEET IN");
    l5.setFont(f1);
    l6=new JLabel("FEET IN");
    l6.setFont(f1);
    l7=new JLabel(" FEET");
    l7.setFont(f1);

    c = getContentPane();
    c.setLayout(null);
    c.setBackground(Color.lightGray);
    c.setForeground(Color.black);

    t=new JTextField[10];
    l=new JLabel[10];
    t1=new JTextField[10];
    t2=new JTextField[10];
    t3=new JTextField[10];
    t4=new JTextField[10];
    t6=new JTextField(10);

    c.add(l1);
    c.add(l4);
    c.add(l3);
    c.add(l5);
    c.add(l6);
    c.add(l7);
    c.add(b);
    c.add(b1);
    c.add(b2);

    l1.setBounds(320, 10, 130, 50);
    l3.setBounds(450, 10, 130, 50);
    l4.setBounds(580, 10, 100, 50);
    l5.setBounds(345, 25, 100, 50);
    l6.setBounds(475, 25, 100, 50);
    l7.setBounds(605, 25, 100, 50);

    int col=60;
    int col1=60;

    d=a;
    for(i=1;i<=d;i++)
    {

    int row=40;

    l[i] = new JLabel("ENTER THE LENGTH & BREADTH FOR POOJA ROOM "+i);
    l[i].setBounds(row,col,350,30);
    c.add(l[i]);

    row=row+300;
    t[i]=new JTextField();
    c.add(t[i]);
    t[i].setBounds(row,col1,30,30);


    row=row+30;
    t1[i]=new JTextField();
    c.add(t1[i]);
    t1[i].setBounds(row,col1,30,30);

    row=row+100;
    t2[i]=new JTextField();
    c.add(t2[i]);
    t2[i].setBounds(row,col1,30,30);


    row=row+30;
    t3[i]=new JTextField();
    c.add(t3[i]);
    t3[i].setBounds(row,col1,30,30);

    row=row+100;
    t4[i]=new JTextField();
    c.add(t4[i]);
    t4[i].setBounds(row,col1,70,30);


    col=col+70;
    col1=col1+70;
    }


    setSize(800, 800);
    setVisible(true);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }

    public void actionPerformed(ActionEvent ae)
    {

    if(ae.getSource()==b)
    {

    for (int i = 1; i <=d; i++)
    {
    z=new float[10];
    try
    {
    m= Integer.parseInt(t[i].getText());
    n= Integer.parseInt(t1[i].getText());
    n=n/12;
    k=m+n;
    p= Integer.parseInt(t2[i].getText());
    q= Integer.parseInt(t3[i].getText());
    q=q/12;
    r=p+q;
    s=k*r;
    t4[i].setText(" "+s);
    z[i]=s;
    }
    catch (Exception err)
    {
    System.out.println("test"+err);
    }
    }

    }
    if(ae.getSource()==b2)
    {
    new est2();
    }
    if(ae.getSource()==b1)
    {
    new est5(d,z);
    }
    }
    public void pass()
    {
    System.out.println("test");
    }}

    This is my interface

    public interface iest
    {
    void pass();
    }

    here i am calling pass method

    import javax.swing.*;
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;

    public class iest1
    {
    public static void main(String args[])
    {

    iest obe = new test(' ');
    obe.pass();
    }
    }

    Once again thank you

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    This seems to be an unnecessary duplicate post of a currently active thread: Interface concept

    I vote that we keep all responses in the other active thread and let this thread die a natural death.

  3. #3
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    8

    Default

    How about System.exit(1);

  4. #4
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    Can you post the full exception error?

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Drawing charts using swings
    By ravindarjobs in forum New To Java
    Replies: 19
    Last Post: 07-22-2009, 12:03 AM
  2. How to use multiple timer classes in swings
    By theone3nu in forum AWT / Swing
    Replies: 12
    Last Post: 12-30-2008, 03:30 AM
  3. awt and swings
    By masa in forum AWT / Swing
    Replies: 2
    Last Post: 11-24-2008, 08:09 AM
  4. Printing Tree Structure using Swings
    By pradeep1_mca@yahoo.com in forum AWT / Swing
    Replies: 5
    Last Post: 08-30-2008, 02:54 PM
  5. java swings
    By emperoraj in forum AWT / Swing
    Replies: 0
    Last Post: 03-26-2008, 12:50 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
  •