thorax232

Java Swing Panels Example

Jul 20th, 2013
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | None | 0 0
  1. import java.awt.*;
  2. import javax.swing.*;
  3.  
  4. public class TestPanels extends JFrame
  5. {
  6.     public TestPanels()
  7.     {
  8.         // Create panel p1 for the buttons and set GridLayout
  9.         JPanel p1 = new JPanel();
  10.         p1.setLayout(new GridLayout(4, 3));
  11.        
  12.         // Add buttons to the panel
  13.         for(int i = 1; i <= 9; i++)
  14.         {
  15.             p1.add(new JButton("" + i));
  16.         }
  17.        
  18.         p1.add(new JButton("" + 0));
  19.         p1.add(new JButton("Start"));
  20.         p1.add(new JButton("Stop"));
  21.        
  22.         // Create panel p2 to hold a text field and p1
  23.         JPanel p2 = new JPanel(new BorderLayout());
  24.         p2.add(new JTextField("Tiem to be displayed here"),
  25.                 BorderLayout.NORTH);
  26.         p2.add(p1, BorderLayout.CENTER);
  27.        
  28.         // Add contents to the frame
  29.         add(p2, BorderLayout.EAST);
  30.         add(new JButton("Food to be placed here"),
  31.                 BorderLayout.CENTER);
  32.     }
  33.    
  34.     // Main method
  35.     public static void main(String[] args)
  36.     {
  37.         TestPanels frame = new TestPanels();
  38.         frame.setTitle("The Front View of a Microwave Oven");
  39.         frame.setSize(400, 250);
  40.         frame.setLocationRelativeTo(null);
  41.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  42.         frame.setVisible(true);
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment