Created
May 8, 2020 10:37
-
-
Save SiAust/0f20e4cb7a741b2f054986d9fdaa088c to your computer and use it in GitHub Desktop.
Creating a simple window in Java.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.*; | |
import java.awt.event.WindowAdapter; | |
import java.awt.event.WindowEvent; | |
public class AwtExample { | |
/*Abstract Window Toolkit Example */ | |
public static void main(String[] args) { | |
Awt window = new Awt("Test"); | |
window.setVisible(true); | |
} | |
} | |
class Awt extends Frame { | |
public Awt(String title) { | |
super(title); | |
setSize(500,400); | |
addWindowListener(new WindowAdapter() { | |
@Override | |
public void windowClosing(WindowEvent e) { | |
System.exit(0); | |
} | |
}); | |
} | |
@Override | |
public void paint(Graphics g) { | |
super.paint(g); | |
Font sansSerifLarge = new Font("SansSerif", Font.BOLD, 20); | |
Font sansSerifSmall = new Font("SansSerif", Font.BOLD, 12); | |
g.setFont(sansSerifLarge); | |
g.drawString(" Hello, world", 60, 60); | |
g.setFont(sansSerifSmall); | |
g.drawString("Lorem ipsum dolor", 60, 100); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment