| |
14. 5. 13. Button icons, a default button, HTML in a button,and button mnemonics. |
|
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Main {
public static void main(String args[]) {
ImageIcon iconA = new ImageIcon("IconA.gif");
ImageIcon iconDiable = new ImageIcon("disable.gif");
ImageIcon iconOver = new ImageIcon("over.gif");
ImageIcon iconPressed = new ImageIcon("IconAPressed.gif");
final JButton jbtnA = new JButton("Alpha", iconA);
JFrame jfrm = new JFrame();
jfrm.setLayout(new FlowLayout());
jfrm.setSize(300, 300);
jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jbtnA.setRolloverIcon(iconOver);
jbtnA.setPressedIcon(iconPressed);
jbtnA.setDisabledIcon(iconDiable);
jfrm.getRootPane().setDefaultButton(jbtnA);
jbtnA.setMnemonic(KeyEvent.VK_A);
jbtnA.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
System.out.println("Alpha pressed. Beta is enabled.");
jbtnA.setEnabled(!jbtnA.isEnabled());
}
});
jfrm.add(jbtnA);
jfrm.setVisible(true);
}
}
|
|
|