A tour of swing

 

b2 = new JButton("Click Me!");
b2.addActionListener(this);
cp.add(b2);
  • i1 = new ImageIcon("red-ball.gif");
    b3 = new JButton("Red-Ball",i1);
    b3.addActionListener(this);
    cp.add(b3);
  • b4 = new JButton();
    b4.addActionListener(this);
    b4.setText("OK");
    cp.add(b4);
  • }
  • public void actionPerformed(ActionEvent ae)
    {
    Object o;
    o = ae.getSource();
    if(o == b1)
    { t1.setText("Cyan-Ball is Clicked"); }
    else if(o == b2)
    { t1.setText("Button 2 is Clicked"); }
    else if(o == b3)
    { t1.setText("Red Ball is Clicked"); }
    else if(o == b4)
    { t1.setText(b4.getText()); }
  • }
  • }
  • Output:

  • JApplet Output

 

 

a tour of SWING by Mrs.s.sharmila banu & MRs.R.jayabharahti