Here is my code:
package survival;
import javax.swing.*;
import java.awt.*;
public class Survival extends JFrame {
private static int applicationWidth = 1400;
private static int applicationHeight = 900;
public Survival() {
setTitle("Survival");
setResizable(false);
setSize(applicationWidth, applicationHeight);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void paint(Graphics g) {
g.drawString("Test", 0, 0);
}
public static void main(String[] args) {
new Survival();
}
}
Why isn't "Test" showing up?
Do not override paint. Whenever you customize a component, override paintComponent.
Example -
@Override
protected final void paintComponent(final Graphics g){
super.paintComponent(g);
final Graphics gCopy = g.create(); // Prevents clobbering
gCopy.drawString("Test", 0, 0);
gCopy.dispose();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With