I'm working on an applet that, in the end, will display a table for interest in a bank account. I'm am trying to go about gathering input from the user, by displaying a series of prompts, followed by text input boxes, and finally a button to trigger the clear, calculate, and display parts. I would like the prompts and buttons left justified , one set per line (but they're long enough so only 1 fits per line anyways) the problem the keeps occurring, is that try as I may, they keep showing up centered, both in my browser, and in the basic IDE my school uses. I currently have them in panels, but that's not required by me, it was just my last try. Id prefer them gone if possible. Either way, I figure I'm likely missing something, because I'm a noob to java still, and that maybe someone can spot why they are staying on the left like I want. Thanks.
And here's the section of code that's relevant, there's some more for output late, but its not quite ready yet, and I don't think it matters for this question anyways.
import java.applet.*; //imports req'd libraries
import java.awt.*;
public class AppletsExercise_2 extends Applet
{
Label promptDeposit, promptRate, promptStart, promptLast;
TextField inputDeposit, inputRate, inputStart, inputLast;
private Panel p1, p2, p3, p4;
int min = 1998;
int max = 2008;
public void init ()
{
p1 =new Panel(); //a bunch of nasty panels, my last attempt, but not at all preferred
p1.setLayout (new FlowLayout (FlowLayout.LEFT,20,10));
p2 =new Panel();
p2.setLayout (new FlowLayout (FlowLayout.LEFT,20,10));p1 =new Panel();
p3 = new Panel();
p3.setLayout (new FlowLayout (FlowLayout.LEFT,20,10));
p4 =new Panel();
p4.setLayout (new FlowLayout (FlowLayout.LEFT,20,10));
promptDeposit = new Label ("Enter the initial deposit: "); //creates labels for each of the fields
promptRate = new Label ("Enter the interest rate, in percent: ");
promptStart = new Label ("Enter the starting year: ");
promptLast = new Label ("Enter the number of years: ");
inputDeposit = new TextField (6); //creates each of the fields
inputRate = new TextField (2);
inputStart = new TextField (4);
inputLast = new TextField (4);
Button calculate = new Button ("Calculate");
p1.add(promptDeposit); //adds a prompt for each piece of info, followed by a text field for the user
p1.add(inputDeposit);
p2.add(promptRate);
p2.add(inputRate);
p3.add(promptStart);
p3.add(inputStart);
p4.add(promptLast);
p4.add(inputLast);
p1.add (calculate);
add("North", p1); //adds the stupid panels, top down
add("North", p2);
add("North", p3);
add("North", p4);
}
And finally, here's a picture of the current output, in Google Chrome https://i.stack.imgur.com/VGpov.jpg