I'm finishing up a GUI program that'll act as an online ordering menu for a restuarant, however I seem to be having two problems.. My calculate handler method seems to just freeze the entire java applet. It doesnt show any error or anything as well it just freezes. heres the event handler:
ArrayList<Double> yourOrderPrices = new ArrayList<Double>();
ArrayList<String>yourOrderName = new ArrayList<String>();
ArrayList<String> specifications = new ArrayList<String>();
Iterator<Double> it1 = yourOrderPrices.iterator();
private void calcButtonActionPerformed(java.awt.event.ActionEvent evt) {
int x = 0;
double temp;
while(it1.hasNext()){
temp = yourOrderPrices.get(x);
orderTotal += temp;
}
subTotalLabel.setText("Sub Total: " + orderTotal);
totalPriceLabel.setText("Tax Rate: " + orderTotal / TAX_RATE);
totalPriceLabel.setText("Total: " + (orderTotal / TAX_RATE) + orderTotal);
//Reset Variable
orderTotal = 0;
}
Basically what this is supposed to do is calculate the sub total by adding all of the prices in the yourOrderPrices ArrayList, its supposed to divide by the tax rate and display it, and its supposed to add the tax rate for a Total Price. The variables inside are representing prices for food and are doubles. But everytime I press the button the entire program freezes.
Also, i'm trying to wrap the text in 2 textArea boxes, but everytime I try and call the method setLineWrap(true); it shows up on eclipse as not ablee to do that. Heres the two Text areas im trying to put it in:
detailTextArea.setEditable(false);
detailPanel.add(detailTextArea, java.awt.BorderLayout.CENTER);
and
orderTextArea.setEditable(false);
eastPanel.add(orderTextArea);
Use a for each instead.
double orderTotal = 0;
for(Double price : yourOrderPrices) {
orderTotal += price;
}
As for setLineWrap(true), exactly what does Eclipse say?
Solution: I installed java and Eclipse and tried it out by myself. I created a JTextArea and set the lineWrap to true and it works without complaints. Have you checked that you imported javax.swing.JTextArea and not something else?
My code for reference:
import javax.swing.JTextArea;
public class Main {
public static void main(String[] args) {
JTextArea area = new JTextArea();
area.setLineWrap(true);
}
}