GUI Layout
This is my code:
import javax.swing.*;
import java.awt.*;
public class InputWindow extends JFrame
{
private JPanel panel = new JPanel();
private JButton inputButton = new JButton("Input");
private JLabel rainfallLabel = new JLabel("Rainfall: ");
private JLabel rainfallUnitLabel = new JLabel("mm");
private JLabel wheatLabel = new JLabel("Wheat Price: $");
private JLabel barleyLabel = new JLabel("Barley Price: $");
private JLabel sorghumLabel = new JLabel("Sorghum Price: $");
private JTextField enterRainfall = new JTextField(3);
private JTextField enterWheatPrice = new JTextField(3);
private JTextField enterBarleyPrice = new JTextField(3);
private JTextField enterSorghumPrice = new JTextField(3);
private final int WINDOW_WIDTH = 500;
private final int WINDOW_HEIGHT = 375;
public InputWindow()
{
super("DOTA Farming");
setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
buildPanel();
setVisible(true);
}
private void buildPanel()
{
add(panel);
addComponents(rainfallLabel, enterRainfall);
panel.add(rainfallUnitLabel);
addComponents(wheatLabel, enterWheatPrice);
addComponents(barleyLabel, enterBarleyPrice);
addComponents(sorghumLabel, enterSorghumPrice);
panel.add(inputButton);
}
private void addComponents(JLabel label, JTextField textField)
{
panel.add(label);
panel.add(textField);
}
}
How do I set the layout so that it appears this way:
label textField label
label textField
label textField
label textField
button

