Advertisement
Guest User

Java Pyramid

a guest
Jul 15th, 2013
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.95 KB | None | 0 0
  1. import java.awt.EventQueue;
  2.  
  3. import javax.swing.JFrame;
  4. import javax.swing.JButton;
  5. import javax.swing.JEditorPane;
  6. import java.awt.event.ActionListener;
  7. import java.awt.event.ActionEvent;
  8.  
  9.  
  10. public class a {
  11.  
  12.     public String building_1;
  13.     public String building_2;
  14.     public String building_3;
  15.     public String building_4;
  16.     public String building_5;
  17.     public JEditorPane showPyr;
  18.  
  19.     private JFrame Pyramid;
  20.     public static void main(String[] args) {
  21.         EventQueue.invokeLater(new Runnable() {
  22.             public void run() {
  23.                 try {
  24.                     a window = new a();
  25.                     window.Pyramid.setVisible(true);
  26.                 } catch (Exception e) {
  27.                     e.printStackTrace();
  28.                 }
  29.             }
  30.         });
  31.     }
  32.     public a() {
  33.         initialize();
  34.     }
  35.     private void initialize() {
  36.         Pyramid = new JFrame();
  37.         Pyramid.setResizable(false);
  38.         Pyramid.setTitle("Pyramid");
  39.         Pyramid.setBounds(100, 100, 250, 200);
  40.         Pyramid.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  41.         Pyramid.getContentPane().setLayout(null);
  42.  
  43.         building_1 = " ***** ";
  44.         building_2 = "  *****  \n ****** ";
  45.         building_3 = "   ***   \n  *****  \n ****** ";
  46.         building_4 = "     *    \n   ***   \n  *****  \n ****** ";
  47.        
  48.         JButton btnNewButton = new JButton("Start");
  49.         btnNewButton.addActionListener(new ActionListener() {
  50.             public void actionPerformed(ActionEvent arg0) {
  51.                 start_build();
  52.             }
  53.         });
  54.         btnNewButton.setBounds(62, 139, 122, 23);
  55.         Pyramid.getContentPane().add(btnNewButton);
  56.        
  57.         showPyr = new JEditorPane();
  58.         showPyr.setEditable(false);
  59.         showPyr.setBounds(0, 0, 242, 128);
  60.         Pyramid.getContentPane().add(showPyr);
  61.     }
  62.    
  63.     public void start_build(){
  64.         showPyr.setText("");
  65.         try {
  66.             Thread.sleep(1);
  67.             showPyr.setText(building_1);
  68.             Thread.sleep(1);
  69.             showPyr.setText(building_2);
  70.             Thread.sleep(1);
  71.             showPyr.setText(building_3);
  72.             Thread.sleep(1);
  73.             showPyr.setText(building_4);
  74.         } catch (InterruptedException e) {
  75.             // TODO Auto-generated catch block
  76.             e.printStackTrace();
  77.         }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement