Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.*;
- public class Loop1 {
- public Loop1(){
- createLoop();
- }
- public void createLoop(){
- JFrame frame = new JFrame("Set Loop Size");
- frame.setVisible(true);
- frame.setSize(400, 400);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- JPanel panel = new JPanel();
- JButton btn = new JButton();
- btn.setText("Set Loop Size");
- btn.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- String loopSize = JOptionPane.showInputDialog("Enter Loop Size");
- int i = Integer.parseInt(loopSize);
- int k = 0;
- while(k < i){
- k += 1;
- JOptionPane.showMessageDialog(null, "Loop Number: " + k);
- }
- }
- });
- panel.add(btn);
- frame.add(panel);
- }
- public static void main(String args[]){
- new Loop1();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement