Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test;
- import java.awt.*;
- import java.awt.event.*;
- import java.util.*;
- import javax.swing.*;
- public class Math_Problems {
- public static void main(String[] args) {
- JFrame frame = new JFrame("Square");
- frame.setSize(620, 620);
- frame.setLocationRelativeTo(null);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- JPanel panel = new JPanel();
- frame.getContentPane().setBackground(Color.RED);
- JButton red = new JButton("Red");
- red.setBounds(0,0, 200, 200);
- red.setForeground(Color.BLACK);
- red.setBackground(Color.RED);
- red.addMouseListener(new MouseAdapter() {
- public void mouseClicked(MouseEvent arg0) {
- panel.setBackground(Color.RED);
- }
- });
- JButton green = new JButton("Green");
- green.setBounds(210, 0, 200, 200);
- green.setBackground(Color.GREEN);
- green.setForeground(Color.BLACK);
- green.addMouseListener(new MouseAdapter() {
- public void mouseClicked(MouseEvent arg0) {
- panel.setBackground(Color.GREEN);
- }
- });
- JButton blue = new JButton("Blue");
- blue.setBounds(420, 0, 200, 200);
- blue.setBackground(Color.BLUE);
- blue.setForeground(Color.WHITE);
- blue.addMouseListener(new MouseAdapter() {
- public void mouseClicked(MouseEvent arg0) {
- panel.setBackground(Color.BLUE);
- }
- });
- JButton yellow =new JButton("Yellow");
- yellow.setBounds(0, 210, 200, 200);
- yellow.setBackground(Color.YELLOW);
- yellow.setForeground(Color.BLACK);
- JButton cyan = new JButton("Cyan");
- cyan.setBounds(210, 210, 200, 200);
- cyan.setBackground(Color.CYAN);
- cyan.setForeground(Color.BLACK);
- JButton magenta = new JButton("Magenta");
- magenta.setBounds(420, 210, 200, 200);
- magenta.setBackground(Color.MAGENTA);
- magenta.setForeground(Color.WHITE);
- JButton white = new JButton("white");
- white.setBackground(Color.WHITE);
- white.setBounds(0, 420, 200, 200);
- white.setForeground(Color.BLACK);
- JButton black = new JButton("black");
- black.setBounds(210, 420, 200, 200);
- black.setBackground(Color.BLACK);
- black.setForeground(Color.WHITE);
- JButton gray = new JButton("Gray");
- gray.setBounds(420, 420, 200, 200);
- gray.setBackground(Color.GRAY);
- gray.setForeground(Color.WHITE);
- panel.add(red);
- frame.add(red);
- frame.add(green);
- frame.add(blue);
- frame.add(yellow);
- frame.add(cyan);
- frame.add(magenta);
- frame.add(white);
- frame.add(black);
- frame.add(gray);
- frame.add(panel);
- frame.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement