MainClass.java Source code

Java tutorial

Introduction

Here is the source code for MainClass.java

Source

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

import javax.swing.Icon;
import javax.swing.JDesktopPane;
import javax.swing.JOptionPane;

public class MainClass {

    public static void main(String[] a) {
        Icon blueIcon = new MyIcon(Color.BLUE);
        Object stringArray[] = { "Do It", "No Way" };
        JOptionPane.showOptionDialog(new JDesktopPane(), "Continue printing?", "Select an Option",
                JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, blueIcon, stringArray, stringArray[0]);

    }
}

class MyIcon implements Icon {
    Color myColor;

    public MyIcon(Color myColor) {
        this.myColor = myColor;
    }

    public int getIconWidth() {
        return 16;
    }

    public int getIconHeight() {
        return 16;
    }

    public void paintIcon(Component c, Graphics g, int x, int y) {
        g.setColor(myColor);
        g.drawRect(0, 0, 16, 16);
    }
}