Questions
The question I have is that I want to draw without having to drag and then...

The question I have is that I want to draw without having to drag and then clicking the button whether I want a line or rectangle. It should work first by hitting either the line or rectangle button and then making a drag on the panel with mouse, then after releasing the drag it creates the graphic.

Here is my current code.

package Mod1;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class paintGUI extends JComponent {

    // Image in which we're going to draw
    private Image image;
    // Graphics2D object ==> used to draw on
    private Graphics2D g2;
    // Mouse coordinates
    private int currentX, currentY, oldX, oldY;

    public paintGUI() {
        setDoubleBuffered(false);
        addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent e) {
                // save coord x,y when mouse is pressed
                oldX = e.getX();
                oldY = e.getY();
                System.out.println("Mouse pressed");
            }
        });

        addMouseMotionListener(new MouseMotionAdapter() {
            public void mouseDragged(MouseEvent e) {
                System.out.println("Mouse dragged");

                // coord x,y when drag mouse
                currentX = e.getX();
                currentY = e.getY();
            }
        });
    }

    protected void paintComponent(Graphics g) {
        if (image == null) {
            // image to draw null ==> we create
            image = createImage(getSize().width, getSize().height);
            g2 = (Graphics2D) image.getGraphics();

            // clear draw area
            clear();
        }

        g.drawImage(image, 0, 0, null);
        repaint();
    }

    // now we create exposed methods
    public void clear() {
        g2.clearRect(0, 0, getSize().width, getSize().height);
        repaint();
    }

    public void thin() {
        g2.setStroke(new BasicStroke(3));
    }

    public void thick() {
        g2.setStroke(new BasicStroke(10));
    }

    public void red() {
        // apply red color on g2 context
        g2.setPaint(Color.red);
    }

    public void black() {
        g2.setPaint(Color.black);
    }

    public void magenta() {
        g2.setPaint(Color.magenta);
    }

    public void drawLine() {
        System.out.println("Drawing line");
        g2.drawLine(oldX, oldY, currentX, currentY);
        repaint();
    }

    public void drawRectangle() {
        System.out.println("Drawing rectangle");
        g2.drawRect(oldX, oldY, Math.abs(currentX - oldX), Math.abs(currentY - oldY));
        g2.fillRect(oldX, oldY, Math.abs(currentX - oldX), Math.abs(currentY - oldY));
        repaint();
    }

}

public class GUIPaint {

    JButton clearBtn, blackBtn, redBtn, magentaBtn, filledRectangleBtn, lineBtn, thinBtn, thickBtn;
    paintGUI paintGUI;
    ActionListener actionListener = new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (e.getSource() == clearBtn) {
                paintGUI.clear();
            } else if (e.getSource() == thinBtn) {
                paintGUI.thin();
            } else if (e.getSource() == thickBtn) {
                paintGUI.thick();
            } else if (e.getSource() == blackBtn) {
                paintGUI.black();
            } else if (e.getSource() == redBtn) {
                paintGUI.red();
            } else if (e.getSource() == magentaBtn) {
                paintGUI.magenta();
            } else if (e.getSource() == filledRectangleBtn) {
                paintGUI.drawRectangle();
            } else if (e.getSource() == lineBtn) {
                paintGUI.drawLine();
            }
        }
    };

    public static void main(String[] args) {
        new GUIPaint().show();
    }

    public void show() {
        // create main frame
        JFrame frame = new JFrame("Swing Paint");
        Container content = frame.getContentPane();
        // set layout on content pane
        content.setLayout(new BorderLayout());
        // create draw area
        paintGUI = new paintGUI();

        // add to content pane
        content.add(paintGUI, BorderLayout.CENTER);

        // create controls to apply colors and call clear feature
        JPanel controls = new JPanel();

        clearBtn = new JButton("Clear");
        clearBtn.addActionListener(actionListener);
        blackBtn = new JButton("Black");
        blackBtn.addActionListener(actionListener);
        redBtn = new JButton("Red");
        redBtn.addActionListener(actionListener);
        magentaBtn = new JButton("Magenta");
        magentaBtn.addActionListener(actionListener);

        lineBtn = new JButton("Line");
        lineBtn.addActionListener(actionListener);
        filledRectangleBtn = new JButton("Filled Rectangle");
        filledRectangleBtn.addActionListener(actionListener);

        thickBtn = new JButton("Thick Line");
        thickBtn.addActionListener(actionListener);
        thinBtn = new JButton("Thin Line");
        thinBtn.addActionListener(actionListener);

        controls.add(lineBtn);
        controls.add(filledRectangleBtn);
        controls.add(thinBtn);
        controls.add(thickBtn);
        controls.add(blackBtn);
        controls.add(redBtn);
        controls.add(magentaBtn);
        controls.add(clearBtn);

        // add to content pane
        content.add(controls, BorderLayout.NORTH);

        frame.setSize(800, 800);
        // can close frame
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        // show the swing paint result
        frame.setVisible(true);

    }

}

