Re: new Swing project
Arne Vajh=F8j wrote:
bob smith wrote:
What is the easiest way to start a new Swing project in Eclipse?
You prefer to write the code yourself => plain Java project.
You prefer GUI builder => install the plugin and then pick Swing projec=
t
type.
I have no evidence that this is the easiest way, but it's the way I first t=
ried
in response to this question:
- Open Eclipse.
- Menu: File New Project
- New project dialog: "Java Project" Next> (I have no Swing plugin)
- Project Name: "Whatever", "Use default location", Next>
- Finish
Context-menu click on project in "Package Explorer" window
- "New" > "Class"
- Package: "com.example.whatever"
- Name: "Example"
- Check "public static void main(String[] args)" and "Generate comments"
- Finish
You get:
/**
* Example.
*/
package com.example.whatever;
/**
* Example.
*
*/
public class Example {
/**
* main.
*
* @param args
*/
public static void main(String[] args) {
}
}
Then start adding Swingish stuff.
public class Example {
private static final String TITLE="Example Swing App";
static final Logger logger = Logger.getLogger(Example.class.getSimple=
Name());
private final JFrame appWindow = new JFrame(TITLE);
/**
* Constructor.
*/
public Example()
{
appWindow.pack();
}
/**
* Run the screen.
*/
public void run()
{
appWindow.setVisible(true);
}
/**
* main.
*
* @param args String array of arguments.
*/
public static void main(String[] args) {
logger.fine("main()");
Runnable gui = new Runnable()
{
@Override public void run()
{
new Example().run();
}
};
SwingUtilities.invokeLater(gui);
}
}
--
Lew