User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 422,379 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,725 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Jun 13th, 2007
Views: 1,154
A simple GUI that tests the GridLayout function, multiple panels, and different coloured panels.
Last edited : Jun 13th, 2007.
java Syntax
  1. // Arman Majumder
  2. // Induced Contrast GUI
  3.  
  4. import java.awt.*;
  5. import java.awt.event.*;
  6. import java.util.*;
  7. import java.io.*;
  8. import javax.swing.*;
  9.  
  10. class Illusion extends JPanel
  11. {
  12. public Illusion(Color backColor)
  13. {
  14. setBackground(backColor);
  15. }
  16.  
  17. public void paintComponent(Graphics g)
  18. {
  19. super.paintComponent(g);
  20. g.setColor(Color.gray);
  21. g.fillRect(50, 50, 100, 100);
  22.  
  23. }
  24. }
  25.  
  26. public class InducedContrast
  27. {
  28. public static void main(String [] args)
  29. {
  30. JFrame theGUI = new JFrame();
  31. theGUI.setTitle("Induced Contrast");
  32. theGUI.setSize(400, 250);
  33. theGUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  34.  
  35. Illusion panel = new Illusion(Color.black);
  36. JPanel panel1 = new Illusion(Color.black);
  37. panel1.setPreferredSize(new Dimension(200, 200));
  38. JPanel panel2 = new Illusion(Color.white);
  39.  
  40. Container pane = theGUI.getContentPane();
  41. pane.setLayout(new GridLayout(1, 2));
  42. pane.add(panel1);
  43. pane.add(panel2);
  44.  
  45. theGUI.setVisible(true);
  46. }
  47. }
Post Comment

Only community members can submit or comment on code snippets. You must register or log in to contribute.

DaniWeb Marketplace (Sponsored Links)
All times are GMT -4. The time now is 8:33 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC