I am following the examples from Java : The complete reference 8th edition (JDK 7)
on AWT and I cannot succeed to display a string on the window that appears. The size and title are set correctly and the window shows up. If I output a string on the console in the paint() method I see that it actually gets called a few times but the string does not appear on the window of my application. I can't see where I diverged from the example; I actually have a bit less code (they added a mouse listener and a key listener) :\
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class Main {
public static void main(String[] args) {
Application app = new Application();
app.setSize(new Dimension(640, 480));
app.setTitle("This is a test");
app.setVisible(true);
}
}
class MyWindowAdapter extends WindowAdapter {
public void windowClosing(WindowEvent we) {
System.exit(0);
}
}
class Application extends Frame {
public Application() {
addWindowListener(new MyWindowAdapter());
}
public void paint(Graphics g) {
System.out.println("Hey hey !");
g.drawString("Test", 10, 10);
}
}