Advertisement
Guest User

LEZGO2

a guest
Jan 18th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6.  
  7. /**
  8. *
  9. * @author 201812358
  10. */
  11. import javax.swing.*;
  12. import java.awt.GridLayout;
  13. import java.awt.event.*;
  14.  
  15. public class MainWindow extends JFrame implements ActionListener{
  16. private static final JButton BUTTON_ENTER = new JButton("ENTER");
  17. private static final JLabel LABEL_ENTER = new JLabel("<html>Following are the prime numbers<br/>smaller than or equal to:</html>", JLabel.CENTER);
  18. private static final JTextField TXT_FIELD_ENTER = new JTextField();
  19.  
  20. MainWindow(){
  21. super.setTitle("SOE GUI");
  22. super.setLayout(new GridLayout(0, 3));
  23. super.add(LABEL_ENTER); super.add(TXT_FIELD_ENTER); super.add(BUTTON_ENTER);
  24. super.setSize(600, 80);
  25. super.setVisible(true);
  26. super.setLocationRelativeTo(null);
  27. super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  28. BUTTON_ENTER.addActionListener(this);
  29. }
  30.  
  31. @Override
  32. public void actionPerformed(ActionEvent e) {
  33. if(e.getSource() == BUTTON_ENTER){
  34. int n = 0;
  35. try{
  36. n = Integer.parseInt(TXT_FIELD_ENTER.getText());
  37. }catch(Exception ex){
  38. System.out.println(ex);
  39. return;
  40. }
  41. new SOEGui(n);
  42. this.dispose();
  43.  
  44. }
  45. }
  46.  
  47. private class InvalidInputException extends Exception{
  48.  
  49. }
  50.  
  51. public static void main(String[] args) {
  52. new MainWindow();
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement