5 Replies - 1576 Views - Last Post: 07 December 2012 - 12:14 PM Rate Topic: -----

#1 JPcreator  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 06-December 12

JPizza.java issue

Posted 06 December 2012 - 08:56 PM

I'm creating an application where I give the user the option of ordering pizza.


import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.ListSelectionModel;

public class JPizza extends JFrame
{

private JLabel sizeLabel;
private JLabel toppingsLabel;
private JLabel priceLabel;
private JTextField priceTextField;
private JButton calculateButton;
private JList sizeList;
private JList toppingList;


private JList sizeJList;
private static final String[] pizzaSizes = {"Small ($7)", "Medium ($9)",
"Large ($11)", "Extra Large ($14) "};
private static final Integer[] sizePrice = {7,9,11,14};

private JList toppingsJList;
private static final String[] pizzaToppings = {"Cheese ($0)", "Pepperoni ($1)",
"Mushrooms ($1)", "Peppers ($1)", "Olives ($1)"};
private static final Integer[] toppingsPrice = {0,1,1,1,1};

public JPizza()
{
setLayout( new FlowLayout() ); // set frame layout

sizeLabel = new JLabel("Choose Pizza Size");
add(sizeLabel);

sizeJList = new JList (pizzaSizes);
sizeJList.setVisibleRowCount(4); // display 4 rows at once
sizeJList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // do not allow multiple selection
add(new JScrollPane(sizeJList));

sizeJList.addListSelectionListener();
new ListSelectionListener()
{
public void valueChanged( ListSelectionEvent event)
{
priceTextField.(sizePrice[sizeJList.getSelectedIndex()]);
}
;}
toppingsLabel = new JLabel ("Choose Pizza Toppings");
add( toppingsLabel);

toppingsJList = new JList (pizzaToppings);
toppingsJList.setVisibleRowCount(5);
toppingsJList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
add(new JScrollPane(toppingsJList));

priceLabel = new JLabel ("The price is:");
add(priceLabel);

priceTextField = new JTextField("", 4);
priceTextField.setEditable(false);
add(priceTextField);

calculateButton = new JButton ("Calculate Price");
add (calculateButton);
}
}


My only issue is this "priceTextField.(sizePrice[sizeJList.getSelectedIndex()]);}
;}" I have only one error and I get "Error<Identified>expected" I've been trying to figure what do I need to do in order to get this fix.

This post has been edited by Atli: 06 December 2012 - 09:01 PM
Reason for edit:: Use [code] tags when posting code.


Is This A Good Question/Topic? 0
  • +

Replies To: JPizza.java issue

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8334
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: JPizza.java issue

Posted 06 December 2012 - 09:16 PM

priceTextField.(sizePrice[sizeJList.getSelectedIndex()]);

ouf....
ok assuming priceTextField is a JTextField there is no Java syntax taht allows

jtextField.( <---

sizePrice being an array of double[] getSelectedIndex returning a int we have

priceTextField.(123456);

what are you trying to do here ?
Was This Post Helpful? 0
  • +
  • -

#3 JPcreator  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 06-December 12

Re: JPizza.java issue

Posted 06 December 2012 - 09:50 PM

View Postpbl, on 06 December 2012 - 09:16 PM, said:

priceTextField.(sizePrice[sizeJList.getSelectedIndex()]);

ouf....
ok assuming priceTextField is a JTextField there is no Java syntax taht allows

jtextField.( <---

sizePrice being an array of double[] getSelectedIndex returning a int we have

priceTextField.(123456);

what are you trying to do here ?

I'm displaying the price after you choose your pizza size, topping then price of the pizza depending on size. No charge for cheese.
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8334
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: JPizza.java issue

Posted 06 December 2012 - 09:57 PM

Let's rephrase the whole thing

You do:
JTextField x = new JTextField();
x.(123456); <--- this Java instruction is supposed to to what... you think ?
assuming that this instruction is a valid Java syntax
Was This Post Helpful? 0
  • +
  • -

#5 JPcreator  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 06-December 12

Re: JPizza.java issue

Posted 07 December 2012 - 11:57 AM

YES!! it's almost done but now I have this problem and I'm finish.

JTextField x = new JTextField();
}
;}<---

This is a strange one because I kept getting "error ';' expected" even though I put it there it still say that I have an error.
Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8334
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: JPizza.java issue

Posted 07 December 2012 - 12:14 PM

INDENT your updated post correctly and repost it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1