Home arrow static arrow Java Programming [Archive] - Decided no pop up
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Decided no pop up
This topic has 2 replies on 1 page.

Registered: 4/21/04
Decided no pop up  
Jun 18, 2004 12:21 PM

I decided to add the graph to a JPanel on someone suggestion. I am using a text field to add the graph, is this the proper way of doing it.? I want the outpur of my calculations to create the graph and put it in the Row 7 JPanel. I have created the field but I am not sure if that is the correct way to add a graph.
Any suggestions?


import javax.swing.*;import java.awt.*;import java.awt.Graphics;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.ItemEvent;import java.awt.event.ItemListener;import java.text.NumberFormat;import java.util.Locale; public class Mortgage8 extends JFrame implements ItemListener, ActionListener {        //currency number formatter    NumberFormat formatter = NumberFormat.getCurrencyInstance(Locale.US);        // set up row 1    JPanel row1 = new JPanel();    JLabel principleLabel = new JLabel("Please enter your Principle with no commas: ", JLabel.RIGHT);    JTextField principle = new JTextField(10);        //set up row 2    JPanel row2 = new JPanel();    JLabel termLabel = new JLabel("Please enter the term of the loan in years: ", JLabel.RIGHT);    JTextField term = new JTextField(10);        //set up row 3    JPanel row3 = new JPanel();    JLabel aprLabel = new JLabel("Please enter your interest rate then press the enter key: ", JLabel.RIGHT);    JTextField apr = new JTextField(10);        //setup row 4 jcombo box    JPanel row4 = new JPanel();    JButton apr7 = new JButton("APR of 5.35% and a term of 7 years");    JButton apr15 = new JButton("APR of 5.5% and a term of 15 years");    JButton apr30 = new JButton("APR of 5.75% and a term of 30 years");            //set up row 5 the monthly payment output    JPanel row5 = new JPanel();    JLabel paymentLabel = new JLabel("Here is your monthly payment: ", JLabel.RIGHT);    JTextField payment = new JTextField(10);    JLabel paymentOutputLabel = new JLabel("Payment Output: ", JLabel.RIGHT);    JTextArea paymentOutput = new JTextArea(4,30);        //set up row 6 clear or exit    JPanel row6 = new JPanel();    JButton calculate = new JButton("Caculate Monthly Payments");    JButton clear = new JButton("Clear Fields");    JButton quit = new JButton("Quit");    //set up row 7 the monthly payments output    JPanel row7 = new JPanel();    JLabel compareLabel = new JLabel("Interest and Principle Comparison ", JLabel.RIGHT);    JTextArea compare = new JTextArea(4,30);            public Mortgage8(){        super("Mortgage Calculator");        setSize(800, 900);        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        GridLayout layout = new GridLayout(10, 30, 40, 5);        Container pane = getContentPane();        pane.setLayout(layout);        FlowLayout layout1 = new FlowLayout(FlowLayout.LEFT, 10, 10);        row1.setLayout(layout1);        row1.add(principleLabel);        row1.add(principle);        pane.add(row1);                FlowLayout layout2 = new FlowLayout(FlowLayout.LEFT, 10, 10);        row2.setLayout(layout2);        row2.add(termLabel);        //term.setEditable(false);        row2.add(term);        pane.add(row2);                FlowLayout layout3 = new FlowLayout(FlowLayout.LEFT, 10, 10);        row3.setLayout(layout3);        row3.add(aprLabel);        //apr.setEditable(false);        row3.add(apr);        pane.add(row3);                FlowLayout layout4 = new FlowLayout(FlowLayout.LEFT, 10, 10);        row4.setLayout(layout4);        row4.add(apr7);        row4.add(apr15);        row4.add(apr30);        pane.add(row4);                row4.add(apr7, FlowLayout.LEFT);        row4.add(apr15, FlowLayout.CENTER);        row4.add(apr30, FlowLayout.RIGHT);        pane.add(row4);                FlowLayout layout5 = new FlowLayout(FlowLayout.LEFT, 10, 10);        row5.setLayout(layout5);        row5.add(paymentLabel);        row5.add(payment);        row5.setLayout(layout5);        row5.add(paymentOutputLabel);        paymentOutput.setLineWrap(true);        paymentOutput.setWrapStyleWord(true);        JScrollPane scroll = new JScrollPane(paymentOutput,        JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,        JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);        row5.add(scroll);        pane.add(row5);                FlowLayout layout6 = new FlowLayout(FlowLayout.CENTER, 10, 10);        row6.setLayout(layout6);        row6.add(calculate);        row6.add(clear);        row6.add(quit);        Mortgage8.this.setVisible(false);        pane.add(row6);                        FlowLayout layout7 = new FlowLayout(FlowLayout.LEFT);        row7.setLayout(layout7);        row7.add(compareLabel);        compare.setLineWrap(true);        compare.setWrapStyleWord(true);        JScrollPane scrolla = new JScrollPane(compare,        JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,        JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);        row7.add(scrolla);        pane.add(row7);                setVisible(true);                //Add Listeners        calculate.addActionListener(this);        clear.addActionListener(this);        quit.addActionListener(this);        principle.addActionListener(this);        term.addActionListener(this);        apr.addActionListener(this);        apr7.addActionListener(this);        apr15.addActionListener(this);        apr30.addActionListener(this);        pack();    }        public static void main(String[] arguments) {        Mortgage8 frame = new Mortgage8();    }        public void actionPerformed(ActionEvent event) {        //clearing the fields        if (event.getSource().equals(clear)) {            principle.setText(null);            term.setText(null);            apr.setText(null);            payment.setText(null);            paymentOutput.setText(null);        }                //exit the application        if (event.getSource().equals(quit))            System.exit(0);                        if (event.getSource().equals(apr7)){            apr.setText("5.35");            term.setText("7");        }                if (event.getSource().equals(apr15)){            apr.setText("5.5");            term.setText("15");        }                if (event.getSource().equals(apr30)){            apr.setText("5.75");            term.setText("30");        }                if (event.getSource().equals(calculate)) {                        double interestRate = Double.parseDouble(apr.getText());            int loanYears = Integer.parseInt(term.getText());            double prin = Double.parseDouble(principle.getText());                        double month_payment;            double monthlyinterest;            double monthlyinterestPaid;            double mo_prin;            double total_interest;            double prinPaid;            double total_interest_paid;                        //sets these as standard integers            int months;            int monthsTotal;            int payment_num = 1;                        monthlyinterest = (interestRate / 100) / 12;		//monthly interest            months = (loanYears * 12);                        monthlyinterest = (interestRate / 100) / 12;		//monthly interest            months = (loanYears * 12);                        //monthly payment calculation            month_payment = (prin * monthlyinterest) / (1-Math.pow(1 + monthlyinterest, - months));            payment.setText(formatter.format(month_payment));                        monthlyinterestPaid=(prin * monthlyinterest);           //monthly interest paid            prinPaid=(month_payment-monthlyinterestPaid); //monthly principal payment            total_interest =(monthlyinterestPaid * months);                                    //allows the number payments to start at 1 for each term and interest            for (;months > 0 ; months -- ) {                                prin=(prin - prinPaid);                                payment_num = (payment_num + 1);                monthlyinterestPaid = (prin * monthlyinterest);    //monthly interest paid                                //this formula defines the monthly payment for the loan                month_payment=(prin * monthlyinterest)/(1-Math.pow(1+monthlyinterest,- months));                prinPaid=(month_payment - monthlyinterestPaid); //monthly principal payment                                paymentOutput.append("For payment number " +payment_num +                "\n You will have "+formatter.format(prin)+ " left on your principle" +                "\n You will pay, " +formatter.format(prinPaid)+ " towards your principle" +                "\n and " +formatter.format(monthlyinterestPaid)+ " in interest for this month"+                "\n You will also pay a total of  " +formatter.format(total_interest)+ " in interest. " +                "\n*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n");                        }                     }                         }    public void itemStateChanged(ItemEvent event) {}}

Registered: 00-08-28
Re: Decided no pop up  
Jun 18, 2004 1:59 PM (reply 1 of 2)

what is this to with pop ups?

Registered: 8/15/02
Re: Decided no pop up  
Jun 18, 2004 3:07 PM (reply 2 of 2)

I suspect the OP originally displayed the graph in a pop-up
This topic has 2 replies on 1 page.