JFrame pack()

The pack method packs the components within the window based on the component’s preferred sizes. Program       Program Source import javax.swing.JFrame; import javax.swing.JButton; import java.awt.FlowLayout; class Frame extends JFrame { void makeSizedFrame() { setTitle(“SetSize(700,200)”); setLayout(new FlowLayout()); setButton(); setSize(700, 200); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } void makepackFrame() { setTitle(“Withpack()”); setLayout(new FlowLayout()); setButton(); pack(); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } … Read more…

extends JFrame

The JFrame is a class like any other and can be extended. Program       Program Source import javax.swing.JFrame; class Frame extends JFrame{ Frame() { setTitle(“First java GUI application”); setSize(700, 200); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } public class Javaapp { public static void main(String[] args) { Frame frame = new Frame(); } }

Java-Swing

Swing The Swing package in Java enables the programmers to create Graphical User Interface applications. It contains a number of classes that help to implement Windows-based tasks, such as manipulating windows, adding scroll bars, buttons, list items, text boxes, etc. All the classes are contained in the javax.swing package. These classes are hierarchically arranged inside … Read more…