Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.*;
- public class main {
- public static void main(String[] args){
- // Frames
- JFrame mainFrame = new JFrame("It's the frame");
- // Panels
- JPanel panel = new JPanel();
- // Buttons
- JButton button1 = new JButton();
- JButton button2 = new JButton();
- JButton button3 = new JButton();
- JButton button4 = new JButton();
- // Frame
- mainFrame.setVisible(true);
- mainFrame.add(panel);
- mainFrame.setResizable(false);
- mainFrame.setSize(500, 150);
- // Panel
- panel.add(button1);
- panel.add(button2);
- panel.add(button3);
- panel.add(button4);
- // Button 1
- button1.setBackground(Color.RED);
- button1.setForeground(Color.RED);
- button1.setPreferredSize(new Dimension(100, 100));
- // Button 2
- button2.setBackground(Color.GREEN);
- button2.setForeground(Color.GREEN);
- button2.setPreferredSize(new Dimension(100, 100));
- // Button 3
- button3.setBackground(Color.BLUE);
- button3.setForeground(Color.BLUE);
- button3.setPreferredSize(new Dimension(100, 100));
- // Button 4
- button4.setBackground(Color.YELLOW);
- button4.setForeground(Color.YELLOW);
- button4.setPreferredSize(new Dimension(100, 100));
- // Pack it up
- mainFrame.pack();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment