JFrame class เป็น subclass ของ Frame components ที่เพิ่มเข้า frame เรียกว่า contents จัดการโดย contentPane JFrame มี window พร้อม title, border, (optional) menu bar และ user-specific components โดย default minimize JFrame ด้วยปุ่ม minimize และ maximize ด้วยปุ่ม maximize ที่มุมขวาบน สามารถทำโดยโปรแกรมได้ด้วย setState(JFrame.ICONIFIED) minimize และ setExtendedState(JFrame.MAXIMIZED_BOTH) maximize
ตัวอย่าง
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class JFrameIconifiedTest extends JFrame implements ActionListener {
private JButton iconifyButton, maximizeButton;
public JFrameIconifiedTest() {
setTitle("JFrameIconified Test");
iconifyButton = new JButton("JFrame Iconified");
add(iconifyButton, BorderLayout.NORTH);
iconifyButton.addActionListener(this);
maximizeButton = new JButton("JFrame Maximized");
add(maximizeButton, BorderLayout.SOUTH);
maximizeButton.addActionListener(this);
setSize(400, 275);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
}
public void actionPerformed(ActionEvent ae) {
if (ae.getSource().equals(iconifyButton)) {
setState(JFrame.ICONIFIED); // Minimize frame
} else if (ae.getSource().equals(maximizeButton)) {
setExtendedState(JFrame.MAXIMIZED_BOTH); // Maximize frame
}
}
public static void main(String args[]) {
new JFrameIconifiedTest();
}
}
Output

ในโปรแกรมข้างต้น หากคลิกปุ่ม "JFrame Iconified" frame จะ minimized คลิก "JFrame Maximized" frame จะ maximized