MainClass.java Source code

Java tutorial

Introduction

Here is the source code for MainClass.java

Source

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;

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

public class MainClass {

    public static void main(String args[]) {
        JFrame frame = new JFrame("Focus Cycle Sample");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        frame.setLayout(new GridLayout(3, 3));

        for (int i = 0; i < 3; i++) {
            JButton button = new JButton("" + i);
            frame.add(button);
        }

        JPanel panel = new JPanel();
        panel.setFocusCycleRoot(true);
        panel.setFocusTraversalPolicyProvider(true);
        panel.setLayout(new GridLayout(1, 3));
        for (int i = 0; i < 3; i++) {
            JButton button = new JButton("" + (i + 3));
            panel.add(button);
        }
        frame.add(panel);

        for (int i = 0; i < 3; i++) {
            JButton button = new JButton("" + (i + 6));
            frame.add(button);
        }

        frame.setSize(300, 200);
        frame.setVisible(true);
    }
}