Can you fix my good/ bad day java program?
-
We had a tutorial in class it gave us code. I followed the code. Here is the program description and code. //************************************… Program Name: WhatDay.java Programmers Name: Desiree Carter Program Description: Click Good or Bad button. Get back good day for good button or bad day for bad button ****************************************… package w; import javax.swing.*; import java.awt.event.*; import java.awt.Container; import java.awt.*; // need this for layout manager public class WhatDay extends JFrame { private JFrame mainFrame; private JButton cmdGood; private JButton cmdBad; public WhatDay()// a constructot { mainFrame = new JFrame ("Messages"); // create the button objects cmdGood = new JButton("Good"); cmdBad = new JButton ("Bad"); //get the content pane & specify layout manager Container c = mainFrame.getContentPane(); c.setLayout(new FlowLayout()); // add the button to the ContentPane c.add(cmdGood); c.add(cmd.Bad); //create accelerator keys cmdGood.setMnemonic('G'); cmdBad.setMnemonic('B'); mainFrame.setSize(300,100); //define and register window event handler mainFrame.addWindowListener(new WindowAdapter() { public void windowClosing (WindowEvent e){System.exit(0);} }; // create and register a single buttpm event handler ButtonsHandler bhandler = new ButtonsHandler(); // instantiate a handler cmdGood.addActionListener(bhandler); // register the handler cmdBad.addActionListener(bhandler); // register the handler mainFrame.show(); } // inner class for the button event handler class ButtonsHandler implements ActionListener { public void actionPerformed(ActionEvent e) { if (e.getSource() == cmdGood) JOptionPane.showMessageDialog(null, "Today is a good day!"), "Event Handler Message", JOptionPane.INFORMATION_MESSAGE); else if (e.getSource() == cmdBad) JOptionPane.showMessageDialog(null, "I'm having a bad day today!"), "Event Handler Message",JOptionPane.INFORMATION_MESSAGE… } } // end of inner class public static void main(String args[]) { WhatDay app; // declare a WhatGui variable app = new WhatDay(); //instantiate a GUI object } }
-
Answer:
I'm not going to tell you what's wrong, I'm going to let you find out yourself!!! (that's better, the question shows you're still a student, so you'll need to learn :) -> download and install eclipse -> make a new java project (doesn't really matter how you name it) -> make a new class (this can be a bit of a challenge, but you will find your way) -> copy paste your code into the editor, or open your .java file in eclipse (might be easier) -> eclipse, friendly and patient as always, will aid you by marking everything you did wrong in red and why (I got 5 errors in your program, some of them hard to spot by a human) -> correct those errors by the use of your own smart young brain or the internetz :) done :) you're welcome :)
bamboomy at Yahoo! Answers Visit the source
Related Q & A:
- How can I make a Spinner only by java?Best solution by stackoverflow.com
- What is a good free video editing program?Best solution by Yahoo! Answers
- Creatine is it Good? Bad? Does it Work?Best solution by Yahoo! Answers
- What is a good one day family vacation?Best solution by Quora
- How to create this Java program?Best solution by ChaCha
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.