fork download
  1. import java.awt.*;
  2. import javax.swing.*;
  3. import java.awt.event.*;
  4. import java.util.*;
  5. import java.util.stream.Stream;
  6.  
  7. public class Dentaku extends JFrame implements ActionListener{
  8.     public static void main(String[] args) {
  9.         new Dentaku();
  10.     }
  11.  
  12.     JTextField result = new JTextField("");
  13.  
  14.     JPanel buttonarea = new JPanel(new GridLayout(4,4));
  15.     ArrayList<JButton> buttons = new ArrayList<JButton>();
  16.     JButton tasuButton = new JButton("+");
  17.     JButton hikuButton = new JButton("-");
  18.     JButton kakeButton = new JButton("×");
  19.     JButton wariButton = new JButton("÷");
  20.     JButton equalButton = new JButton("=");
  21.     JButton clearButton = new JButton("C");
  22.  
  23.     int beforeNum = 0;
  24.     Integer dispNum = null;
  25.     String op = "";
  26.  
  27.     JButton  button7,button8,button9,buttonwaru,button4,button5,button6,buttonkake;
  28.     JButton button1,button2,button3,buttonhiku,buttonclear,button0,buttontasu,buttonequal;
  29.  
  30.     Dentaku(){
  31.         String[] keys = {
  32.             "7","8","9","÷",
  33.             "4","5","6","×",
  34.             "1","2","3","-",
  35.             "C","0","+","="
  36.         };
  37.  
  38.         Stream.of(keys).forEach(-> {
  39.             JButton button = new JButton(x);
  40.             button.addActionListener(this);
  41.             buttonarea.add(button);
  42.             buttons.add(button);
  43.         });
  44.  
  45.         //コンテナに追加
  46.         add(result);
  47.         add(buttonarea);
  48.         
  49.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  50.         setSize(280320);
  51.         setVisible(true);
  52.         setResizable(false);
  53.         setLayout(new GridLayout(2,1));
  54.         result.setFont(new Font("Arial"Font.PLAIN40));
  55.         result.setHorizontalAlignment(JTextField.RIGHT);
  56.     }
  57.  
  58.     @Override
  59.     public void actionPerformed(ActionEvent e){
  60.         //選択されたボタンごとに処理をする
  61.         JButton selectedButton = (JButton)e.getSource();
  62.  
  63.         try{
  64.         //数値ボタンが選択された場合
  65.             if(buttons.contains(selectedButton)){
  66.                 if(dispNum == null){
  67.                     dispNum = Integer.valueOf(selectedButton.getText());
  68.                 }
  69.                 else{
  70.                     dispNum = Integer.valueOf(String.valueOf(dispNum) + selectedButton.getText());
  71.                 }
  72.                 result.setText(String.valueOf(dispNum));
  73.             }
  74.         }
  75.         catch(NumberFormatException ex){
  76.             //"+"が選択された場合
  77.             if((selectedButton.getText()).equals("+")){
  78.                 op = "+";
  79.                 result.setText(String.valueOf(dispNum));
  80.                 beforeNum = dispNum;
  81.                 dispNum = 0;
  82.             }
  83.             //"-"が選択された場合
  84.             else if((selectedButton.getText()).equals("-")){
  85.                 op = "-";
  86.                 result.setText(String.valueOf(dispNum));
  87.                 beforeNum = dispNum;
  88.                 dispNum = 0;
  89.             }
  90.             //"×"が選択された場合
  91.             else if((selectedButton.getText()).equals("×")){
  92.                 op = "×";
  93.                 result.setText(String.valueOf(dispNum));
  94.                 beforeNum = dispNum;
  95.                 dispNum = 0;
  96.             }
  97.             //"÷"が選択された場合
  98.             else if((selectedButton.getText()).equals("÷")){
  99.                 op = "÷";
  100.                 result.setText(String.valueOf(dispNum));
  101.                 beforeNum = dispNum;
  102.                 dispNum = 0;
  103.             }
  104.             //"="が選択された場合
  105.             else if((selectedButton.getText()).equals("=")){
  106.                 if(op.equals("+")){
  107.                     dispNum = dispNum + beforeNum;
  108.                     result.setText((String.valueOf(dispNum)));
  109.                     beforeNum = dispNum;
  110.                     dispNum = 0;
  111.                     op = "";    //演算子クリア
  112.                 }
  113.                 else if(op.equals("-")){
  114.                     dispNum = beforeNum - dispNum;
  115.                     result.setText((String.valueOf(dispNum)));
  116.                     beforeNum = dispNum;
  117.                     dispNum = 0;
  118.                     op = "";
  119.                 }
  120.                 else if(op.equals("×")){
  121.                     dispNum = dispNum * beforeNum;
  122.                     result.setText((String.valueOf(dispNum)));
  123.                     beforeNum = dispNum;
  124.                     dispNum = 0;
  125.                     op = "";
  126.                 }
  127.                 else if(op.equals("÷")){
  128.                     dispNum = beforeNum / dispNum;
  129.                     result.setText((String.valueOf(dispNum)));
  130.                     beforeNum = dispNum;
  131.                     dispNum = 0;
  132.                     op = "";
  133.                 }
  134.             }
  135.             if((selectedButton.getText()).equals("C")){
  136.                 dispNum = 0;
  137.                 beforeNum = 0;
  138.                 op = "";
  139.                 result.setText("");
  140.             }
  141.         }
  142.     }
  143. }
  144.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: illegal character: '\u00a0'
