//jTobbleButton with JToolBar
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class jf0005 extends JFrame implements ActionListener
{
JToggleButton jt1,jt2,jt3,jt4,jt5;
JPanel pane;
JToolBar jtb;
JTextField jtf1;
String st;
public jf0005()
{
super("JToggle button");
setSize(300,200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
st=new String();
jt1=new JToggleButton("B");
jtf1=new JTextField("B(off)I(off)U(off)A(off)K(off)",33);
jt2=new JToggleButton("I");
jt3=new JToggleButton("U");
jt4=new JToggleButton("A");
jt5=new JToggleButton("K");
jtf1=new JTextField();
jtb=new JToolBar();
jtb.add(jt1);
jtb.add(jt2);
jtb.add(jt3);
jtb.add(jt4);
jtb.add(jt5);
jt1.addActionListener(this);
jt2.addActionListener(this);
jt3.addActionListener(this);
jt4.addActionListener(this);
jt5.addActionListener(this);
pane=new JPanel();
pane.setLayout(new BorderLayout());
pane.add("Center",jtf1);
pane.add("North",jtb);
setContentPane(pane);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
st="";
if(jt1.isSelected())
st=st+"B(on)";
else
st=st+"B(off)";
if(jt2.isSelected())
st=st+"I(on)";
else
st=st+"I(off)";
if(jt3.isSelected())
st=st+"U(on)";
else
st=st+"U(off)";
if(jt4.isSelected())
st=st+"A(on)";
else
st=st+"A(off)";
if(jt5.isSelected())
st=st+"K(on)";
else
st=st+"K(off)";
jtf1.setText(st);
}
public static void main(String args[])
{
jf0005 a=new jf0005 ();
}
}
No comments:
Post a Comment