0

I'm newby in AWT and I've got some questions. How move text fields to the left? How to move second text field to next line? This is my init():

public void init() {
        setSize(500, 200);
        encode = new Button("Encode");
        Label valueL = new Label("Text:");
        Label codeLabel = new Label("Crypt:");
        text = new TextField(12);
        codeField = new TextField(12);
        add(valueL);
        add(text);
        add(encode);
        add(codeLabel);
        add(codeField);
        text.addActionListener(this);
        encode.addActionListener(this);
    }
Tony
  • 3,605
  • 14
  • 52
  • 84
  • 1
    Why not use the newer Swing? – Reimeus Oct 03 '13 at 17:23
  • I use AWT for academic purposes. – Tony Oct 03 '13 at 17:25
  • You must use layout managers: http://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html Other link: http://journals.ecs.soton.ac.uk/java/tutorial/ui/layout/index.html – angel_navarro Oct 03 '13 at 17:25
  • 1
    Does 'academic purposes' mean the prof. specified AWT components? I ask because for *learning purposes*, it would be far more optimal to teach Swing components. Many of the people who ever used AWT components have not used them for so long that they forget the details. As a result, most current info. on AWT is flawed, and the old information is obsolescent (e.g. using deprecated methods). – Andrew Thompson Oct 04 '13 at 00:43

2 Answers2

1

You must use layout managers. Some usefull links:

docs.oracle.com/javase/tutorial/uiswing/layout/visual.html

journals.ecs.soton.ac.uk/java/tutorial/ui/layout/index.html

angel_navarro
  • 1,757
  • 10
  • 11
1

Use JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT)); to create a new JPanel.

Add you elements to the new JPanel like so.

panel.add(text); panel.add(codeField);

also see:

How can I align all elements to the left in JPanel?

Community
  • 1
  • 1
CCD
  • 470
  • 1
  • 7
  • 19