import javax.swing.*; import java.awt.*; public class ButtonExample extends JFrame { JButton button; public ButtonExample() { button = new JButton("Click me!"); button.setMinimumSize(new Dimension(100, 50)); add(button); pack(); setVisible(true); } public static void main(String[] args) { new ButtonExample(); } }
import javax.swing.*; import java.awt.*; public class ButtonExample extends JFrame { JButton button1, button2, button3; public ButtonExample() { button1 = new JButton("Small"); button1.setMinimumSize(new Dimension(50, 25)); button2 = new JButton("Medium"); button2.setMinimumSize(new Dimension(100, 50)); button3 = new JButton("Large"); button3.setMinimumSize(new Dimension(150, 75)); JPanel panel = new JPanel(); panel.add(button1); panel.add(button2); panel.add(button3); add(panel); pack(); setVisible(true); } public static void main(String[] args) { new ButtonExample(); } }In this example, three JButtons are created with different minimum sizes using the setMinimumSize method. The buttons are then added to a JPanel, which is added to the JFrame. The pack method is again called to pack the components tightly together. Finally, the setVisible method is called to make the JFrame visible on the screen. Package/Library: java.awt - this is the AWT (Abstract Window Toolkit) package, which provides a set of classes for creating and manipulating GUI components.