MainClass.java Source code

Java tutorial

Introduction

Here is the source code for MainClass.java

Source

import java.awt.Graphics;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class MainClass extends JPanel {

    public void paint(Graphics g) {
        g.drawString(g.getClipBounds().toString(), 10, 30);

        g.clipRect(10, 40, getSize().width - 20, getSize().height - 80);

        g.fillOval(0, 0, getSize().width, getSize().height);

        String newClip = g.getClipBounds().toString();

        g.setClip(0, 0, getSize().width, getSize().height);

        g.drawString(newClip, 10, getSize().height - 10);
    }

    public static void main(String[] args) {
        JFrame frame = new JFrame();
        frame.getContentPane().add(new MainClass());

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(200, 200);
        frame.setVisible(true);
    }
}