Advertisement
Guest User

Untitled

a guest
Mar 26th, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1.  
  2. import java.awt.*;
  3. import java.awt.event.ActionEvent;
  4. import java.awt.event.ActionListener;
  5. import javax.swing.*;
  6.  
  7. /*
  8. * To change this license header, choose License Headers in Project Properties.
  9. * To change this template file, choose Tools | Templates
  10. * and open the template in the editor.
  11. */
  12.  
  13. /**
  14. *
  15. * @author hilma
  16. */
  17. public class Reiknivel implements ActionListener {
  18. public static final Font BTN_FONT = new Font(Font.SANS_SERIF, Font.BOLD, 24);
  19. //Breytur
  20. JFrame frame;
  21. String frameTitle;
  22. JTextArea text;
  23. JPanel numpad;
  24. JPanel output;
  25.  
  26.  
  27. public Reiknivel() {
  28. frame = new JFrame("Reiknivél");
  29. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  30. numpad = new JPanel(new GridLayout(4,4));
  31. output = new JPanel();
  32. text = new JTextArea(1,25);
  33. JScrollPane scroll = new JScrollPane(text);
  34. text.setMargin(new Insets(0,0,0,0));
  35. frame.setLayout(new BorderLayout());
  36.  
  37.  
  38. String [] symbols = {"7","8","9","X","4","5","6","-","1","2","3","+","/","0",".","="};
  39. for (var symbol : symbols) {
  40. JButton button = new JButton(symbol);
  41. button.setFont(BTN_FONT);
  42. button.addActionListener(this);
  43. numpad.add(button);
  44. }
  45. output.add(text);
  46.  
  47. frame.add(output, BorderLayout.PAGE_START);
  48. frame.add(numpad, BorderLayout.CENTER);
  49. frame.pack();
  50. frame.show();
  51. }
  52.  
  53. public int calculate(){
  54. return 0;
  55. }
  56.  
  57. @Override
  58. public void actionPerformed(ActionEvent e) {
  59. String command = e.getActionCommand();
  60. if(command.equals("="){
  61. calculate();
  62. }
  63. text.append(command);
  64.  
  65.  
  66. }
  67. public static void main(String args[]) {
  68. Reiknivel e = new Reiknivel();
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement