Introduction to Graphical User Interfaces (GUIs)

 

Basic Applet Code – Draws A Rectangle

import java.applet.Applet;

import java.awt.*;

public class rect extends Applet

{

    public void paint (Graphics g)

    {

        //Program code goes here

        g.setColor (Color.blue);

        g.drawRect (200, 200, 100, 100);

    }

}

Some Graphics Methods To Put in void Paint

g.setColor(Color.red);

g.drawstring("Hello World", 75, 100);

g.drawRect(1,1, 200, 400);

g.fillRect(1,1,200,400);

g.drawOval(50,50, 20, 30);

g.fillOval(50,50,20,30);

g.drawPolygon(Xarray, Yarray, NumPoints);

g.fillPolygon(Xarray, Yarray, NumPoints);

 

 

Void Main (Text Based User Interface)

You already know this mode, we used it in unit 1:

String c = IBIO.inputString(“Please enter your name”);

int j = IBIO.inputInt(“Please enter the year”);

 

Applets (GUI)

Applets are ‘little applications’. You can post them on your webpage. 

To get one:

Note these differences from the text based programs we wrote before:

Applets need extends Applet on the end of the class declaration line.

Applets have certain predefined methods that you should use.