@leeappelbaum/

Java Swing Test

Java Swing

No description

fork
loading
Files
  • Main.java
  • ColorPanel.class
  • ColorPanel.java
  • nohup.out
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import javax.swing.*;
import java.awt.*;
import java.util.Random;

public class Main
{
    public static void main (String[] args)
    {
        JFrame theGUI = new JFrame();
        theGUI.setTitle("Lots of Panels");
        String inputStr = JOptionPane.showInputDialog("Number of rows: ", "5");
        if (inputStr == null) return;
        int rows = Integer.parseInt(inputStr);
        inputStr = JOptionPane.showInputDialog("Number of cols: ", "5");
        if (inputStr == null) return;
        int cols = Integer.parseInt(inputStr);
        theGUI.setSize(50*cols, 50*rows);
        theGUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Container pane = theGUI.getContentPane();
        pane.setLayout(new GridLayout(rows, cols));
        Random gen = new Random();
        for (int i = 1; i <= rows*cols; i++)
        {
            int red = gen.nextInt(256);
            int green = gen.nextInt(256);
            int blue = gen.nextInt(256);
            Color bgcolor = new Color(red, green, blue);
            ColorPanel panel = new ColorPanel(bgcolor);
            pane.add(panel);
        }
        theGUI.setVisible(true);
    }
}