Created
March 17, 2010 04:03
-
-
Save clairvy/334899 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| *.class |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.applet.*; | |
| import java.awt.*; | |
| import java.util.*; | |
| public class dentaku extends Applet | |
| { | |
| dentakuKeisan Keisan = new dentakuKeisan(); | |
| public void init(){ | |
| setLayout(new BorderLayout()); | |
| Panel PA = new Panel(); | |
| PA.setLayout(new GridLayout(5,5,5,5)); | |
| Button B = new Button(); | |
| Font f = new Font("TimesRoman",Font.ITALIC,15); | |
| B.setFont(f); | |
| B.setBackground(Color.lightGray); | |
| B.setForeground(Color.red); | |
| PA.add(B = new Button("7")); | |
| PA.add(B = new Button("8")); | |
| PA.add(B = new Button("9")); | |
| PA.add(B = new Button("/")); | |
| PA.add(B = new Button("4")); | |
| PA.add(B = new Button("5")); | |
| PA.add(B = new Button("6")); | |
| PA.add(B = new Button("*")); | |
| PA.add(B = new Button("1")); | |
| PA.add(B = new Button("2")); | |
| PA.add(B = new Button("3")); | |
| PA.add(B = new Button("-")); | |
| PA.add(B = new Button(".")); | |
| PA.add(B = new Button("0")); | |
| PA.add(B = new Button("+/-")); | |
| PA.add(B = new Button("+")); | |
| PA.add(B = new Button("C")); | |
| PA.add(B = new Button("=")); | |
| PA.add(B = new Button("(")); | |
| PA.add(B = new Button(")")); | |
| add("North",Keisan); | |
| add("Center",PA); | |
| } | |
| public boolean action(Event ev,Object arg){ | |
| if(ev.target instanceof Button){ | |
| String la = (String)arg; | |
| if(la.equals("C")){ | |
| Keisan.Clear(); | |
| return true; | |
| }else if(la.equals(".")){ | |
| Keisan.Ten(); | |
| return true; | |
| }else if(la.equals("+")){ | |
| Keisan.Sisoku(); | |
| Keisan.n = 1; | |
| return true; | |
| }else if(la.equals("-")){ | |
| Keisan.Sisoku(); | |
| Keisan.n = 2; | |
| return true; | |
| }else if(la.equals("*")){ | |
| Keisan.Sisoku(); | |
| Keisan.n = 3; | |
| return true; | |
| }else if(la.equals("/")){ | |
| Keisan.Sisoku(); | |
| Keisan.n = 4; | |
| return true; | |
| }else if(la.equals("+/-")){ | |
| Keisan.Hanten(); | |
| return true; | |
| }else if(la.equals("=")){ | |
| Keisan.Dewa(); | |
| return true; | |
| } | |
| else{ | |
| Keisan.Suji(la); | |
| return true; | |
| } | |
| } | |
| return false; | |
| } | |
| } | |
| class dentakuKeisan extends Panel | |
| { | |
| Label LA = new Label(" 0"); | |
| String s = " 0"; | |
| double total = 0; | |
| String totals; | |
| public int n = 0; | |
| dentakuKeisan(){ | |
| setBackground(Color.yellow); | |
| setFont(new Font("TimesRoman",Font.BOLD + Font.ITALIC,20)); | |
| LA.setBackground(Color.white); | |
| LA.setAlignment(1); | |
| add("Center",LA); | |
| } | |
| void Suji(String su){ | |
| s = s + su; | |
| if(s.length() == 2 && s.charAt(0) == '0' && s.charAt(1) != '.'){ | |
| s = s.substring(1); | |
| } | |
| LA.setText(s); | |
| } | |
| void Hanten(){ | |
| if(s.length() == 0)return; | |
| if(s.charAt(0) == '-')s = s.substring(1); | |
| else s = "-" + s; | |
| LA.setText(s); | |
| } | |
| void Ten(){ | |
| if(s.indexOf('.') != -1){ | |
| return; | |
| }else{ | |
| s = s + "."; | |
| } | |
| LA.setText(s); | |
| } | |
| void Sisoku(){ | |
| if(s.length() == 0)return; | |
| Double d = Double.valueOf(s); | |
| switch(n){ | |
| case 1: | |
| total = total + d.doubleValue(); | |
| break; | |
| case 2: | |
| total = total - d.doubleValue(); | |
| break; | |
| case 3: | |
| total = total * d.doubleValue(); | |
| break; | |
| case 4: | |
| total = total / d.doubleValue(); | |
| break; | |
| default: | |
| total = d.doubleValue(); | |
| break; | |
| } | |
| totals = new Double(total).toString(); | |
| LA.setText(totals); | |
| s = "0"; | |
| } | |
| void Dewa(){ | |
| if(s.length() == 0)return; | |
| Double d = Double.valueOf(s); | |
| switch(n){ | |
| case 1: | |
| total = total + d.doubleValue(); | |
| break; | |
| case 2: | |
| total = total - d.doubleValue(); | |
| break; | |
| case 3: | |
| total = total * d.doubleValue(); | |
| break; | |
| case 4: | |
| total = total / d.doubleValue(); | |
| break; | |
| default: | |
| total = d.doubleValue(); | |
| break; | |
| } | |
| totals = new Double(total).toString(); | |
| LA.setText(totals); | |
| s = "0"; | |
| } | |
| void Clear(){ | |
| total = 0; | |
| n = 0; | |
| s = "0"; | |
| LA.setText(s); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <body> | |
| <applet code="dentaku.class" width="800" height="400"></applet> | |
| </body> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Base = dentaku | |
| JAVAC_Opts = -encoding utf8 -Xlint:unchecked -Xlint:deprecation | |
| JAVA_Opts = -Dfile.encoding=UTF8 | |
| APV_Opts = | |
| default : do | |
| build : $(Base).class | |
| $(Base).class : $(Base).java | |
| javac $(JAVAC_Opts) $(Base).java 2>&1 | lv -Ou | cat | |
| do : build | |
| appletviewer $(APV_Opts) index.html | |
| test : build | |
| prove ./test.pl | |
| clean : | |
| rm -rf *.class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment