import java.awt.*; import javax.swing.*; public class MyWindow extends JFrame { public MyWindow() { super("Title of window"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(400, 300); setVisible(true); } public static void main(String[] args) { new MyWindow(); } }
import java.awt.*; import javax.swing.*; public class MyButton extends JFrame { public MyButton() { super("Button Example"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(400, 300); JButton myButton = new JButton("Click Me!"); add(myButton); setVisible(true); } public static void main(String[] args) { new MyButton(); } }This program creates a JFrame window and adds a JButton component to it. When the button is clicked, it does not perform any action. Package library: javax.swing