Results 1 to 11 of 11
- 04-12-2012, 11:38 PM #1
Member
- Join Date
- Apr 2012
- Posts
- 7
- Rep Power
- 0
Problem with App, used a template, not working correctly.
Hello,
Im having a problem with my second Applet for my java programming class. The professor gave out a template sheet to use as a reference and I filled in everything as needed to produce the program. It just isnt working correctly.
Thank you for any help or advice. -.gif)
It should look like this:

and heres the code:
____________________________________
Java Code:import javax.swing.*; import java.awt.*; import java.awt.event.*; import javax.swing.border.*; import java.text.*; public class Assignment8 extends JFrame implements ActionListener, ItemListener { double sPrice = 6.99, mPrice = 8.99, lPrice = 10.99; double totalPrice = sPrice; ButtonGroup sizeGrp = new ButtonGroup(); JRadioButton sRB = new JRadioButton("Small",true); JRadioButton mRB = new JRadioButton("Medium",false); JRadioButton lRB = new JRadioButton("Large",false); double sausagePrice = 1.49, pepperoniPrice = 1.49, salamiPrice = 1.49, olivesPrice = 0.99, mushroomsPrice = 0.99, anchoviesPrice = 0.99; JCheckBox sausageBox = new JCheckBox("Sausage",false); JCheckBox pepperoniBox = new JCheckBox("Pepperoni",false); JCheckBox salamiBox = new JCheckBox("Salami",false); JCheckBox olivesBox = new JCheckBox("Olives",false); JCheckBox mushroomsBox = new JCheckBox("Mushrooms",false); JCheckBox anchoviesBox = new JCheckBox("Anchovies",false); JButton exit = new JButton("Exit"); JPanel topPanel = new JPanel(new FlowLayout()); JPanel middlePanel = new JPanel(new FlowLayout()); JPanel bottomPanel = new JPanel(new FlowLayout()); JTextField totPrice = new JTextField(10); Container con = getContentPane(); NumberFormat currency = NumberFormat.getCurrencyInstance(); public Assignment8() { super("Pizza Calculator"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); con.setLayout(new BorderLayout()); sizeGrp.add(sRB); sRB.addItemListener(this); sizeGrp.add(mRB); mRB.addItemListener(this); sizeGrp.add(lRB); lRB.addItemListener(this); Border topBorder = BorderFactory.createEtchedBorder(); topBorder = BorderFactory.createTitledBorder(topBorder,"Size"); topPanel.add(sRB); topPanel.add(mRB); topPanel.add(lRB); Border middleBorder = BorderFactory.createEtchedBorder(); middleBorder = BorderFactory.createTitledBorder(middleBorder,"Toppings"); middlePanel.add(sausageBox); middlePanel.add(pepperoniBox); middlePanel.add(salamiBox); middlePanel.add(olivesBox); middlePanel.add(mushroomsBox); middlePanel.add(anchoviesBox); Border bottomBorder = BorderFactory.createEtchedBorder(); bottomBorder = BorderFactory.createTitledBorder(bottomBorder); totPrice.setText(currency.format(totalPrice)); bottomPanel.add(totPrice); bottomPanel.add(exit); exit.addActionListener(this); con.add(bottomPanel, BorderLayout.SOUTH); } public static void main(String[] arguments) { Assignment8 aFrame = new Assignment8(); aFrame.setSize(450,225); aFrame.setResizable(false); aFrame.setVisible(true); } public void itemStateChanged(ItemEvent check) { Object source = check.getItem(); if(source == sRB) { int select = check.getStateChange(); if(select == ItemEvent.SELECTED) totalPrice += sPrice; else if(select == ItemEvent.DESELECTED) totalPrice -= sPrice; } if(source == mRB) { int select = check.getStateChange(); if(select == ItemEvent.SELECTED) totalPrice += mPrice; else if(select == ItemEvent.DESELECTED) totalPrice -= mPrice; } if(source == sausageBox) { int select = check.getStateChange(); if(select == ItemEvent.SELECTED) totalPrice += sausagePrice; else if(select == ItemEvent.DESELECTED) totalPrice -= sausagePrice; } if(source == pepperoniBox) { int select = check.getStateChange(); if(select == ItemEvent.SELECTED) totalPrice += pepperoniPrice; else if(select == ItemEvent.DESELECTED) totalPrice -= pepperoniPrice; } if(source == salamiBox) { int select = check.getStateChange(); if(select == ItemEvent.SELECTED) totalPrice += salamiPrice; else if(select == ItemEvent.DESELECTED) totalPrice -= salamiPrice; } if(source == olivesBox) { int select = check.getStateChange(); if(select == ItemEvent.SELECTED) totalPrice += olivesPrice; else if(select == ItemEvent.DESELECTED) totalPrice -= olivesPrice; } if(source == mushroomsBox) { int select = check.getStateChange(); if(select == ItemEvent.SELECTED) totalPrice += mushroomsPrice; else if(select == ItemEvent.DESELECTED) totalPrice -= mushroomsPrice; } if(source == anchoviesBox) { int select = check.getStateChange(); if(select == ItemEvent.SELECTED) totalPrice += anchoviesPrice; else if(select == ItemEvent.DESELECTED) totalPrice -= anchoviesPrice; } totPrice.setText(currency.format(totalPrice)); } public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if(source == exit) System.exit(0); } }Last edited by Norm; 04-13-2012 at 12:50 AM. Reason: added code tags
- 04-13-2012, 12:51 AM #2
Re: Problem with Applet, used a template, not working correctly.
Please explain what is not working correctly.It just isnt working correctlyIf you don't understand my response, don't ignore it, ask a question.
- 04-13-2012, 02:04 AM #3
Member
- Join Date
- Apr 2012
- Posts
- 7
- Rep Power
- 0
Re: Problem with Applet, used a template, not working correctly.
The only part working is the text field and the exit button.
- 04-13-2012, 02:07 AM #4
Re: Problem with Applet, used a template, not working correctly.
That's good that some of it works. Now pick one part that does not work and explain all about what happens or does not happen.
Post moved from Applet section. Nothing to do with java applets.Last edited by Norm; 04-13-2012 at 02:11 AM. Reason: Moved thread
If you don't understand my response, don't ignore it, ask a question.
- 04-13-2012, 01:31 PM #5
Member
- Join Date
- Apr 2012
- Posts
- 7
- Rep Power
- 0
Re: Problem with App, used a template, not working correctly.
The top two panels are blank, I can't see my radio buttons or check boxes.
- 04-13-2012, 01:32 PM #6
Re: Problem with App, used a template, not working correctly.
Where do you add those panels to the GUI so they can be shown?
If you don't understand my response, don't ignore it, ask a question.
- 04-13-2012, 01:37 PM #7
Member
- Join Date
- Apr 2012
- Posts
- 7
- Rep Power
- 0
Re: Problem with App, used a template, not working correctly.
Between lines 80-97.
- 04-13-2012, 01:39 PM #8
Re: Problem with App, used a template, not working correctly.
What is the line number where you add the top panel to the GUI.
If you don't understand my response, don't ignore it, ask a question.
- 04-13-2012, 05:26 PM #9
Member
- Join Date
- Apr 2012
- Posts
- 7
- Rep Power
- 0
Re: Problem with App, used a template, not working correctly.
Number line 80
- 04-13-2012, 05:32 PM #10
Re: Problem with App, used a template, not working correctly.
Are you using the line numbers from your post? Here are lines 79,80 and 81
Line 80 is the {Java Code:public static void main(String[] arguments) { Assignment8 aFrame = new Assignment8();
Look at the code you posted and use the line number from there.
Hnt: You have NOT added the top panel to the GUIIf you don't understand my response, don't ignore it, ask a question.
- 04-13-2012, 09:48 PM #11
Member
- Join Date
- Apr 2012
- Posts
- 7
- Rep Power
- 0
Similar Threads
-
method not working correctly
By r1b in forum New To JavaReplies: 4Last Post: 01-04-2012, 08:09 PM -
Trying to use the Paint but program isn't working correctly
By quickfingers in forum New To JavaReplies: 2Last Post: 12-28-2011, 09:15 AM -
Applet not working correctly?
By Beavotropper2 in forum Java AppletsReplies: 2Last Post: 04-18-2011, 06:32 AM -
[SOLVED] \t not working correctly?
By Gakusei in forum New To JavaReplies: 5Last Post: 05-06-2008, 04:45 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks