Java Reference
In-Depth Information
an input component, by invoking Component 's void setEnabled(boolean
b) method with a false argument on the component instance, it no longer has the
Figure 7-4 reveals that all components have the same size, which results from
GridLayout ignoring a component's preferred size. The resulting GUI doesn't look
professional, but we can improve the GUI's appearance with a little bit of effort, as
demonstrated in Listing 7-2 .
Listing 7-2 . Improving TempVerter 's GUI
import java.awt.Button;
import java.awt.EventQueue;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.Panel;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
class TempVerter
static Panel createGUI()
Panel pnlLayout = new Panel();
pnlLayout.setLayout(new GridLayout(3, 1));
Panel pnlTemp = new Panel();
pnlTemp.add(new Label("Degrees"));
final TextField txtDegrees = new TextField(10);
pnlTemp = new Panel();
pnlTemp.add(new Label("result"));
final TextField txtResult = new TextField(30);
Search WWH ::

Custom Search