import?java.awt.*;
      ^
Main.java:2: error: illegal character: '\u00a0'
import?javax.swing.*;
      ^
Main.java:3: error: illegal character: '\u00a0'
import?java.awt.event.*;
      ^
Main.java:4: error: illegal character: '\u00a0'
import?java.util.*;
      ^
Main.java:5: error: illegal character: '\u00a0'
import?java.util.stream.Stream;
      ^
Main.java:7: error: illegal character: '\u00a0'
public?class?Dentaku?extends?JFrame?implements?ActionListener{
      ^
Main.java:7: error: illegal character: '\u00a0'
public?class?Dentaku?extends?JFrame?implements?ActionListener{
            ^
Main.java:7: error: illegal character: '\u00a0'
public?class?Dentaku?extends?JFrame?implements?ActionListener{
                    ^
Main.java:7: error: illegal character: '\u00a0'
public?class?Dentaku?extends?JFrame?implements?ActionListener{
                            ^
Main.java:7: error: illegal character: '\u00a0'
public?class?Dentaku?extends?JFrame?implements?ActionListener{
                                   ^
Main.java:7: error: illegal character: '\u00a0'
public?class?Dentaku?extends?JFrame?implements?ActionListener{
                                              ^
Main.java:7: error: class, interface, or enum expected
public?class?Dentaku?extends?JFrame?implements?ActionListener{
                                                             ^
Main.java:8: error: illegal character: '\u00a0'
????public?static?void?main(String[]?args)?{
^
Main.java:8: error: illegal character: '\u00a0'
????public?static?void?main(String[]?args)?{
 ^
Main.java:8: error: illegal character: '\u00a0'
????public?static?void?main(String[]?args)?{
  ^
Main.java:8: error: illegal character: '\u00a0'
????public?static?void?main(String[]?args)?{
   ^
Main.java:8: error: illegal character: '\u00a0'
????public?static?void?main(String[]?args)?{
          ^
Main.java:8: error: illegal character: '\u00a0'
????public?static?void?main(String[]?args)?{
                 ^
Main.java:8: error: illegal character: '\u00a0'
????public?static?void?main(String[]?args)?{
                      ^
Main.java:8: error: class, interface, or enum expected
????public?static?void?main(String[]?args)?{
                           ^
Main.java:8: error: illegal character: '\u00a0'
????public?static?void?main(String[]?args)?{
                                    ^
Main.java:8: error: illegal character: '\u00a0'
????public?static?void?main(String[]?args)?{
                                          ^
Main.java:9: error: illegal character: '\u00a0'
????????new?Dentaku();
^
Main.java:9: error: illegal character: '\u00a0'
????????new?Dentaku();
 ^
Main.java:9: error: illegal character: '\u00a0'
????????new?Dentaku();
  ^
Main.java:9: error: illegal character: '\u00a0'
????????new?Dentaku();
   ^
Main.java:9: error: illegal character: '\u00a0'
????????new?Dentaku();
    ^
Main.java:9: error: illegal character: '\u00a0'
????????new?Dentaku();
     ^
Main.java:9: error: illegal character: '\u00a0'
????????new?Dentaku();
      ^
Main.java:9: error: illegal character: '\u00a0'
????????new?Dentaku();
       ^
Main.java:9: error: illegal character: '\u00a0'
????????new?Dentaku();
           ^
Main.java:10: error: illegal character: '\u00a0'
????}
^
Main.java:10: error: illegal character: '\u00a0'
????}
 ^
Main.java:10: error: illegal character: '\u00a0'
????}
  ^
Main.java:10: error: illegal character: '\u00a0'
????}
   ^
Main.java:10: error: class, interface, or enum expected
????}
    ^
Main.java:12: error: illegal character: '\u00a0'
????JTextField?result?=?new?JTextField("");
^
Main.java:12: error: illegal character: '\u00a0'
????JTextField?result?=?new?JTextField("");
 ^
Main.java:12: error: illegal character: '\u00a0'
????JTextField?result?=?new?JTextField("");
  ^
Main.java:12: error: illegal character: '\u00a0'
????JTextField?result?=?new?JTextField("");
   ^
Main.java:12: error: illegal character: '\u00a0'
????JTextField?result?=?new?JTextField("");
              ^
Main.java:12: error: illegal character: '\u00a0'
????JTextField?result?=?new?JTextField("");
                     ^
Main.java:12: error: illegal character: '\u00a0'
????JTextField?result?=?new?JTextField("");
                       ^
Main.java:12: error: illegal character: '\u00a0'
????JTextField?result?=?new?JTextField("");
                           ^
Main.java:14: error: illegal character: '\u00a0'
????JPanel?buttonarea?=?new?JPanel(new?GridLayout(4,4));
^
Main.java:14: error: illegal character: '\u00a0'
????JPanel?buttonarea?=?new?JPanel(new?GridLayout(4,4));
 ^
Main.java:14: error: illegal character: '\u00a0'
????JPanel?buttonarea?=?new?JPanel(new?GridLayout(4,4));
  ^
Main.java:14: error: illegal character: '\u00a0'
????JPanel?buttonarea?=?new?JPanel(new?GridLayout(4,4));
   ^
Main.java:14: error: illegal character: '\u00a0'
????JPanel?buttonarea?=?new?JPanel(new?GridLayout(4,4));
          ^
Main.java:14: error: illegal character: '\u00a0'
????JPanel?buttonarea?=?new?JPanel(new?GridLayout(4,4));
                     ^
Main.java:14: error: illegal character: '\u00a0'
????JPanel?buttonarea?=?new?JPanel(new?GridLayout(4,4));
                       ^
Main.java:14: error: illegal character: '\u00a0'
????JPanel?buttonarea?=?new?JPanel(new?GridLayout(4,4));
                           ^
Main.java:14: error: illegal character: '\u00a0'
????JPanel?buttonarea?=?new?JPanel(new?GridLayout(4,4));
                                      ^
Main.java:15: error: illegal character: '\u00a0'
????ArrayList<JButton>?buttons?=?new?ArrayList<JButton>();
^
Main.java:15: error: illegal character: '\u00a0'
????ArrayList<JButton>?buttons?=?new?ArrayList<JButton>();
 ^
Main.java:15: error: illegal character: '\u00a0'
????ArrayList<JButton>?buttons?=?new?ArrayList<JButton>();
  ^
Main.java:15: error: illegal character: '\u00a0'
????ArrayList<JButton>?buttons?=?new?ArrayList<JButton>();
   ^
Main.java:15: error: class, interface, or enum expected
????ArrayList<JButton>?buttons?=?new?ArrayList<JButton>();
    ^
Main.java:15: error: illegal character: '\u00a0'
????ArrayList<JButton>?buttons?=?new?ArrayList<JButton>();
                      ^
Main.java:15: error: illegal character: '\u00a0'
????ArrayList<JButton>?buttons?=?new?ArrayList<JButton>();
                              ^
Main.java:15: error: illegal character: '\u00a0'
????ArrayList<JButton>?buttons?=?new?ArrayList<JButton>();
                                ^
Main.java:15: error: illegal character: '\u00a0'
????ArrayList<JButton>?buttons?=?new?ArrayList<JButton>();
                                    ^
Main.java:16: error: illegal character: '\u00a0'
????JButton?tasuButton?=?new?JButton("+");
^
Main.java:16: error: illegal character: '\u00a0'
????JButton?tasuButton?=?new?JButton("+");
 ^
Main.java:16: error: illegal character: '\u00a0'
????JButton?tasuButton?=?new?JButton("+");
  ^
Main.java:16: error: illegal character: '\u00a0'
????JButton?tasuButton?=?new?JButton("+");
   ^
Main.java:16: error: illegal character: '\u00a0'
????JButton?tasuButton?=?new?JButton("+");
           ^
Main.java:16: error: illegal character: '\u00a0'
????JButton?tasuButton?=?new?JButton("+");
                      ^
Main.java:16: error: illegal character: '\u00a0'
????JButton?tasuButton?=?new?JButton("+");
                        ^
Main.java:16: error: illegal character: '\u00a0'
????JButton?tasuButton?=?new?JButton("+");
                            ^
Main.java:17: error: illegal character: '\u00a0'
????JButton?hikuButton?=?new?JButton("-");
^
Main.java:17: error: illegal character: '\u00a0'
????JButton?hikuButton?=?new?JButton("-");
 ^
Main.java:17: error: illegal character: '\u00a0'
????JButton?hikuButton?=?new?JButton("-");
  ^
Main.java:17: error: illegal character: '\u00a0'
????JButton?hikuButton?=?new?JButton("-");
   ^
Main.java:17: error: illegal character: '\u00a0'
????JButton?hikuButton?=?new?JButton("-");
           ^
Main.java:17: error: illegal character: '\u00a0'
????JButton?hikuButton?=?new?JButton("-");
                      ^
Main.java:17: error: illegal character: '\u00a0'
????JButton?hikuButton?=?new?JButton("-");
                        ^
Main.java:17: error: illegal character: '\u00a0'
????JButton?hikuButton?=?new?JButton("-");
                            ^
Main.java:18: error: illegal character: '\u00a0'
????JButton?kakeButton?=?new?JButton("?");
^
Main.java:18: error: illegal character: '\u00a0'
????JButton?kakeButton?=?new?JButton("?");
 ^
Main.java:18: error: illegal character: '\u00a0'
????JButton?kakeButton?=?new?JButton("?");
  ^
Main.java:18: error: illegal character: '\u00a0'
????JButton?kakeButton?=?new?JButton("?");
   ^
Main.java:18: error: illegal character: '\u00a0'
????JButton?kakeButton?=?new?JButton("?");
           ^
Main.java:18: error: illegal character: '\u00a0'
????JButton?kakeButton?=?new?JButton("?");
                      ^
Main.java:18: error: illegal character: '\u00a0'
????JButton?kakeButton?=?new?JButton("?");
                        ^
Main.java:18: error: illegal character: '\u00a0'
????JButton?kakeButton?=?new?JButton("?");
                            ^
Main.java:19: error: illegal character: '\u00a0'
????JButton?wariButton?=?new?JButton("?");
^
Main.java:19: error: illegal character: '\u00a0'
????JButton?wariButton?=?new?JButton("?");
 ^
Main.java:19: error: illegal character: '\u00a0'
????JButton?wariButton?=?new?JButton("?");
  ^
Main.java:19: error: illegal character: '\u00a0'
????JButton?wariButton?=?new?JButton("?");
   ^
Main.java:19: error: illegal character: '\u00a0'
????JButton?wariButton?=?new?JButton("?");
           ^
Main.java:19: error: illegal character: '\u00a0'
????JButton?wariButton?=?new?JButton("?");
                      ^
Main.java:19: error: illegal character: '\u00a0'
????JButton?wariButton?=?new?JButton("?");
                        ^
Main.java:19: error: illegal character: '\u00a0'
????JButton?wariButton?=?new?JButton("?");
                            ^
Main.java:20: error: illegal character: '\u00a0'
????JButton?equalButton?=?new?JButton("=");
^
Main.java:20: error: illegal character: '\u00a0'
????JButton?equalButton?=?new?JButton("=");
 ^
Main.java:20: error: illegal character: '\u00a0'
????JButton?equalButton?=?new?JButton("=");
  ^
Main.java:20: error: illegal character: '\u00a0'
????JButton?equalButton?=?new?JButton("=");
   ^
Main.java:20: error: illegal character: '\u00a0'
????JButton?equalButton?=?new?JButton("=");
           ^
Main.java:20: error: illegal character: '\u00a0'
????JButton?equalButton?=?new?JButton("=");
                       ^
100 errors
stdout
Standard output is empty