Java Graphics Libraries (AWT and Swing)

java.awt.Graphics java.awt.event java.awt.Container javax.swing.JFrame javax.swing.JButton

10 flashcards · Programming Languages · by lakesare

  1. drawOval(int x, int y, int width, int height) fillOval(int x, int y, int width, int height) What is the difference between these 2 methods?

    g.drawOval() - Draws the perimeter of an oval. g.fillOval() - Draws the perimeter and fills an oval with the current color.

  2. drawOval(int x, int y, int width, int height) fillOval(int x, int y, int width, int height) What do x and y refer to?

    x - the x coordinate of the upper left corner of the oval to be drawn. y - the y coordinate of the upper left corner of the oval to be drawn.

  3. What javax.swing.JFrame is used for?

    Creates window of some size, buttons (JButton), text inputs (JTextField).

  4. What does java.awt stand for?

    awt - Abstract Window Toolkit

  5. java.awt VS java.swing?

    Swing was developed to provide a more sophisticated set of GUI components than the earlier Abstract Window Toolkit (AWT). Swing provides a look and feel that emulates the look and feel of several platforms, and also supports a pluggable look and feel that allows applications to have a look and feel unrelated to the underlying platform. It has more powerful and flexible components than AWT. In addition to familiar components such as buttons, check boxes and labels, Swing provides several advance…

  6. JFrame frame = new JFrame(); How to get a Container of this frame?

    Container container = frame.getContentPane()

  7. import javax.swing.JPanel; class Panel extends JPanel{} panel = new Panel(); What method will be called on panel.repaint()?

    paintComponent(Graphics g): class Panel extends JPanel{ public void paintComponent(Graphics g) {} } When we want to draw our own graphics on the screen, we should put our graphics code inside the paintComponent() method. But we never call this method directly. The system calls it.However, we can ask the system to refresh the display by calling repaint(). The repaint() call eventually leads to paintComponent() being called. import javax.swing.JPanel; class Rrr extends JPanel{ public void paintCo…

  8. How to stop execution of the java script for 3 seconds?

    Thread.sleep(3000); Thread.sleep() suspends the current thread for N milliseconds.

  9. JButton myButton = new JButton("Click me."); How to change text of the button onClick (3 steps)?

    myButton.addActionListener(new ButtonListener()); class ButtonListener implements ActionListener{} with the method actionPerformed(){} import javax.swing.JButton; import java.awt.event.ActionListener; JButton myButton = new JButton("Click me."); myButton.addActionListener(new ButtonListener()) public class ButtonListener implements ActionListener{ public void actionPerformed(ActionEvent event) { myButton.setText("I've been clicked!"); } }

  10. Every content pane is initialized to use a BorderLayout. How many areas does it have?

    5 BorderLayout constants: PAGE_START PAGE_END LINE_START LINE_END CENTER ...//Container pane = aFrame.getContentPane()... JButton button = new JButton("Button 1 (PAGE_START)"); pane.add(button, BorderLayout.PAGE_START);