0

I'm confuse on these questions, I was just wondering if anyone see if I'm doing them right.

If you want to create an effect like a rubber-band line, which changes continually with user input, you will most likely need a (an) A. MouseListener B. ActionListener C. MouseAdapter D. MouseMotionListener E. KeyListener

I think the answer is action listener because what ever the object is observing generate a action event.

Suppose a programmer creates a Java class named MyFrame which extends JFrame. Class MyFrame contains a single constructor whose body is empty. If an object of type MyFrame is created and made visible (but no other methods in the object are invoked), then when the user clicks on the “X” in the upper right corner of the window (frame),

A. the program will terminate

B. the window will be hidden but will still exist

C. the window will be closed

D. the window will be minimized (“iconified”)

E. the question cannot be answered because such a class cannot be compiled

F. the answer cannot be determined from the information given

Assuming I understood the questions right. So the class MyFram extends to JFrame. And my class MyFrame { } constructor is empty. I think it B, because it will compile, but may not doing any form of action assuming nothing is invoked at all.

Learning
  • 1
  • 2
  • What's a rubber-band line effect? – Oneiros Mar 16 '17 at 08:15
  • 1
    Ask your self this, what information would an `ActionListener` give you that would allow you to determine the start point and end point the selection area? – MadProgrammer Mar 16 '17 at 08:31
  • 1
    @Oneiros: A a rubber-band line is one way to effect a GUI selection rectangle; I've cited an example [here](http://stackoverflow.com/a/42829574/230513). – trashgod Mar 16 '17 at 09:13

2 Answers2

1

As you can read from official Java documentation, the default close operation for JFrame is HIDE_ON_CLOSE, so your answer is correct. Extending JFrame with MyFrame but using an empty constructor makes JFrame and MyFrame totally equivalent.

Oneiros
  • 4,328
  • 6
  • 40
  • 69
1

A MouseMotionListener, such as the MouseMotionHandler used during rubber band selection in the example cited here, allows the view to be updated in its implementation of mouseDragged().

private class MouseMotionHandler extends MouseMotionAdapter {
    …
    @Override
    public void mouseDragged(MouseEvent e) {
        …
        e.getComponent().repaint();
    }
}
Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045