Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: HELP! Recompile with -Xlint:unchecked for details?????

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default HELP! Recompile with -Xlint:unchecked for details?????

    When I try to compile my code I get this message. What does this mean about my code?

    Note: C:\Users\myname\Desktop\Week3_421.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.

    Tool completed successfully

    Thank you for any help.

    Here is my code:

    import javax.swing.*;
    import java.awt.Container;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;


    public class Week3_421 extends JFrame implements ActionListener
    {
    // Variables
    JLabel titleLabel = new JLabel("Mortgage Calculator");
    JLabel amntLabel = new JLabel("Mortgage Amount: ");
    JLabel selecLabel = new JLabel("Choose your Mortgage: ");


    JTextField amntText = new JTextField("");
    JComboBox loanType;


    JButton buttonCal = new JButton("Calculate");
    JButton buttonClr = new JButton("Reset");
    JButton buttonExit = new JButton("Exit");


    JTextArea displayArea = new JTextArea(40, 20);

    java.text.DecimalFormat fmt = new java.text.DecimalFormat("###,###,###.00");

    public static void main(String[] args)
    {
    Week3_421 window = new Week3_421();
    window.setSize(490, 490);
    window.setVisible(true);
    }

    public Week3_421()
    {
    setTitle("Week3_421");
    buildGUI();
    }


    public void buildGUI()
    {
    Container content = getContentPane();
    content.setLayout(null);


    // The array of loans
    Loan[] loans = new Loan[3];
    loans[0] = new Loan(5.35, 7);
    loans[1] = new Loan(5.5, 15);
    loans[2] = new Loan(5.75, 30);


    loanType = new JComboBox(loans);


    content.add(titleLabel);
    content.add(amntLabel);
    content.add(selecLabel);
    content.add(amntText);
    content.add(loanType);
    content.add(buttonCal);
    content.add(buttonClr);
    content.add(buttonExit);

    JScrollPane scroll = new JScrollPane(displayArea);
    content.add(scroll);

    // Orientation
    titleLabel.setBounds(180, 20, 200, 30);
    amntLabel.setBounds(50, 60, 150, 30);
    amntText.setBounds(260, 60, 180, 30);
    selecLabel.setBounds(50, 100, 150, 30);
    loanType.setBounds(260, 100, 180, 30);

    buttonCal.setBounds(50, 200, 100, 30);
    buttonClr.setBounds(200, 200, 100, 30);
    buttonExit.setBounds(350, 200, 100, 30);

    scroll.setBounds(50, 250, 400, 180);

    buttonCal.addActionListener(this);
    buttonClr.addActionListener(this);
    buttonExit.addActionListener(this);
    }

    // The course of Action
    public void actionPerformed(ActionEvent e)
    {
    if (e.getSource()==buttonClr)
    {
    buttonClear();
    }
    else
    if (e.getSource()==buttonCal)
    {
    buttonCalculate();

    }
    else if (e.getSource()==buttonExit)
    {
    buttonExit();
    }
    }


    // The action of Reset
    public void buttonClear()
    {
    amntText.setText("");
    displayArea.setText("");
    }

    // The Action of Exit
    public void buttonExit()
    {
    System.exit(0);
    }

    // The Action of Calculate
    public void buttonCalculate()
    {
    try
    {

    Loan loan = (Loan)loanType.getSelectedItem();
    double amount = Double.parseDouble(amntText.getText());
    int year = loan.getTermYears();
    double rate = loan.getInterestYearly();

    double payment = calcMonthlyPayment(amount, rate / 100, year);
    displayMonthlyPayment(amount, rate / 100, year, payment);
    } catch (Exception e)
    {
    displayArea.setText("Error! Please, ENTER the APPROPRIATE information.");
    }
    }


    // Display
    public void displayMonthlyPayment(double principal, double interestYearly, int termYears, double monthlyPayment)
    {
    double interestMonthly = interestYearly / 12.0;
    displayArea.setText("Loan Amount: " + fmt.format(principal) + "\n");
    displayArea.append("Years: " + termYears + "\n");
    displayArea.append("Interest: " + interestYearly * 100 + "% \n");
    displayArea.append("Monthly Payment: " + fmt.format(monthlyPayment) + "\n\n");
    displayArea.append("Month\tPrinciple\tBalance Paid\tInterest Paid\n");
    for (int count = 1; count <= termYears * 12; count++)
    {

    double interest = principal * interestMonthly; // Interest Paid

    double loan = monthlyPayment - interest; // Load Balanced Paid

    principal -= loan; // Amount left

    // Display for balance and interest Paid
    displayArea.append(String.format("%01d\t%s\t%s\t%s \n", count, fmt.format(principal),fmt.format(loan), fmt.format(interest)));
    }
    }


    // Calculation of Monthly payment

    public double calcMonthlyPayment(double principal, double interestYearly, int termYears)
    {

    double interestMonthly = interestYearly / 12.0;
    double numberOfPayments = termYears * 12;
    return (principal * interestMonthly) / (1.0 - (Math.pow((1.0 + interestMonthly), -numberOfPayments)));
    }

    }

    class Loan
    {
    private double yearlyInterest;
    private int termYears;


    public Loan(double yearlyInterest, int termYears)
    {
    this.yearlyInterest = yearlyInterest;
    this.termYears = termYears;
    }

    //Get the interestYearly
    public double getInterestYearly()
    {
    return yearlyInterest;
    }

    //Get the termYears
    public int getTermYears()
    {
    return termYears;
    }

    //Overriden toString
    public String toString()
    {
    return String.format("%d year term at %.2f%%", termYears, yearlyInterest);
    }

    }


  2. #2
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: HELP! Recompile with -Xlint:unchecked for details?????

    You should do what it suggests. Just add the -Xlint:unchecked to your javac command line and it will tell you exactly what it's not happy about.

  3. #3
    Junior Member
    Join Date
    Aug 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: HELP! Recompile with -Xlint:unchecked for details?????

    Quote Originally Posted by Sean4u View Post
    You should do what it suggests. Just add the -Xlint:unchecked to your javac command line and it will tell you exactly what it's not happy about.
    So I complied it with Xlint and this is what it does not like. I am a java newbie so the warning does not make scene to me.

    Thank you for your help!!!!

    C:\Users\MYname\Desktop\Week3_421.java:68: warning: [unchecked] unchecked call to JComboBox(E[]) as a member of the raw type JComboBox
    loanType = new JComboBox(loans);
    ^
    where E is a type-variable:
    E extends Object declared in class JComboBox

  4. #4
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: HELP! Recompile with -Xlint:unchecked for details?????

    That is a bit of an obscure warning! Have a look at the API doc for JComboBox (you should have a copy of the API docs on your PC and have it open in a browser tab all the time you're writing Java) - here's Oracle's page: JComboBox (Java Platform SE 6)

    Hmmm - I can see nothing wrong with that line. Have you changed your code since your first post?
    Last edited by Sean4u; August 7th, 2011 at 05:50 AM. Reason: oops, not quite right

  5. #5
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: HELP! Recompile with -Xlint:unchecked for details?????

    That'll teach me to think out loud - I don't think I'm looking at the same API as you. That warning should normally only appear for 'generic' classes, and in my API JComboBox is not generic. What version of Java do you have installed? On a hunch, I changed the '6' to a '7' in my previous link to the API and I get:
    JComboBox (Java Platform SE 7 )

    Generic ComboBox! OK, so now the link in the API to 'How to use Combo Boxes' is now out of date - you'll have to read that page (your code is good for Java 6 and before, needs updating for Java 7) in conjunction with Java Generics Lesson: Generics (The Java™ Tutorials > Learning the Java Language)

Similar Threads

  1. need details on Implementing Dictionary Filters for English words
    By madcrazyboys in forum Java Theory & Questions
    Replies: 2
    Last Post: May 6th, 2011, 12:53 PM
  2. Unchecked or Unsafe Operations
    By saxophonemaster in forum Collections and Generics
    Replies: 2
    Last Post: April 12th, 2011, 04:40 AM
  3. Unchecked or Unverified Warning
    By saxophonemaster in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 2nd, 2011, 08:59 PM
  4. How to extract a particular element details which has more references ???
    By j_kathiresan in forum Algorithms & Recursion
    Replies: 1
    Last Post: December 31st, 2009, 01:11 AM