In: Computer Science

X Company is considering a new processor that costs $150,000.Shipping and setup costs for the...

X Company is considering a new processor that costs $150,000. Shipping and setup costs for the new processor are estimated to be $15,000. X’s working capital requirement is expected to increase by $17,000 when the new processor begins operation and is expected to be fully recoverable at the end of the project. The new processor’s useful life is expected to be 5 years and its salvage value at that point is estimated to be $60,000. The new processor is being depreciated using a 5-year ACRS life. Assume a tax rate of 35% and a cost of capital of 12%. Estimated incremental revenues and incremental cash operating expenses for the new processor before tax for each year are shown in the table below. Year Revenues Operating Expenses 1: $87,000 $23,000 2: $82,000 $25,000 3: $93,000 $30,000 4: $87,000 $23,000 5: $88,000 $29,000 The processor will be depreciated to a zero book value using the following annual depreciation rates that are applied to the original installed cost. Year Depreciation % 1: 15 2: 22 3 - 5: 21 A) What is the book value of the new processor at the end of Year 3? B) What is the incremental after-tax cash flows in Year 4? C) What is the total after-tax cash flows in Year 5? Total means incremental cash flows plus terminal cash flows.

In: Finance

As an engineer working for Thomson Pharmaceutical, you are in charge of developing a new cancer...

As an engineer working for Thomson Pharmaceutical, you are in charge of developing a new cancer drug. The new drug is to be used as a supplement to a well established, currently used drug to reduce tumor sizes in lung cancer patients. Previous studies have shown that the currently-used drug results in an average reduction in tumor mass of 38.7% after 8 weeks of use. To study the effects of the new supplement, you had 16 patients who were given both the current drug and the new supplement drug simultaneously. These patents showed an average 44.7% reduction in tumor mass after 8 weeks (5.92% standard deviation). You also had another 16 patients who were given the current drug along with a placebo (sugar pill) that they thought was the new supplemental drug. This last group showed an average 39.8% reduction after 8 weeks (5.15% standard deviation). In order for development of the new drug to continue, you need to be 99% confident that the supplemental drug is better than the placebo. Determine whether this is true. (Assume the variances are equal for all the studies).

(a) Write the appropriate null, and alternative hypotheses.

(b) Determine the correct pooled statistic (Sp).

(c) Identify the critical region (i.e, the test statistic needs to satisfy what inequality in order to reject the null hypothesis?)

(d) Estimate the p-value for this test. Based on your analysis, can the development of the new drug proceed?

In: Statistics and Probability

Problem 13-28 Net Present Value Analysis [LO13-2] Bilboa Freightlines, S.A., of Panama, has a small truck...

Problem 13-28 Net Present Value Analysis [LO13-2]

Bilboa Freightlines, S.A., of Panama, has a small truck that it uses for intracity deliveries. The truck is worn out and must be either overhauled or replaced with a new truck. The company has assembled the following information:


Present
Truck
New
Truck
Purchase cost new $ 34,000 $ 44,000
Remaining book value $ 21,000 -
Overhaul needed now $ 20,000 -
Annual cash operating costs $ 16,500 $ 15,000
Salvage value-now $ 10,000 -
Salvage value-five years from now $ 9,000 $ 9,000

    

