Advertisement
Dubwyn

Spaghetti solution

Aug 24th, 2019
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.51 KB | None | 0 0
  1. package test;
  2.  
  3. import java.awt.*;
  4. import java.awt.event.*;
  5. import java.util.*;
  6. import javax.swing.*;
  7.  
  8. public class Math_Problems {
  9.     public static void main(String[] args) {
  10.  
  11.         JFrame frame = new JFrame("Square");
  12.         frame.setSize(620, 620);
  13.         frame.setLocationRelativeTo(null);
  14.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  15.        
  16.         JPanel panel = new JPanel();
  17.         frame.getContentPane().setBackground(Color.RED);
  18.  
  19.  
  20.  
  21.  
  22.         JButton red = new JButton("Red");
  23.         red.setBounds(0,0, 200, 200);      
  24.         red.setForeground(Color.BLACK);
  25.         red.setBackground(Color.RED);
  26.         red.addMouseListener(new MouseAdapter() {
  27.             public void mouseClicked(MouseEvent arg0) {
  28.             panel.setBackground(Color.RED);
  29.             }
  30.             });
  31.  
  32.         JButton green = new JButton("Green");
  33.         green.setBounds(210, 0, 200, 200);
  34.         green.setBackground(Color.GREEN);
  35.         green.setForeground(Color.BLACK);
  36.         green.addMouseListener(new MouseAdapter() {
  37.             public void mouseClicked(MouseEvent arg0) {
  38.             panel.setBackground(Color.GREEN);
  39.             }
  40.             });
  41.  
  42.         JButton blue = new JButton("Blue");
  43.         blue.setBounds(420, 0, 200, 200);
  44.         blue.setBackground(Color.BLUE);
  45.         blue.setForeground(Color.WHITE);
  46.         blue.addMouseListener(new MouseAdapter() {
  47.             public void mouseClicked(MouseEvent arg0) {
  48.             panel.setBackground(Color.BLUE);
  49.             }
  50.             });
  51.  
  52.         JButton yellow =new JButton("Yellow");
  53.         yellow.setBounds(0, 210, 200, 200);
  54.         yellow.setBackground(Color.YELLOW);
  55.         yellow.setForeground(Color.BLACK);
  56.  
  57.         JButton cyan = new JButton("Cyan");
  58.         cyan.setBounds(210, 210, 200, 200);
  59.         cyan.setBackground(Color.CYAN);
  60.         cyan.setForeground(Color.BLACK);
  61.  
  62.         JButton magenta = new JButton("Magenta");
  63.         magenta.setBounds(420, 210, 200, 200);
  64.         magenta.setBackground(Color.MAGENTA);
  65.         magenta.setForeground(Color.WHITE);
  66.  
  67.  
  68.         JButton white = new JButton("white");
  69.         white.setBackground(Color.WHITE);
  70.         white.setBounds(0, 420, 200, 200);
  71.         white.setForeground(Color.BLACK);
  72.  
  73.         JButton black = new JButton("black");
  74.         black.setBounds(210, 420, 200, 200);
  75.         black.setBackground(Color.BLACK);
  76.         black.setForeground(Color.WHITE);
  77.  
  78.         JButton gray = new JButton("Gray");
  79.         gray.setBounds(420, 420, 200, 200);
  80.         gray.setBackground(Color.GRAY);
  81.         gray.setForeground(Color.WHITE);
  82.        
  83.         panel.add(red);
  84.  
  85.         frame.add(red);
  86.         frame.add(green);
  87.         frame.add(blue);       
  88.         frame.add(yellow);
  89.         frame.add(cyan);
  90.         frame.add(magenta);
  91.         frame.add(white);
  92.         frame.add(black);
  93.         frame.add(gray);
  94.        
  95.        
  96.         frame.add(panel);
  97.        
  98.        
  99.        
  100.        
  101.        
  102.  
  103.         frame.setVisible(true);
  104.  
  105.  
  106.  
  107.         }
  108.  
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement