source file name: ButtonImageDemo.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class ButtonImageDemo extends JFrame
{
ImageIcon cen=new ImageIcon("center.png");
ImageIcon east=new ImageIcon("east.jpg");
ImageIcon west=new ImageIcon("west.jpg");
ImageIcon north=new ImageIcon("north.jpg");
ImageIcon south=new ImageIcon("south.jpg");
public static void main (String ob[])
{
ButtonImageDemo f=new ButtonImageDemo();
f.setTitle(" Swing Button Images Program");
f.setSize(300,400);
f.setVisible(true);
}
public ButtonImageDemo()
{
FlowLayout fl=new FlowLayout();
setLayout(fl);
JButton b1=new JButton(north);
JButton b2=new JButton(east);
JButton b3=new JButton(cen);
JButton b4=new JButton(west);
JButton b5=new JButton(south);
add(b1);add(b2);add(b3);
add(b4);add(b5);
}
}
output:
0 Comments
Post a Comment