Wednesday, May 12, 2010

Plz tell me how to create control array for button in java?i tried codin.its showin exception in thread?

class ButtonDemo extends Panel implements ActionListener {


Panel panel1; Button[] buttons = new Button[3];


public void actionPerformed(ActionEvent ae) { String str = ae.getActionCommand();if(str.equals(';pre鈥?{ int i; for(i=0; i%26lt;3; i++){ buttons[i] = new Button(); panel1.add(buttons[i]); } }}}


public class Frame1 extends JFrame {


ButtonDemo button; private Panel panel1 = new Panel();


private XYLayout xYLayout1 = new XYLayout();


private Button button1 = new Button(';press';);


public Frame1() {


try { jbInit(); } catch (Exception e) {e.printStackTrace(); } }


private void jbInit() throws Exception {


this.getContentPane().setLayout( null ); this.setSize( new Dimension(400, 300) ); panel1.setBounds(new Rectangle(25, 50, 300, 175));


panel1.setLayout(xYLayout1); panel1.setBackground(new Color(25, 71, 245)); button=new ButtonDemo();panel1.add(button1, new XYConstraints(120, 5, 60, 20));button1.addActionListener(button); }}Plz tell me how to create control array for button in java?i tried codin.its showin exception in thread?
Hi.. its better you give the full coding so that we can identify where is the exact problem of your coding and why it is so ...





Try to add the main method in your Frame1 class..





public static void main(String args[])


{


Frame1 test = new Frame1();


}

No comments:

Post a Comment