Re: JFrame window dimensions
In article <i1dr8g$fr2$1@news.eternal-september.org>,
markspace <nospam@nowhere.com> wrote:
[...]
This is interesting, but "Temp" isn't really a great name for any
variable, let alone a class. Most things that are "run" on another
thread can be described as a "task." This task above creates a GUI,
so...
public class CreateGuiTask implements Runnable {
public static void main(String[] args) {
EventQueue.invokeLater(new CreateGuiTask());
}
@Override
public void run() {
// etc.
This is just a bit more readable, imo.
Much better! Alas, I am cursed with a heavy editorial hand, and "Test"
was the last thing I _hadn't_ changed. :-)
A correspondent prompted me to consider creating a template. At least,
NetBeans will require a different name, if not a good one.
import java.awt.Dimension;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
/** @author John B. Matthews */
public class ${name} extends JPanel implements Runnable {
public static void main(String[] args) {
EventQueue.invokeLater(new ${name}());
}
@Override
public void run() {
JFrame f = new JFrame("${name}");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(this);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
public ${name}() {
this.setPreferredSize(new Dimension(640, 480));
}
}
--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>