// Example.java

import javax.swing.JFrame; 

public class Example extends JFrame {
  public Example() {
    this.add(new Screen()); 
  }
  public static void main(String[] args) {
    JFrame f = new Example(); 
    f.setVisible(true); 
    f.setSize(200, 300); 
  }
}

// Screen.java

import javax.swing.JComponent; 
import java.awt.Graphics; 

public class Screen extends JComponent {
  int i = 0; 
  public void paintComponent(Graphics g) {
    this.i += 1; 
    System.out.println(i + ": How are you?"); 
  }
}

Compile and run.

  Kirk Mitchell Mitch 

  Nicholas Menghan Jordan Joshua Alex 

  Chad Chetan Younghun Yuanyuan Tianqi 

  Tobias Clarence Rui Elizabeth Sarah Magdalena Yixuan 

  Ben Skylar Max Levi Chris Chris 
 
  Quinton Nova Olivia Graham Kendall 

  Justin Kyle Derek Leanne Kyle Jiahao Yiqing 
 
// Example.java

import javax.swing.JFrame; 
import java.awt.event.KeyListener;
import java.awt.event.KeyEvent; 

public class Example extends JFrame implements KeyListener {

  public void keyPressed(KeyEvent e) { 
    System.out.println( e ); 
  }
  public void keyReleased(KeyEvent e) { }
  public void keyTyped(KeyEvent e) { }

  public Example() {
    this.add(new Screen()); 
    this.addKeyListener( this ); 
  }
  public static void main(String[] args) {
    JFrame f = new Example(); 
    f.setVisible(true); 
    f.setSize(200, 300); 
  }
}

// Screen.java

import javax.swing.JComponent; 
import java.awt.Graphics; 

public class Screen extends JComponent {
  int i = 0; 
  public void paintComponent(Graphics g) {
    this.i += 1; 
    System.out.println(i + ": How are you?"); 
  }
}

------------------------------


import javax.swing.JComponent; 
import java.awt.Graphics; 
import java.awt.event.MouseMotionListener; 
import java.awt.event.MouseEvent; 

public class Screen extends JComponent implements MouseMotionListener {

  public Screen() {
    this.addMouseMotionListener( this ); 
  }

  public void mouseMoved(MouseEvent e) { } 
  public void mouseDragged(MouseEvent e) { 
    System.out.println("Mouse dragged at: (" + e.getX() + ", " + e.getY() + ")"); 
  } 

  int i = 0; 
  public void paintComponent(Graphics g) {
    this.i += 1; 
    System.out.println(i + ": How are you?"); 
  }
}

import javax.swing.JFrame; 
import java.awt.event.KeyListener;
import java.awt.event.KeyEvent; 

public class Example extends JFrame implements KeyListener {

  public void keyPressed(KeyEvent e) { 
    System.out.println( e ); 
  }
  public void keyReleased(KeyEvent e) { }
  public void keyTyped(KeyEvent e) { }

  public Example() {
    this.add(new Screen()); 
    this.addKeyListener( this ); 
  }
  public static void main(String[] args) {
    JFrame f = new Example(); 
    f.setVisible(true); 
    f.setSize(200, 300); 
  }
}


import javax.swing.JFrame; 
import java.awt.event.KeyListener;
import java.awt.event.KeyEvent; 

public class Example extends JFrame implements KeyListener {

  public void keyPressed(KeyEvent e) { 
    System.out.println( e ); 
  }
  public void keyReleased(KeyEvent e) { }
  public void keyTyped(KeyEvent e) { }

  public Example() {
    this.add(new Screen()); 
    this.addKeyListener( this ); 
  }
  public static void main(String[] args) {
    JFrame f = new Example(); 
    f.setVisible(true); 
    f.setSize(200, 300); 
  }
}

import javax.swing.JComponent; 
import java.awt.Graphics; 
import java.awt.event.MouseMotionListener; 
import java.awt.event.MouseEvent; 

public class Screen extends JComponent implements MouseMotionListener {
  int x, y; 
  public Screen() {
    this.addMouseMotionListener( this ); 
  }
  public void mouseMoved(MouseEvent e) { } 
  public void mouseDragged(MouseEvent e) { 
    x = e.getX(); 
    y = e.getY(); 
    System.out.println("Mouse dragged at: (" + e.getX() + ", " + e.getY() + ")"); 
    repaint(); 
  } 

  int i = 0; 
  public void paintComponent(Graphics g) {
    this.i += 1; 
    System.out.println(i + ": How are you?"); 
    g.drawString( "(" + x + ", " + y + ")", x, y ); 
  }
}

--