import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class MnemonicTest extends JFrame implements ActionListener
{
JPanel pane;
JButton jb1,jb2,jb3;
JTextField jtf1;
public MnemonicTest()
{
super("Testing buttons");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(300,200);
jb1=new JButton("Display");
jb2=new JButton("Print");
jb3=new JButton("Sign up");
jb1.setMnemonic('D');
jb2.setMnemonic('P');
jb3.setMnemonic('S');
jtf1=new JTextField(15);
pane=new JPanel();
pane.add(jb1);
pane.add(jb2);
pane.add(jb3);
pane.add(jtf1);
setContentPane(pane);
setVisible(true);
jb1.addActionListener(this);
jb2.addActionListener(this);
jb3.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==jb1)
jtf1.setText("Display click");
if(e.getSource()==jb2)
jtf1.setText("Print click");
if(e.getSource()==jb3)
jtf1.setText("Sign up click");
}
public static void main(String args[])
{
MnemonicTest one=new MnemonicTest();
}
}
No comments:
Post a Comment