If the company keeps and overhauls its present delivery truck, then the truck will be usable for five more years. If a new truck is purchased, it will be used for five years, after which it will be traded in on another truck. The new truck would be diesel-operated, resulting in a substantial reduction in annual operating costs, as shown above.

The company computes depreciation on a straight-line basis. All investment projects are evaluated using a 6% discount rate.

Click here to view Exhibit 13B-1 and Exhibit 13B-2, to determine the appropriate discount factor(s) using tables.


Required:

1. What is the net present value of the “keep the old truck” alternative?

2. What is the net present value of the “purchase the new truck” alternative?

3. Should Bilboa Freightlines keep the old truck or purchase the new one?

In: Finance

Bilboa Freightlines, S.A., of Panama, has a small truck that it uses for intracity deliveries. The...

Bilboa Freightlines, S.A., of Panama, has a small truck that it uses for intracity deliveries. The truck is worn out and must be either overhauled or replaced with a new truck. The company has assembled the following information:

Present
Truck
New
Truck
Purchase cost new $ 38,000 $ 48,000
Remaining book value $ 28,000 -
Overhaul needed now $ 27,000 -
Annual cash operating costs $ 20,000 $ 18,500
Salvage value-now $ 10,000 -
Salvage value-five years from now $ 14,000 $ 12,000

    

If the company keeps and overhauls its present delivery truck, then the truck will be usable for five more years. If a new truck is purchased, it will be used for five years, after which it will be traded in on another truck. The new truck would be diesel-operated, resulting in a substantial reduction in annual operating costs, as shown above.

The company computes depreciation on a straight-line basis. All investment projects are evaluated using a 7% discount rate.

Click here to view Exhibit 13B-1 and Exhibit 13B-2, to determine the appropriate discount factor(s) using tables.


Required:

1. What is the net present value of the “keep the old truck” alternative?

2. What is the net present value of the “purchase the new truck” alternative?

3. Should Bilboa Freightlines keep the old truck or purchase the new one?

In: Accounting

Factor Company is planning to add a new product to its line. To manufacture this product,...

Factor Company is planning to add a new product to its line. To manufacture this product, the company needs to buy a new machine at a $479,000 cost with an expected four-year life and a $11,000 salvage value. All sales are for cash, and all costs are out-of-pocket, except for depreciation on the new machine. Additional information includes the following. (PV of $1, FV of $1, PVA of $1, and FVA of $1) (Use appropriate factor(s) from the tables provided.) Expected annual sales of new product $ 1,950,000 Expected annual costs of new product Direct materials 470,000 Direct labor 676,000 Overhead (excluding straight-line depreciation on new machine) 336,000 Selling and administrative expenses 175,000 Income taxes 36 % Required: 1. Compute straight-line depreciation for each year of this new machine’s life. 2. Determine expected net income and net cash flow for each year of this machine’s life. 3. Compute this machine’s payback period, assuming that cash flows occur evenly throughout each year. 4. Compute this machine’s accounting rate of return, assuming that income is earned evenly throughout each year. 5. Compute the net present value for this machine using a discount rate of 7% and assuming that cash flows occur at each year-end. (Hint: Salvage value is a cash inflow at the end of the asset’s life.)

In: Accounting

Factor Company is planning to add a new product to its line. To manufacture this product,...

Factor Company is planning to add a new product to its line. To manufacture this product, the company needs to buy a new machine at a $515,000 cost with an expected four-year life and a $11,000 salvage value. All sales are for cash, and all costs are out-of-pocket, except for depreciation on the new machine. Additional information includes the following. (PV of $1, FV of $1, PVA of $1, and FVA of $1) (Use appropriate factor(s) from the tables provided.)

Expected annual sales of new product $ 1,920,000
Expected annual costs of new product
Direct materials 460,000
Direct labor 671,000
Overhead (excluding straight-line depreciation on new machine) 337,000
Selling and administrative expenses 171,000
Income taxes 32 %


