import java.awt.*; import javax.swing.*; public class ButtonExample extends JFrame { public ButtonExample() { JButton saveButton = new JButton("Save"); saveButton.setMnemonic('S'); add(saveButton); setSize(200, 100); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); } public static void main(String[] args) { new ButtonExample(); } }
import java.awt.*; import javax.swing.*; public class ButtonExample extends JFrame { public ButtonExample() { JButton okButton = new JButton("OK"); okButton.setMnemonic('O'); JButton cancelButton = new JButton("Cancel"); cancelButton.setMnemonic('C'); JPanel panel = new JPanel(); panel.add(okButton); panel.add(cancelButton); add(panel); setSize(200, 100); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); } public static void main(String[] args) { new ButtonExample(); } }Package library: java.awt