0% found this document useful (0 votes)
28 views2 pages

Awtgraphicsdemo Frame Awtgraphicsdemo: Package Import Import Event Import Public Class Extends Public Super

This document contains code for two Java classes that demonstrate using different fonts: 1. The AWTGraphicsDemo class creates a frame, sets its size, and overrides the paint method to draw the same string in different fonts (plain, italic, bold, bold-italic) at different y-coordinates. 2. The FontClass class extends Applet, sets the font to Arial italic size 20 in the init method, and draws the string "Welcome to Java" in green color in the paint method.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views2 pages

Awtgraphicsdemo Frame Awtgraphicsdemo: Package Import Import Event Import Public Class Extends Public Super

This document contains code for two Java classes that demonstrate using different fonts: 1. The AWTGraphicsDemo class creates a frame, sets its size, and overrides the paint method to draw the same string in different fonts (plain, italic, bold, bold-italic) at different y-coordinates. 2. The FontClass class extends Applet, sets the font to Arial italic size 20 in the init method, and draws the string "Welcome to Java" in green color in the paint method.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

package​ com​.​tutorialspoint​.

​gui​;

import​ java​.​awt​.*;
import​ java​.​awt​.​event​.*;
import​ java​.​awt​.​geom​.*;

public​ ​class​ ​AWTGraphicsDemo​ ​extends​ ​Frame​ ​{

​public​ ​AWTGraphicsDemo​(){
​super​(​"Java AWT Examples"​);
prepareGUI​();
​ }

​public​ ​static​ ​void​ main​(​String​[]​ args​){


​AWTGraphicsDemo​ awtGraphicsDemo ​=​ ​new​ ​AWTGraphicsDemo​();
awtGraphicsDemo​.​setVisible​(​true​);
​}

​private​ ​void​ prepareGUI​(){


setSize​(​400​,​400​);
addWindowListener​(​new​ ​WindowAdapter​()​ ​{
​public​ ​void​ windowClosing​(​WindowEvent​ windowEvent​){
​System​.​exit​(​0​);
​}
​});
​ }

​@Override
​public​ ​void​ paint​(​Graphics​ g​)​ ​{
​Graphics2D​ g2 ​=​ ​(​Graphics2D​)​g​;
​Font​ plainFont ​=​ ​new​ ​Font​(​"Serif"​,​ ​Font​.​PLAIN​,​ ​24​);
g2​.​setFont​(​plainFont​);
g2​.​drawString​(​"Welcome to TutorialsPoint"​,​ ​50​,​ ​70​);
​Font​ italicFont ​=​ ​new​ ​Font​(​"Serif"​,​ ​Font​.​ITALIC​,​ ​24​);
g2​.​setFont​(​italicFont​);
g2​.​drawString​(​"Welcome to TutorialsPoint"​,​ ​50​,​ ​120​);
​Font​ boldFont ​=​ ​new​ ​Font​(​"Serif"​,​ ​Font​.​BOLD​,​ ​24​);
g2​.​setFont​(​boldFont​);
g2​.​drawString​(​"Welcome to TutorialsPoint"​,​ ​50​,​ ​170​);
​Font​ boldItalicFont ​=​ ​new​ ​Font​(​"Serif"​,​ ​Font​.​BOLD​+​Font​.​ITALIC​,
24​);
g2​.​setFont​(​boldItalicFont​);
g2​.​drawString​(​"Welcome to TutorialsPoint"​,​ ​50​,​ ​220​);
​}
}
import ​java​.applet.Applet;
import java.awt.*;
import java.awt.event.*;
/* <APPLET CODE ="FontClass.class" WIDTH=300 HEIGHT=200> </APPLET> */
public class FontClass extends java.applet.Applet
{
Font f;
String m;
public void init()
{
f=new Font("Arial",Font.ITALIC,20);
m="Welcome to Java";
setFont(f);
}
public void paint(Graphics g)
{
Color c=new Color(0,255,0);
g.setColor(c);
g.drawString(m,4,20);
}
}

O/p:

You might also like