Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.awt.Color;
import java.awt.Graphics;

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

public class Main extends JPanel {

    public void paint(Graphics g) {
        int w = getSize().width;
        int midW = w / 2;

        g.drawString("XOR Mode", 0, 30);

        g.drawOval(7, 37, 50, 50);

        g.setXORMode(Color.white);

        for (int i = 0; i < 15; i += 3) {
            g.drawOval(10 + i, 40 + i, 50, 50);
        }

        g.setPaintMode();

        g.drawString("Paint Mode", midW, 30);

        g.drawOval(midW + 7, 37, 50, 50);

        for (int i = 0; i < 15; i += 3) {
            g.drawOval(midW + 10 + i, 40 + i, 50, 50);
        }
    }

    public static void main(String[] args) {
        JFrame frame = new JFrame();
        frame.add(new Main());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setBounds(20, 20, 500, 500);
        frame.setVisible(true);
    }
}