Java Reference
In-Depth Information
to fahrenheit");
btnConvertToFahrenheit.addActionListener(al);
pnlLayout.add(btnConvertToFahrenheit);
add(pnlLayout);
pack();
setResizable(false);
setVisible(true);
}
public static void main(String[] args)
{
Runnable r = new Runnable()
{
@Override
public void run()
{
new TempVerter();
}
};
EventQueue.invokeLater(r);
}
}
Followingseveralimportstatements, Listing7-1 presentsthetemperature-conversion
application's TempVerter class,whichextendsthe Frame classtodescribeaframe
window that displays the GUI.
TempVerter declares a noargument constructor for constructing the GUI. Its
main() methodinstantiates TempVerter andinvokesitsnoargumentconstructorto
create the GUI.
main() does not directly execute new TempVerter(); . Doing so would con-
struct the GUI on the main thread. Instead, main() defers GUI creation to a special
AWT thread known as the event-dispatch thread (EDT) . It does so by creating a
java.lang.Runnable instancewhose run() methodexecutes new TempVert-
er(); , and by passing this runnable to the java.awt.EventQueue class's void
invokeLater(Runnable runnable) classmethod,whichexecutestherunnable
on the EDT.
Search WWH ::




Custom Search