Skip to content

Instantly share code, notes, and snippets.

@zzorn
Created August 9, 2013 13:03
Show Gist options
  • Select an option

  • Save zzorn/6193462 to your computer and use it in GitHub Desktop.

Select an option

Save zzorn/6193462 to your computer and use it in GitHub Desktop.
SimpleFrame
import javax.swing.*;
import java.awt.*;
/**
* A Swing JFrame with sensible default settings.
*/
public class SimpleFrame extends JFrame {
private static final int DEFAULT_WIDTH = 800;
private static final int DEFAULT_HEIGHT = 600;
public SimpleFrame() {
this("", null);
}
public SimpleFrame(String title) {
this(title, null);
}
public SimpleFrame(String title, JComponent content) {
this(title, content, DEFAULT_WIDTH, DEFAULT_HEIGHT);
}
public SimpleFrame(String title, JComponent content, int initialWidth, int initialHeight) {
setTitle(title);
if (content != null) setContentPane(content);
setPreferredSize(new Dimension(initialWidth, initialHeight));
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
pack();
setVisible(true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment