Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Inheritance
- MusicVideo item3 = new MusicVideo("Music", 80, "Lil Wayne", "R&B");
- item3.show();
- class MusicVideo extends VideoTape {
- String artistN;
- String category;
- public MusicVideo(String ttl, int lngth, String artistN, String category) {
- super(ttl, lngth);
- this.artistN = artistN;
- this.category = category;
- }
- public void show() {
- super.show();
- System.out.println("artist : " + artistN + " " + "\ncategory : "+ category);
- }
- }
- //POLYMORPH
- Scanner sc = new Scanner(System.in);
- Saloon[] s1 = new Saloon[3];
- for (int i = 0; i < s1.length; i++) {
- s1[i] = new BodyTreatment(customerNumber, customerName, member, date, treatmentType);
- s1[i] = new HairTreatment(customerNumber, customerName, member, date, rebonding, cutting, washing, dyeing);
- }
- for (int i = 0; i < s1.length; i++) {
- s1[i].show();
- System.out.println("Treatment Cost \t: RM " + s1[i].computePayment() + "\n========================================\n");
- }
- sc.close();
- //GUI
- package ex2;
- import javax.swing.*;
- import javax.swing.event.ChangeEvent;
- import java.awt.*;
- import java.awt.event.*;
- import java.io.*;
- class MainMethod extends JFrame implements ActionListener{
- // Default frame width
- private static final int FRAME_WIDTH = 350;
- // Default frame height
- private static final int FRAME_HEIGHT = 200;
- // x coordinate of the frame default original point
- private static final int FRAME_X_ORIGIN = 150;
- // y coordinate of the frame default original point
- private static final int FRAME_Y_ORIGIN = 250;
- /**
- * The Swing button
- */
- private JButton btnCalculate;
- private JButton btnClear;
- /**
- * The JTextField for the user to enter the numbers
- */
- private JTextField txtNum1;
- private JTextField txtNum2;
- private JTextField txtTotal;
- //Checkbox
- private JCheckBox btnAlmond;
- private JCheckBox btnMazola;
- //Radio button
- private JRadioButton delivery;
- private JRadioButton noDelivery;
- /**
- * The JLabel for prompting the user
- */
- private JLabel lblNum1;
- private JLabel lblNum2;
- private JLabel lblTotal;
- //------------------------------------
- // Main Method
- //------------------------------------
- public static void main(String[] args) throws IOException {
- MainMethod calculator = new MainMethod();
- calculator.setVisible(true);
- }
- //------------------------------------
- // Constructors
- //------------------------------------
- public MainMethod()
- {
- Container contentPane;
- //set the frame properties
- setSize (FRAME_WIDTH, FRAME_HEIGHT);
- setResizable(true);
- setTitle ("Mini Calculator");
- setLocation (FRAME_X_ORIGIN, FRAME_Y_ORIGIN);
- contentPane = getContentPane();
- contentPane.setLayout(new GridLayout(6,2));
- JMenuBar mb = new JMenuBar();
- setJMenuBar(mb);
- JMenu fileMenu = new JMenu("File", false);
- fileMenu.add(new JMenuItem("new"));
- fileMenu.add(new JMenuItem("open"));
- fileMenu.addSeparator();
- fileMenu.add(new JMenuItem("print"));
- fileMenu.add(new JMenuItem("exit"));
- fileMenu.addSeparator();
- JMenu helpMenu = new JMenu("Help", true);
- helpMenu.add(new JCheckBoxMenuItem("Check it"));
- JMenu softwareHelpSubMenu = new JMenu("Software");
- JMenu hardwareHelpSubMenu = new JMenu("Hardware");
- helpMenu.add(softwareHelpSubMenu);
- helpMenu.add(hardwareHelpSubMenu);
- softwareHelpSubMenu.add(new JMenuItem("Unix"));
- softwareHelpSubMenu.add(new JMenuItem("NT"));
- softwareHelpSubMenu.add(new JMenuItem("Win95"));
- hardwareHelpSubMenu.add(new JMenuItem("MacOS"));
- mb.add(fileMenu);
- mb.add(helpMenu);
- JPopupMenu jPopupMenu = new JPopupMenu();
- JPopupMenu(new JMenuItem("New"));
- JPopupMenu(new JMenuItem("Open"));
- jPopupMenu.show(lblNum1, 500, 500);
- // add the labels
- lblNum1 = new JLabel();
- lblNum1.setText("Types");
- lblNum1.setSize(150, 25);
- lblNum2 = new JLabel();
- lblNum2.setText("Quantity/Box");
- lblNum2.setSize(150, 25);
- lblTotal = new JLabel();
- lblTotal.setText("Total Price:");
- lblTotal.setSize(150, 25);
- //add check box
- btnAlmond = new JCheckBox("Almond London");
- btnMazola = new JCheckBox("Mazola Cookies");
- //add radio button
- delivery = new JRadioButton("Delivery");
- delivery.setSelected(true);
- noDelivery = new JRadioButton("No Delivery");
- noDelivery.setSelected(true);
- // add the text fields
- txtNum1 = new JTextField();
- txtNum1.setColumns(15);
- txtNum1.setFont(new Font("Courier", Font.PLAIN, 14));
- txtNum2 = new JTextField();
- txtNum2.setColumns(15);
- txtNum2.setFont(new Font("Courier", Font.PLAIN, 14));
- txtTotal = new JTextField();
- txtTotal.setColumns(27);
- txtTotal.setFont(new Font("Courier", Font.PLAIN, 14));
- //create and place buttons on the frame
- btnCalculate = new JButton("CALCULATE");
- btnClear = new JButton("CLEAR");
- //add the objects to the content pane
- contentPane.add(lblNum1);
- contentPane.add(lblNum2);
- contentPane.add(btnAlmond);
- contentPane.add(txtNum1);
- contentPane.add(btnMazola);
- contentPane.add(txtNum2);
- //Radio button added in group
- ButtonGroup group = new ButtonGroup();
- delivery = new JRadioButton("DELIVERY ");
- delivery.setSelected(true);
- noDelivery = new JRadioButton("NO DELIVERY ");
- group.add(delivery );
- group.add(noDelivery );
- contentPane.add(delivery);
- contentPane.add(noDelivery);
- contentPane.add(lblTotal);
- contentPane.add(txtTotal);
- //add the button objects to the content pane
- contentPane.add(btnCalculate);
- contentPane.add(btnClear);
- //register this frame as an action listener of the buttons
- txtNum1.addActionListener(this);
- txtNum2.addActionListener(this);
- btnAlmond.addActionListener(this);
- btnMazola.addActionListener(this);
- btnCalculate.addActionListener(this);
- btnClear.addActionListener(this);
- setDefaultCloseOperation( EXIT_ON_CLOSE);
- }
- private void JPopupMenu(JMenuItem jMenuItem) {
- // TODO Auto-generated method stub
- }
- public void actionPerformed(ActionEvent event) {
- if (event.getSource() == btnCalculate ) {
- double total = 0.0;
- int almond = Integer.parseInt(txtNum1.getText());
- int mazola = Integer.parseInt(txtNum2.getText());
- if (delivery.isSelected() == true) {
- if (btnAlmond.isSelected() == true) {
- total += (20 * almond);
- }
- if (btnMazola.isSelected() == true) {
- total += (15 * mazola);
- }
- txtTotal.setText("RM " + (total + 5));
- } else if (noDelivery.isSelected() == true) {
- if (btnAlmond.isSelected() == true) {
- total += (20 * almond);
- }
- if (btnMazola.isSelected() == true) {
- total += (15 * mazola);
- }
- System.out.println("here");
- txtTotal.setText("RM " + total );
- }
- } else if ( event.getSource() == btnClear) {
- txtNum1.setText(" " + 0);
- txtNum2.setText(" " + 0);
- txtTotal.setText(" " + 0);
- }
- } // end of ActionPerformed
- }
Add Comment
Please, Sign In to add comment