import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.KeyEvent;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
public class ButtonSample {
public static void main(String args[]) {
String title = "JButton Sample";
JFrame frame = new JFrame(title);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container content = frame.getContentPane();
content.setLayout(new GridLayout(2, 2));
JButton button1 = new JButton("Text Button");
button1.setMnemonic(KeyEvent.VK_B);
content.add(button1);
Icon warnIcon = new ImageIcon("Warn.gif");
JButton button2 = new JButton(warnIcon);
content.add(button2);
JButton button3 = new JButton("Warning", warnIcon);
content.add(button3);
String htmlButton = "<html><sup>HTML</sup> <sub><em>Button</em></sub><br>" +
"<font color=\"#FF0080\"><u>Multi-line</u></font>";
JButton button4 = new JButton(htmlButton);
content.add(button4);
frame.setSize(300, 200);
frame.setVisible(true);
}
}
|