RSS Forums RSS
Please support our Java advertiser: Lunarpages Java Web Hosting

a Java GUI based program using Swing classes, Vat

Join Date: Mar 2005
Posts: 1
Reputation: shakaal is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
shakaal shakaal is offline Offline
Newbie Poster

Re: a Java GUI based program using Swing classes, Vat

  #6  
Apr 1st, 2005
please help
could any one help me
how to design the UML for this program.


// Exercivat = subtotal * 0.175;ext ( total );ables users to calculate vat.
import java.awt.*;
import java.awt.event.*;
import java.text.*;
import javax.swing.*;

public class orderForm extends JFrame
{
//JLabel for business name
private JLabel businessNameJLabel;

//JPicture
private JLabel computerJLabel; // JLabel that displays an image

//JPicture
private JLabel computer2JLabel; // JLabel that displays an image

// JLabel and JTextField for order number
private JLabel orderJLabel;
private JTextField orderJTextField;

// JLabel and JTextField for name
private JLabel nameJLabel;
private JTextField nameJTextField;

// JLabel and JTextField for addressline1
private JLabel addressLine1JLabel;
private JTextField addressLine1JTextField;

// JLabel and JTextField for addressLine2
private JLabel addressLine2JLabel;
private JTextField addressLine2JTextField;

//JLabel for product name
private JLabel productNameJLabel;

//JLabel for productQuantity
private JLabel productQuantityJLabel;

//JLabel for productPrice
private JLabel productPriceJLabel;

//JLabel for orderTotals
private JLabel orderTotalsJLabel;

// JCheckBox and JLabel for computer
private JCheckBox computerJCheckBox;
private JLabel computerPriceJLabel;

// JCheckBox and JLabel for printer
private JCheckBox printerJCheckBox;
private JLabel printerPriceJLabel;

//JTextField for computerquantity
private JTextField computerquantityJTextField;

//JTextField for printerquantity
private JTextField printerquantityJTextField;

//JTextField for computerprice
private JTextField computerpriceJTextField;

//JTextField for printerprice
private JTextField printerpriceJTextField;

//JTextField for computerTotals
private JTextField computerTotalsJTextField;

//JTextField for printerTotals
private JTextField printerTotalsJTextField;

// JLabel and JTextField for subtotal
private JLabel subtotalJLabel;
private JTextField subtotalJTextField;

// JLabel and JTextField for vat
private JLabel vatJLabel;
private JTextField vatJTextField;

// JLabel and JTextField for total
private JLabel totalJLabel;
private JTextField totalJTextField;

// JButton to initiate calculation
private JButton calculateJButton;


// no-argument constructor
public orderForm()
{
createUserInterface();
}

// create and position GUI components
public void createUserInterface()
{
// get content pane and set its layout
Container container = getContentPane();
container.setLayout( null );

// set up businessNameJLabel
businessNameJLabel = new JLabel();
businessNameJLabel.setText( "Cool Computer Sales" );
businessNameJLabel.setLocation( 35, 20 );
businessNameJLabel.setSize( 550, 88 );
businessNameJLabel.setFont( new Font( "SansSerif", Font.PLAIN, 36 ) );
businessNameJLabel.setHorizontalAlignment( JLabel.CENTER );
container.add( businessNameJLabel );

// set up pictureJLabel
computerJLabel = new JLabel();
computerJLabel.setIcon( new ImageIcon( "computer.jpg" ) );
computerJLabel.setBounds( 10, 30, 100, 100 );
computerJLabel.setHorizontalAlignment( JLabel.CENTER );
container.add( computerJLabel );

// set up pictureJLabel
computer2JLabel = new JLabel();
computer2JLabel.setIcon( new ImageIcon( "computer.jpg" ) );
computer2JLabel.setBounds( 510, 30, 100, 100 );
computer2JLabel.setHorizontalAlignment( JLabel.CENTER );
container.add( computer2JLabel );

// set up orderJLabel
orderJLabel = new JLabel();
orderJLabel.setBounds( 26, 170, 134, 21 );
orderJLabel.setText( "Order No:" );
container.add( orderJLabel );

// set up orderJTextField
orderJTextField = new JTextField();
orderJTextField.setBounds( 120, 170, 40, 21 );
orderJTextField.setText( "" );
container.add( orderJTextField );

// set up nameJLabel
nameJLabel = new JLabel();
nameJLabel.setBounds( 26, 200, 130, 21 );
nameJLabel.setText( "Name:" );
container.add( nameJLabel );

// set up nameJTextField
nameJTextField = new JTextField();
nameJTextField.setBounds( 120, 200, 220, 21 );
nameJTextField.setText( "" );
container.add( nameJTextField );

// set up addressLine1JLabel
addressLine1JLabel = new JLabel();
addressLine1JLabel.setBounds( 26, 230, 120, 21 );
addressLine1JLabel.setText( "Address Line 1:" );
container.add( addressLine1JLabel );

// set up addressLine1JTextField
addressLine1JTextField = new JTextField();
addressLine1JTextField.setBounds( 120, 230, 220, 21 );
addressLine1JTextField.setText( "" );
container.add( addressLine1JTextField );

// set up addressLine2JLabel
addressLine2JLabel = new JLabel();
addressLine2JLabel.setBounds( 26, 260, 120, 21 );
addressLine2JLabel.setText( "Address Line 2:" );
container.add( addressLine2JLabel );

// set up addressLine2JTextField
addressLine2JTextField = new JTextField();
addressLine2JTextField.setBounds( 120, 260, 220, 21 );
addressLine2JTextField.setText( "" );
container.add( addressLine2JTextField );

// set up productNameJLabel
productNameJLabel = new JLabel();
productNameJLabel.setBounds( 26, 315, 64, 21 );
productNameJLabel.setText( "Product" );
container.add( productNameJLabel );

// set up productQuantityJLabel
productQuantityJLabel = new JLabel();
productQuantityJLabel.setBounds( 160, 315, 64, 21 );
productQuantityJLabel.setText( "Quantity" );
container.add( productQuantityJLabel );

// set up productPriceJLabel
productPriceJLabel = new JLabel();
productPriceJLabel.setBounds( 260, 315, 64, 21 );
productPriceJLabel.setText( "Price" );
container.add( productPriceJLabel );

// set up orderTotalsJLabel
orderTotalsJLabel = new JLabel();
orderTotalsJLabel.setBounds( 360, 315, 64, 21 );
orderTotalsJLabel.setText( "Totals" );
container.add( orderTotalsJLabel );

// set up computerJCheckBox
computerJCheckBox = new JCheckBox();
computerJCheckBox.setBounds( 26, 350, 122, 24 );
computerJCheckBox.setText( "Computer" );
container.add( computerJCheckBox );

// set up printerJCheckBox
printerJCheckBox = new JCheckBox();
printerJCheckBox.setBounds( 26, 390, 122, 24 );
printerJCheckBox.setText( "Printer" );
container.add( printerJCheckBox );

// set up computerquantityJTextField
computerquantityJTextField = new JTextField();
computerquantityJTextField.setBounds( 160, 350, 56, 21 );
computerquantityJTextField.setText( "0" );
computerquantityJTextField.setHorizontalAlignment( JTextField.CENTER );
container.add( computerquantityJTextField );

// set up printerquantityJTextField
printerquantityJTextField = new JTextField();
printerquantityJTextField.setBounds( 160, 390, 56, 21 );
printerquantityJTextField.setText( "0" );
printerquantityJTextField.setHorizontalAlignment( JTextField.CENTER );
container.add( printerquantityJTextField );


// set up computerpriceJTextField
computerpriceJTextField = new JTextField();
computerpriceJTextField.setBounds( 260, 350, 56, 21 );
computerpriceJTextField.setText( "$350.00" );
computerpriceJTextField.setEditable( false );
computerpriceJTextField.setHorizontalAlignment( JTextField.CENTER );
container.add( computerpriceJTextField );

// set up printerpriceJTextField
printerpriceJTextField = new JTextField();
printerpriceJTextField.setBounds( 260, 390, 56, 21 );
printerpriceJTextField.setText( "$125.00" );
printerpriceJTextField.setEditable( false );
printerpriceJTextField.setHorizontalAlignment( JTextField.CENTER );
container.add( printerpriceJTextField );

// set up computerTotalsJTextField
computerTotalsJTextField = new JTextField();
computerTotalsJTextField.setBounds( 360, 350, 56, 21 );
computerTotalsJTextField.setText( "$0.00" );
computerTotalsJTextField.setEditable( false );
computerTotalsJTextField.setHorizontalAlignment( JTextField.CENTER );
container.add( computerTotalsJTextField );

// set up printerTotalsJTextField
printerTotalsJTextField = new JTextField();
printerTotalsJTextField.setBounds( 360, 390, 56, 21 );
printerTotalsJTextField.setText( "$0.00" );
printerTotalsJTextField.setEditable( false );
printerTotalsJTextField.setHorizontalAlignment( JTextField.CENTER );
container.add( printerTotalsJTextField );

// set up subtotalJLabel
subtotalJLabel = new JLabel();
subtotalJLabel.setBounds( 260, 430, 134, 21 );
subtotalJLabel.setText( "Subtotal:" );
container.add( subtotalJLabel );

// set up subtotalJTextField
subtotalJTextField = new JTextField();
subtotalJTextField.setBounds( 360, 430, 56, 21 );
subtotalJTextField.setText( "$0.00" );
subtotalJTextField.setEditable( false );
subtotalJTextField.setHorizontalAlignment( JTextField.CENTER );
container.add( subtotalJTextField );

// set up vatJLabel
vatJLabel = new JLabel();
vatJLabel.setBounds( 260, 470, 134, 21 );
vatJLabel.setText( "VAT 17.5%:" );
container.add( vatJLabel );

// set up vatJTextField
vatJTextField = new JTextField();
vatJTextField.setBounds( 360, 470, 60, 21 );
vatJTextField.setText( "$0.00" );
vatJTextField.setEditable( false );
vatJTextField.setHorizontalAlignment( JTextField.CENTER );
container.add( vatJTextField );

// set up totalJLabel
totalJLabel = new JLabel();
totalJLabel.setBounds( 260, 510, 134, 21 );
totalJLabel.setText( "Total:" );
container.add( totalJLabel );

// set up totalJTextField
totalJTextField = new JTextField();
totalJTextField.setBounds( 360, 510, 60, 21 );
totalJTextField.setText( "$0.00" );
totalJTextField.setEditable( false );
totalJTextField.setHorizontalAlignment( JTextField.CENTER );
container.add( totalJTextField );

// set up calculateJButton
calculateJButton = new JButton();
calculateJButton.setBounds( 335, 550, 90, 24 );
calculateJButton.setText( "Calculate" );
container.add( calculateJButton );

calculateJButton.addActionListener(

new ActionListener()
{
public void actionPerformed (ActionEvent event)
{
calculateJButtonActionPerformed (event);
}
}
);

// set properties of application’s window
setTitle( "Cool Computer Sales" ); // set title bar text
setSize( 650, 650 ); // set window size
setVisible( true ); // display window

} // end method createUserInterface

// calculate total of order

private void calculateJButtonActionPerformed ( ActionEvent event )
{

// declare
String orderNumber = orderJTextField.getText();
String name = nameJTextField.getText();
String addressLine1 = addressLine1JTextField.getText();
String addressLine2 = addressLine2JTextField.getText();

double computerTotals = 0.0;
double printerTotals = 0.0;
double subtotal = 0.0;
double vat = 0.0;
double total =0.0;


// display error message if no name entered or
// no JCheckBox is selected
if ( ( orderNumber.equals( "" ) ) ||
( ( name.equals( "" ) ) ||
( ( addressLine1.equals( "" ) ) ||
( ( addressLine2.equals( "" ) ) ||
( !computerJCheckBox.isSelected() ) ) ) ) )
{
// display error message
JOptionPane.showMessageDialog( null,
"Please enter a Order No, Name, Address details and check at least one item.",
"Missing Information", JOptionPane.ERROR_MESSAGE );
}
else // otherwise, do calculations
{

DecimalFormat dollars = new DecimalFormat ("$0.00");
computerTotals = Integer.parseInt(
computerquantityJTextField.getText() ) * 350.00;
printerTotals = Integer.parseInt(
printerquantityJTextField.getText() ) * 125.00;

computerTotals = computerTotals;
computerTotalsJTextField.setText ( dollars.format(computerTotals));

printerTotals = printerTotals;
printerTotalsJTextField.setText ( dollars.format(printerTotals));

subtotal = computerTotals + printerTotals;
subtotalJTextField.setText ( dollars.format(subtotal ));

vat = subtotal * 0.175;
vatJTextField.setText ( dollars.format( vat ));

total = subtotal + vat;
totalJTextField.setText ( dollars.format( total ));


}

}

// main method
public static void main( String[] args )
{
orderForm application = new orderForm();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

} // end method main

} // end class orderForm
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 11:33 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC