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: don't know what's wrong

  1. #1
    Junior Member james's Avatar
    Join Date
    Jan 2010
    Posts
    19
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Red face don't know what's wrong

    Hey. guys it's me again I got this GUI program but I don't what kind of problem occuring in my program.This GUI program should convert seconds to years, weeks,days,hours,and minutes.Assume 1 year has 365 days.



    [

    import javax.swing.*;
    import java.awt.*;

    public class moimoi extends JFrame

    {
    private JLabel secondsL, yearsL, weeksL, daysL, hoursL, minuteL, SecondsL;
    private JButton calculateB, exitB;
    private JTextField SecondsTF, YearsTF, WeeksTF, DaysTF, HoursTF, MinuteTF, SecondsTF;
    private CalculateButtonHandler cbHandler;
    private ExitButtonHandler ebHandler;
    private static final int WIDTH = 326;
    private static final int HEIGHT = 450;

    public moimoi()
    {
    secondsL = new JLabel("Enter Seconds: ", SwingConstants.RIGHT);
    yearsL = new JLabel("Years: ", SwingConstants.RIGHT);
    weeksL = new JLabel("Weeks: ", SwingConstants.RIGHT);
    daysL = new JLabel("Days: ", SwingConstants.RIGHT);
    hoursL = new JLabel("Days: ", SwingConstants.RIGHT);
    minuteL = new JLabel("Minute: ", SwingConstants.RIGHT);
    SecondsL = new JLabel("Seconds: ", SwingConstants.RIGHT);

    secondsTF = new JTextField(13);
    yearsTF = new JTextField(13);
    weeksTF = new JTextField(13);
    daysTF = new JTextField(13);
    hoursTF = new JTextField(13);
    minuteTF = new JTextField(13);
    SecondsTF = new JTextField(13);



    calculateB = new JButton("Push");
    pbHandler = new PushButtonHandler();
    pushB.addActionListener(pbHandler);

    exitB = new JButton("Exit");
    ebHandler = new ExitButtonHandler();
    exitB.addActionListener(cbHandler);

    setTitle("Seconds Converter Program ");

    Container pane = getContentPane();

    pane.setLayout(new GridLayout (6, 3));

    pane.add(secondsL);
    pane.add(secondsTF);

    pane.add(yearsL);
    pane.add(yearsTF);

    pane.add(weeksL);
    pane.add(weeksTF);

    pane.add(daysL);
    pane.add(daysTF);

    pane.add(hoursL);
    pane.add(hoursTF);

    pane.add(minuteL);
    pane.add(minuteTF);

    pane.add(SecondsL);
    pane.add(SecondsTF);

    pane.add(calculateB);
    pane.add(exitB);

    setSize(WIDTH, HEIGHT);
    setVisible(true);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    }

    private class CalculateButtonHandler implements ActionListener

    {
    public void actionPerformed(ActionEvent e)
    {
    double years, weeks, days, hours, minute, Seconds;


    seconds = Double.parseDouble(secondsTF.getText());
    years = 365 days * 86400 seconds ;
    weeks = 7 days * 86400 seconds ;
    days = 24 hours * 3600 seconds;
    hours = 60 minutes * 60 seconds;
    minute = 1 seconds * 60 seconds;
    Seconds = seconds;


    secondsTF.setText("" + String.format("%.2f%n", seconds));
    yearsTF.setText("" + String.format("%.2f%n", years));
    weeksTF.setText("" + String.format("%.2f%n", weeks));
    daysTF.setText("" + String.format("%.2f%n", days));
    hoursTF.setText("" + String.format("%.2f%n", hours));
    minuteTF.setText("" + String.format("%.2f%n", minute));
    SecondsTF.setText("" + String.format("%.2f%n", Seconds));


    }
    }

    private class ExitButtonHandler implements ActionListener
    {
    public void actionPerfomed(ActionEvent e)
    {
    System.exit(0);
    }
    }
    public static void main(String[] args)
    {

    moimoi moiObject = new moimoi();
    }
    }
    /]


  2. #2
    Member
    Join Date
    Feb 2010
    Location
    Dehradun, India
    Posts
    37
    Thanks
    1
    Thanked 7 Times in 6 Posts

    Default Re: don't know what's wrong

    May i know from where you are getting your programs?

    I think you are not writing these programs yourself.

  3. #3
    Junior Member james's Avatar
    Join Date
    Jan 2010
    Posts
    19
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: don't know what's wrong

    Well, the truth is that I wrote this programs on my own with the help from examples from Malik book's.

  4. #4
    Member
    Join Date
    Feb 2010
    Location
    Dehradun, India
    Posts
    37
    Thanks
    1
    Thanked 7 Times in 6 Posts

    Default Re: don't know what's wrong

    Hi james I will suggest you to use Eclipse IDE so that you can have a look on different functions. Their parameters. how to use them. You can program much better then

  5. #5
    Junior Member james's Avatar
    Join Date
    Jan 2010
    Posts
    19
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Unhappy Re: don't know what's wrong

    Well, Ihave made some changes to my program but I STILL HAVE ONE ERROR LEFT AND I DON'T KNOW WHAT I SHOULD DO TO IT.PLEASE HELP ME.HERE IS MY MODIFIED PROGRAM WITH ONE ERROR:

    [

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class moimoi extends JFrame

    {
    private JLabel secondsL, YearsL, WeeksL, DaysL, HoursL, MinuteL, SecondsL;
    private JButton calculateB, exitB;
    private JTextField secondsTF, YearsTF, WeeksTF, DaysTF, HoursTF, MinuteTF, SecondsTF;
    private CalculateButtonHandler cbHandler;
    private ExitButtonHandler ebHandler;
    private static final int WIDTH = 326;
    private static final int HEIGHT = 450;

    public moimoi()
    {
    secondsL = new JLabel("Enter Seconds: ", SwingConstants.RIGHT);
    YearsL = new JLabel("Years: ", SwingConstants.RIGHT);
    WeeksL = new JLabel("Weeks: ", SwingConstants.RIGHT);
    DaysL = new JLabel("Days: ", SwingConstants.RIGHT);
    HoursL = new JLabel("Days: ", SwingConstants.RIGHT);
    MinuteL = new JLabel("Minute: ", SwingConstants.RIGHT);
    SecondsL = new JLabel("Seconds: ", SwingConstants.RIGHT);

    secondsTF = new JTextField(13);
    YearsTF = new JTextField(13);
    WeeksTF = new JTextField(13);
    DaysTF = new JTextField(13);
    HoursTF = new JTextField(13);
    MinuteTF = new JTextField(13);
    SecondsTF = new JTextField(13);



    calculateB = new JButton("Calculate");
    cbHandler = new CalculateButtonHandler();
    calculateB.addActionListener(cbHandler);

    exitB = new JButton("Exit");
    ebHandler = new ExitButtonHandler();
    exitB.addActionListener(cbHandler);

    setTitle("Seconds Converter Program ");

    Container pane = getContentPane();

    pane.setLayout(new GridLayout (7, 2));

    pane.add(secondsL);
    pane.add(secondsTF);

    pane.add(YearsL);
    pane.add(YearsTF);

    pane.add(WeeksL);
    pane.add(WeeksTF);

    pane.add(DaysL);
    pane.add(DaysTF);

    pane.add(HoursL);
    pane.add(HoursTF);

    pane.add(MinuteL);
    pane.add(MinuteTF);

    pane.add(SecondsL);
    pane.add(SecondsTF);

    pane.add(calculateB);
    pane.add(exitB);

    setSize(WIDTH, HEIGHT);
    setVisible(true);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    }

    private class CalculateButtonHandler implements ActionListener

    {
    public void actionPerformed(ActionEvent e)
    {
    double seconds, years, weeks, days, hours, minute, Seconds;


    seconds = Double.parseDouble(secondsTF.getText());
    years = 365* days * 86400 * seconds ;
    weeks = 7 * days * 86400 * seconds ;
    days = 24 * hours * 3600 * seconds;
    hours = 60 * minute * 60 * seconds;
    minute = 1 * seconds * 60 * seconds;
    Seconds = seconds;


    secondsTF.setText("" + String.format("%.2f%n", seconds));
    YearsTF.setText("" + String.format("%.2f%n", years));
    WeeksTF.setText("" + String.format("%.2f%n", weeks));
    DaysTF.setText("" + String.format("%.2f%n", days));
    HoursTF.setText("" + String.format("%.2f%n", hours));
    MinuteTF.setText("" + String.format("%.2f%n", minute));
    SecondsTF.setText("" + String.format("%.2f%n", Seconds));


    }
    }

    private class ExitButtonHandler implements ActionListener
    {
    public void actionPerfomed(ActionEvent e)
    {
    System.exit(0);
    }
    }
    public static void main(String[] args)
    {

    moimoi moiObject = new moimoi();
    }
    }
    /]

    AND HERE IS THE ERROR;

    H:\JAVAFILES>javac moimoi.java
    moimoi.java:107: moimoi.ExitButtonHandler is not abstract and does not override
    abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.Ac
    tionListener
    private class ExitButtonHandler implements ActionListener
    ^
    1 error

Similar Threads

  1. Where am I going wrong? :)
    By KevinGreen in forum What's Wrong With My Code?
    Replies: 9
    Last Post: October 18th, 2009, 12:03 AM
  2. whats wrong with this one....
    By chronoz13 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: October 6th, 2009, 10:08 AM
  3. help whats wrong
    By silverspoon34 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 3rd, 2009, 01:41 AM
  4. [SOLVED] whats wrong with my IDE
    By chronoz13 in forum Java IDEs
    Replies: 2
    Last Post: August 27th, 2009, 06:34 AM
  5. Generation of Palindrome number in Java
    By tina.goyal in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 26th, 2009, 08:49 AM