need programme of following java1,
April 22, 2009 at 10:01 PM
Objective: To use Swing widgets to develop a GUI Write an application that presents a colorful ordering screen for Lonny’s Lucky Logos Inc. which sells selected items with team logos to sports arena shops. You will display JButtons for the logos available: Tigers ($2.00), Lions ($3.00), Pistons ($4.00) and Redwings($5.00). The buttons should have icons and text showing the price of each. You will display JCheckBox for the items available: Tee Shirts, Sweat Shirts and Caps. These will be labeled, but do not have to have icons The user may choose only ONE logo, but as many of the items as he wishes to make up a gift set. You will also have a JTextField where the user can enter how many of these sets he wants to order. When he is finished he will press a done button. You will present a bill as shown in the JOptionPane – see sample screen below. When he has placed his order and seen his bill, he will press a clear button which will erase the Computer bill from the screen so that another user can place an order.
1.Globally declare: The 6 JButtons, 4 JCheckBoxs and 1 JTextField, any JLabels you need ‘constants’ for the price of each logo as given above (private final double lionlogo=2.0;) An int variable (numOrdered) to store the number to order entered in the JTextField A cost (to strore the cost of the logo selected (initialize to 0) An itemcost to accumulate the cost of all souvenir items ordereds(initialize to 0) A String initialized to null to accumulate all output Three Strings initialized to null: capStr, teeStr,sweatStr to store the item selected and to allow deselection A contentPane Any ImageIcons desired private ImageIcon lionlogo = new ImageIcon("lionsp7.gif"); DecimalFormat $###.00 or NumberFormat using US currency Any font desired Font f1 = new Font("serif",Font.BOLD,72); (to apply to any widget: myJLbl.setFont(f1);
2.Write the main Create an object of this JFrame child, set its size, set its visiblilbty
3.Write the constructor to place all widgets on the screen similar to my example above. a. Use FlowLayout for the easiest implementation. b. create and add each widget in the order it should appear on the screen c. Create an object of a class for handling JButtons (implements ActionListener) and one for handling JCheckBox objects (implements ItemListener) and register components appropriately.
4. in the event handler for JButtons: Set the global generic cost variable to the selected logo cost based on the button that was clicked and assign to the global string variable an appropriate message and price , like str = "Pistons @ $ "+df.format(cost); //where mf is an object of the NumberFormat class used for currency formatting (Use chained if structure since only one of logo can be selected)
If the done button was clicked: a. Extract the input from the JTextField and convert to integer. b. Add to the String that is accumulating all your output the sum of the capStr, teeStr, sweatStr (if one or more has been deselected in the execution of the code, it will have a “” (null) value c. Then add the cost of the logo and itemcost (see JCheckBox info below) and multiply by the number ordered. Output the string and the total cost in a JOptionPane as shown below.
If the clear button is clicked, a. deslect each JCheckBox: jtb.setSelected(false); b. set all accumulating variables to 0 c. set all strings to null, and d. Set the JTextField value to “0”: jtf.setText("0"); e. and finally give the command: repaint(); to clear the screen
5. in the event handler for JCheckBoxs: accumulate values in the global generic variable itemcost
if that JCheckBox is selected, and append an appropriate message to the string, for example itemcost += capcost; capStr = "\nCap @ $ "+df.format(capcost); if that JCheckBox is deselected, subtract the cost from the itemcost variable and set the capStr to null (same logic for all JCheckBoxes)