Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Lv 2812 points

mathew

Favorite Answers18%
Answers146
  • Can someone tell me what is wrong with my Java program?

    I am using "Starting out with JAVA" by Tony Gaddis, and I'm putting in code directly from the book with my own alterations of course, otherwise it wouldn't be my own program. The way the book says to do it should technically be right, but when I try to build the program, it says that "public windows()" line needs a return type, but the book does not say to use return types for these.

    import javax.swing.*;

    import java.awt.*;

    import java.awt.event.*;

    public class Jokes extends JFrame

    {

    private JPanel panel;

    private JButton button;

    private JLabel joke;

    public windows() //ERROR IS HERE

    {

    setTitle("Jokes!");

    setSize(300, 500);

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    add(panel);

    buildPanel();

    setVisible(true);

    }

    private void buildPanel()

    {

    button = new JButton("Get Answer");

    button.addActionListener(new ButtonListener());

    joke = new JLabel("Why did the chicken cross the road?");

    panel = new JPanel();

    panel.add(button);

    panel.add(joke);

    }

    private class ButtonListener implements ActionListener

    {

    public void actionPerformed(ActionEvent e)

    {

    JOptionPane.showMessageDialog(null, "Because it was actually a rooster, and not a chicken.");

    }

    }

    public static void main(String[] args)

    {

    int answer = JOptionPane.showConfirmDialog(null, "Do you want to hear a joke?");

    if(answer == JOptionPane.YES_OPTION)

    new windows();

    if(answer == JOptionPane.NO_OPTION)

    JOptionPane.showMessageDialog(null, "Then why do you even bother to live?");

    }

    }

    1 AnswerProgramming & Design1 decade ago