TotteL

JFrame

Oct 16th, 2014
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.39 KB | None | 0 0
  1. package main;
  2.  
  3. import java.awt.*;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6.  
  7. import javax.swing.*;
  8.  
  9. public class main {
  10.    
  11.     public static void main(String[] args){
  12.  
  13.         // Frames
  14.        
  15.         JFrame mainFrame = new JFrame("It's the frame");
  16.        
  17.         // Panels
  18.        
  19.         JPanel panel = new JPanel();
  20.        
  21.         // Buttons
  22.        
  23.         JButton button1 = new JButton();
  24.         JButton button2 = new JButton();
  25.         JButton button3 = new JButton();
  26.         JButton button4 = new JButton();
  27.        
  28.         // Frame
  29.         mainFrame.setVisible(true);
  30.         mainFrame.add(panel);
  31.         mainFrame.setResizable(false);
  32.         mainFrame.setSize(500, 150);
  33.        
  34.         // Panel
  35.        
  36.         panel.add(button1);
  37.         panel.add(button2);
  38.         panel.add(button3);
  39.         panel.add(button4);
  40.        
  41.         // Button 1
  42.        
  43.         button1.setBackground(Color.RED);
  44.         button1.setForeground(Color.RED);
  45.         button1.setPreferredSize(new Dimension(100, 100));
  46.        
  47.         // Button 2
  48.        
  49.         button2.setBackground(Color.GREEN);
  50.         button2.setForeground(Color.GREEN);
  51.         button2.setPreferredSize(new Dimension(100, 100));
  52.        
  53.         // Button 3
  54.        
  55.         button3.setBackground(Color.BLUE);
  56.         button3.setForeground(Color.BLUE);
  57.         button3.setPreferredSize(new Dimension(100, 100));
  58.        
  59.         // Button 4
  60.        
  61.         button4.setBackground(Color.YELLOW);
  62.         button4.setForeground(Color.YELLOW);
  63.         button4.setPreferredSize(new Dimension(100, 100));
  64.        
  65.         // Pack it up
  66.        
  67.         mainFrame.pack();
  68.        
  69.         }
  70.     }
Advertisement
Add Comment
Please, Sign In to add comment