FileDocCategorySizeDatePackage
GoToPage.javaAPI DocExample1395Sat Nov 25 12:55:14 GMT 2000None

GoToPage

public class GoToPage extends Dialog
Implement a simple "Go To Page" dialog Row one: "Go to Page", textfield second OK, Cancel buttons.

Fields Summary
protected TextField
tf
TextField used to enter the number
protected JButton
ok
The OK button
protected JButton
can
The cancel button
Constructors Summary
public GoToPage(JFrame f, String title)
Construct a GoToPage window (no actions yet)

		super(f);
		setTitle(title);

		Label l = new Label("Page Number:");
		tf = new TextField(4);
		tf.setText("1");
		// set the text initially selected so you can easily overtype it
		tf.selectAll();

		ok = new JButton("OK");
		can = new JButton("Cancel");

		Panel top = new Panel();
		top.add(l);
		top.add(tf);

		Panel bottom = new Panel();
		bottom.add(ok);
		bottom.add(can);

		add(BorderLayout.NORTH, top);
		add(BorderLayout.SOUTH, bottom);

		pack();
	
Methods Summary
protected intgetValue()

		int i = Integer.parseInt(tf.getText());
		return i;
	
public static voidmain(java.lang.String[] unused)

		final JFrame f = new JFrame("Page Dialog Test");
		JButton b;
		f.getContentPane().add(b = new JButton("Show Dialog"));
		b.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				new GoToPage(f, "GoToPage Demo").setVisible(true);
			}
		});
		f.pack();
		f.setVisible(true);