Required:
1. Compute straight-line depreciation for each year of this new machine’s life.
2. Determine expected net income and net cash flow for each year of this machine’s life.
3. Compute this machine’s payback period, assuming that cash flows occur evenly throughout each year.
4. Compute this machine’s accounting rate of return, assuming that income is earned evenly throughout each year.
5. Compute the net present value for this machine using a discount rate of 7% and assuming that cash flows occur at each year-end. (Hint: Salvage value is a cash inflow at the end of the asset’s life.)

In: Accounting

Hat Tricks Company (HTC) is a Buffalo, New York, manufacturer of hats and gloves. Recently, the...

Hat Tricks Company (HTC) is a Buffalo, New York, manufacturer of hats and gloves. Recently, the company purchased a new machine to aid in producing the hat product lines. Production efficiency on the new machine increases with the workforce experience. It has been shown that as cumulative output on the new machine increases, average labor time per unit decreases up to the production of at least 3,200 units. As HTC’s cumulative output doubles from a base of 100 units produced, the cumulative average labor time per unit declines by a learning rate of 90%.

HTC has developed a new style of men’s hat to be produced on the new machine. One hundred of these hats can be produced in a total of 10 labor hours. All other direct costs to produce each hat are $25 per hat, excluding direct labor cost. Direct labor cost per hour is $84. Fixed costs are $8,000 per month, and HTC has the capacity to produce 3,200 hats per month.

Required:

HTC plans to set the selling price for the new men’s hat at 200% of direct production cost. If the company is planning to sell 100 hats, what is the selling price? If the plan is to sell 800 hats, what should be the selling price? (Do not round intermediate calculations. Round your answers to 2 decimal places.)

In: Accounting

RP owned residential real estate with a $726,000 adjusted basis that was condemned by City Q...

RP owned residential real estate with a $726,000 adjusted basis that was condemned by City Q because it needed the land for a new convention center. RP received $1,028,000 condemnation proceeds for the real estate. Assume that RP would elect to defer gain recognition when possible.

a. Assume RP spent $269,000 of the proceeds to expand its inventory and the remaining $759,000 to purchase new residential real estate. Calculate RP’s gain or loss realized, gain or loss recognized, and tax basis in the inventory and new real estate.

b. How would your answer to part a change if RP’s basis in the condemned real estate were $906,000 rather than $726,000?

c. How would your answer to part a change if RP invested the entire condemnation proceeds plus an additional $132,000 cash in new residential real estate?

Assume RP spent $269,000 of the proceeds to expand its inventory and the remaining $759,000 to purchase new residential real estate. Calculate RP’s gain or loss realized, gain or loss recognized, and tax basis in the inventory and new real estate.

Realized gain selected answer correct

$302,000 selected answer correct

Recognized gain selected answer correct

$269,000 selected answer correct

Basis in the inventory

$33,000 WRONG

Basis in the new real estate

$726,000selected answer correct

In: Accounting

Bilboa Freightlines, S.A., of Panama, has a small truck that it uses for intracity deliveries. The...

Bilboa Freightlines, S.A., of Panama, has a small truck that it uses for intracity deliveries. The truck is worn out and must be either overhauled or replaced with a new truck. The company has assembled the following information: Present Truck New Truck Purchase cost (new) $ 28,000 $ 38,000 Remaining book value $ 15,000 Overhaul needed now $ 14,000 Annual cash operating costs $ 14,500 $ 13,000 Salvage value-now $ 10,000 Salvage value-five years from now $ 9,000 $ 12,000 If the company keeps and overhauls its present delivery truck, then the truck will be usable for five more years. If a new truck is purchased, it will be used for five years, after which it will be traded in on another truck. The new truck would be diesel-operated, resulting in a substantial reduction in annual operating costs, as shown above. The company computes depreciation on a straight-line basis. All investment projects are evaluated using a 13% discount rate. Click here to view Exhibit 12B-1 and Exhibit 12B-2, to determine the appropriate discount factor(s) using tables. Required:

1. What is the net present value of the “keep the old truck” alternative?

2. What is the net present value of the “purchase the new truck” alternative?

3. Should Bilboa Freightlines keep the old truck or purchase the new one?

In: Accounting