Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.image.BufferedImage;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class Main {
    public static void main(String[] args) {
        JPanel gui = new JPanel(new BorderLayout(2, 2));
        BufferedImage bi = new BufferedImage(600, 200, BufferedImage.TYPE_INT_RGB);
        gui.add(new JLabel(new ImageIcon(bi)));

        JFrame myframe = new JFrame();
        JPanel myPanel = new JPanel();
        gui.add(myPanel, BorderLayout.PAGE_END);
        myPanel.setLayout(new GridLayout(2, 0, 0, 0));

        int x = 0;
        int y = 5;

        for (char alphabet = 'A'; alphabet <= 'Z'; alphabet++) {
            myPanel.add(new JButton(alphabet + ""));
            x++;
            if (x > 15) {
                y = 6;
                x = 0;
            }
        }
        myframe.add(gui);
        myframe.pack();
        myframe.setVisible(true);

        myframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}