tweety_bird_bunny
Journeyman
hi...
i am trying to write a program in java....the class uses ActionListener interface....
i have 2 create multiple jpanels so i created an array of jpanels.....
the array works fine in constructor....but as soon as as i try to use the panels of array in public void actionPerformed(ActionEvent ae)interface, the program compiles sucesfully but as soon as i click on the button when the program is runnning a huge list of errors comes in console....
plz help me to sort out the problem...
i'm pasting the code...
//start of code
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class MyFrame1 implements ActionListener
{
JFrame frame;
JPanel main,panel[];
JButton next,previous,endexam;
JLabel lab1,lab2,lab3,lab4,lab5;
public MyFrame1()
{
int i;
frame = new JFrame("Welcome to My Frame");
main = new JPanel();
JPanel panel[]=new JPanel[2];
for(i=0;i<2;i++)panel=new JPanel();
next = new JButton("Next");
previous = new JButton("Previous");
lab1 = new JLabel("Panel ONE");
lab2 = new JLabel("Panel TWO");
main.add(panel[0]);
main.add(panel[1]);
frame.getContentPane().add(main);
frame.setVisible(true);
frame.setSize(600,600);
panel[1].setVisible(false);
panel[0].add(lab1);
panel[0].add(next);
panel[0].add(previous);
next.addActionListener(this);
previous.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
JPanel panel[]=new JPanel[2];
String s = e.getActionCommand();
if ("Next".equals(s))
{
String str ="panel";
panel[0].setVisible(false);
panel[1].add(lab2);
panel[1].add(next);
panel[1].add(previous);
panel[1].setVisible(true);
}
if ("Previous".equals(s))
{
panel[0].setVisible(true);
panel[0].add(lab1);
panel[0].add(next);
panel[0].add(previous);
panel[1].setVisible(false);
}
}
public static void main(String[] args)
{
MyFrame1 my = new MyFrame1();
}
}
// end of code.....
also plz refer me some more interactive compiler for java(j2sdk)....i am bored with this whole console interface....
some gui cmpiler (eg devc++ for c....similarly refer me for java) which supports all the basic commands...
i am trying to write a program in java....the class uses ActionListener interface....
i have 2 create multiple jpanels so i created an array of jpanels.....
the array works fine in constructor....but as soon as as i try to use the panels of array in public void actionPerformed(ActionEvent ae)interface, the program compiles sucesfully but as soon as i click on the button when the program is runnning a huge list of errors comes in console....
plz help me to sort out the problem...
i'm pasting the code...
//start of code
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class MyFrame1 implements ActionListener
{
JFrame frame;
JPanel main,panel[];
JButton next,previous,endexam;
JLabel lab1,lab2,lab3,lab4,lab5;
public MyFrame1()
{
int i;
frame = new JFrame("Welcome to My Frame");
main = new JPanel();
JPanel panel[]=new JPanel[2];
for(i=0;i<2;i++)panel=new JPanel();
next = new JButton("Next");
previous = new JButton("Previous");
lab1 = new JLabel("Panel ONE");
lab2 = new JLabel("Panel TWO");
main.add(panel[0]);
main.add(panel[1]);
frame.getContentPane().add(main);
frame.setVisible(true);
frame.setSize(600,600);
panel[1].setVisible(false);
panel[0].add(lab1);
panel[0].add(next);
panel[0].add(previous);
next.addActionListener(this);
previous.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
JPanel panel[]=new JPanel[2];
String s = e.getActionCommand();
if ("Next".equals(s))
{
String str ="panel";
panel[0].setVisible(false);
panel[1].add(lab2);
panel[1].add(next);
panel[1].add(previous);
panel[1].setVisible(true);
}
if ("Previous".equals(s))
{
panel[0].setVisible(true);
panel[0].add(lab1);
panel[0].add(next);
panel[0].add(previous);
panel[1].setVisible(false);
}
}
public static void main(String[] args)
{
MyFrame1 my = new MyFrame1();
}
}
// end of code.....
also plz refer me some more interactive compiler for java(j2sdk)....i am bored with this whole console interface....
some gui cmpiler (eg devc++ for c....similarly refer me for java) which supports all the basic commands...