Induced Contrast GUI

Arman Majumder 0 Tallied Votes 299 Views Share

A simple GUI that tests the GridLayout function, multiple panels, and different coloured panels.

// Arman Majumder
// Induced Contrast GUI

   import java.awt.*;
   import java.awt.event.*;
   import java.util.*;
   import java.io.*;
   import javax.swing.*;
       
    class Illusion extends JPanel
   {
       public Illusion(Color backColor)
      {
         setBackground(backColor);
      }
      
       public void paintComponent(Graphics g)
      {
         super.paintComponent(g);     	
         g.setColor(Color.gray);  
         g.fillRect(50, 50, 100, 100);
            
      }
   }
      	
    public class InducedContrast
   {
       public static void main(String [] args)
      {
         JFrame theGUI = new JFrame();
         theGUI.setTitle("Induced Contrast");
         theGUI.setSize(400, 250);
         theGUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         
         Illusion panel = new Illusion(Color.black);
         JPanel panel1 = new Illusion(Color.black);
         panel1.setPreferredSize(new Dimension(200, 200));
         JPanel panel2 = new Illusion(Color.white);
      
         Container pane = theGUI.getContentPane();
         pane.setLayout(new GridLayout(1, 2));
         pane.add(panel1);
         pane.add(panel2);
      
         theGUI.setVisible(true);
      }
   }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.