Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.30 KB | None | 0 0
  1. package HW;
  2. import javax.swing.*;
  3. import java.awt.*;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6.  
  7. public class GUI2 {
  8.    
  9.     public class GUI2 extends JFrame implements ActionListener {
  10.         FlowLayout flow = new FlowLayout();
  11.        
  12.         JButton b1 = new JButton("Abraham Lincoln");
  13.         JButton b2 = new JButton("Ronald Regan");
  14.         JButton b3 = new JButton("Jimmy Carter");
  15.         JButton b4 = new JButton("George Bush");
  16.         JButton b5 = new JButton("Bill Clinton");
  17.    
  18.     public GUI2() {
  19.         Container con = getContentPane();
  20.         con.setLayout(new BorderLayout());
  21.         con.add(b1, BorderLayout.NORTH);
  22.         con.add(b2, BorderLayout.CENTER);
  23.         con.add(b3, BorderLayout.WEST);
  24.         con.add(b4, BorderLayout.EAST);
  25.         con.add(b5, BorderLayout.SOUTH);
  26.         b1.addActionListener(new ActionListener());
  27.         b2.addActionListener(new ActionListener());
  28.         b3.addActionListener(new ActionListener());
  29.         b4.addActionListener(new ActionListener());
  30.         b5.addActionListener(new ActionListener());
  31.        
  32.     }
  33.     public static void main(String[] args) {// main method
  34.         GUI2 temp = new GUI2();
  35.         temp.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// close on x
  36.         temp.setSize(600, 300);// frame size
  37.         temp.setVisible(true);// make GUI visible  
  38.        
  39.     }
  40.     public void actionPerformed(ActionEvent e) {
  41.         System.exit(0);
  42.        
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement