Advertisement
TermSpar

GUI For Loop

Feb 18th, 2016
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  1. import java.awt.event.ActionEvent;
  2. import java.awt.event.ActionListener;
  3.  
  4. import javax.swing.*;
  5.  
  6. public class mySelf2 {
  7.     public mySelf2(){
  8.         frame();
  9.     }
  10.    
  11.     public void frame(){
  12.         JFrame frame = new JFrame("Test");
  13.         frame.setSize(500, 500);
  14.         frame.setVisible(true);
  15.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  16.        
  17.         JPanel panel = new JPanel();
  18.         panel.setLayout(null);
  19.        
  20.        
  21.         JButton btn = new JButton("This is a button");
  22.         btn.setBounds(168, 150, 120, 35);
  23.         btn.addActionListener(new ActionListener(){
  24.  
  25.             public void actionPerformed(ActionEvent e){
  26.                 int i;
  27.                 for (i = 1; i < 6; i++){
  28.                     JOptionPane.showMessageDialog(null, "Test " + i);
  29.                 }
  30.             }
  31.         });
  32.        
  33.         panel.add(btn);
  34.         frame.add(panel);
  35.     }
  36.    
  37.     public static void main(String args[]){
  38.         new mySelf2();
  39.     }
  40.    
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement