Why wont the Button wrap?
Hi,
Working on an assignment and everything is going great until I notice that the Button is not wrapping. What am I missing that can help me move this thing down?
Thanks,
Taylor
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class KilowattApplet extends Applet implements ActionListener
{
//component constructor
Label welcome = new Label("Welcome to the Appliance Energy Calculator");
Label costKwhrLabel = new Label("Please enter the cost per kilowatt-hour in cents:");
TextField costKwhrField = new TextField(5);
Label hoursPerYearLabel = new Label("Please enter the kilowatt-hours consumed:");
TextField hoursPerYearField = new TextField(5);
Button calcButton = new Button("Calculate");
Label outputLabel = new Label("Click the Calculate button to display the average energy cost.");
public void init()
{
add(welcome);
add(costKwhrLabel);
add(costKwhrField);
add(hoursPerYearLabel);
add(hoursPerYearField);
add(calcButton); // *This button prints on the same line as the previous line of code "add(hoursPerYearField)"*
calcButton.addActionListener(this);
add(outputLabel);
}
public void actionPerformed(ActionEvent e)
{
double costKwhr = Double.parseDouble(costKwhrField.getText());
double kwHours = Double.parseDouble(hoursPerYearField.getText());
double average = costKwhr*kwHours;
outputLabel.setText("The average annual cost to operate this appliance is $" + Math.round(average*100)/100D);
}
}
Re: Why wont the Button wrap?
Quote:
the Button is not wrapping
Can you explain what what you mean by wrapping a Button?
Re: Why wont the Button wrap?
By wrapping I mean returning to the next line. I want the Button to display on the line UNDER the Label I have created not and the same line. I hope I explained well.
Thanks,
Taylor
Re: Why wont the Button wrap?
The position of components in a container in your GUI is controlled by the layout manager.
Which layout manager are you using? It looks like the flow layout manager.
If you want to align components other than having them flow left to right and wrap at the end, you need to read up on layout managers and see which one will format your components the way you want them to appear.
You can get some changes by changing the width= attribute in the <APPLET tag.
Re: Why wont the Button wrap?