Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.*;
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author hilma
- */
- public class Reiknivel implements ActionListener {
- public static final Font BTN_FONT = new Font(Font.SANS_SERIF, Font.BOLD, 24);
- //Breytur
- JFrame frame;
- String frameTitle;
- JTextArea text;
- JPanel numpad;
- JPanel output;
- public Reiknivel() {
- frame = new JFrame("Reiknivél");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- numpad = new JPanel(new GridLayout(4,4));
- output = new JPanel();
- text = new JTextArea(1,25);
- JScrollPane scroll = new JScrollPane(text);
- text.setMargin(new Insets(0,0,0,0));
- frame.setLayout(new BorderLayout());
- String [] symbols = {"7","8","9","X","4","5","6","-","1","2","3","+","/","0",".","="};
- for (var symbol : symbols) {
- JButton button = new JButton(symbol);
- button.setFont(BTN_FONT);
- button.addActionListener(this);
- numpad.add(button);
- }
- output.add(text);
- frame.add(output, BorderLayout.PAGE_START);
- frame.add(numpad, BorderLayout.CENTER);
- frame.pack();
- frame.show();
- }
- public int calculate(){
- return 0;
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- String command = e.getActionCommand();
- if(command.equals("="){
- calculate();
- }
- text.append(command);
- }
- public static void main(String args[]) {
- Reiknivel e = new Reiknivel();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement