Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. package alex.lesson5;
  2.  
  3. import javax.swing.*;
  4. import java.awt.*;
  5. import java.util.ArrayList;
  6.  
  7. public class Main {
  8.  
  9. public static String[] functions = {
  10. "+", "-", "*", "/",
  11. "a", "b", "c", "d",
  12. "e", "f", "g", " "
  13. };
  14. public static String[] digits = {
  15. "1", "2", "3", "4",
  16. "5", "6", "7", "8",
  17. "9", "0", ".", " "
  18. };
  19.  
  20. public static void main(String[] args) {
  21. JFrame frame = new JFrame();
  22. frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  23. frame.setBounds(100, 100, 385, 240);
  24. frame.setLayout(null);
  25.  
  26. // ArrayList<JButton> digits = new ArrayList<JButton>();
  27.  
  28. Container container = frame.getContentPane();
  29.  
  30. JTextField field = new JTextField();
  31. field.setBounds(5, 5, 365, 30);
  32. container.add(field);
  33. for ( int j = 0; j < 4; j++) {
  34. for (int i = 0; i < 3; i++) {
  35. //String str = Integer.toString(i + 1 + j * 3);
  36. String str = digits[i + j * 3];
  37. JButton button = new JButton(str);
  38. button.setBounds(5 + i * 60, 45 + j * 40, 50, 30);
  39. container.add(button);
  40. }
  41. }
  42.  
  43. for ( int j = 0; j < 4; j++) {
  44. for (int i = 0; i < 3; i++) {
  45. String str = functions[i + j * 3];
  46. JButton button = new JButton(str);
  47. button.setBounds(200 + i * 60, 45 + j * 40, 50, 30);
  48. container.add(button);
  49. }
  50. }
  51.  
  52. frame.setVisible(true);
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement