import java.applet.*; import java.awt.*; import java.awt.event.*; import java.text.*; import java.util.*; public class ten extends Applet implements KeyListener,ActionListener{ Button bs = new Button("開始・消去"); Button bc = new Button("再計算"); Panel pn = new Panel(); Panel ps = new Panel(); TextArea ta = new TextArea(8,60); double r0 = 0; double r1 = 0; double r2 = 0; String s = ""; String x = ""; String ind= ""; Color c; int dw,dh; Image img,wimg; Graphics wx,wg; DecimalFormat f = new DecimalFormat("0.00"); String t [][] = {{" ","0","010","000","or"," "}, {"/","0","040","000","or","e"}, {"*","0","070","000","or","e"}, {"-","0","100","000","or","e"}, {"7","0","010","030","cy","n"}, {"8","0","040","030","cy","n"}, {"9","0","070","030","cy","n"}, {"+","1","100","030","or","e"}, {"4","0","010","060","cy","n"}, {"5","0","040","060","cy","n"}, {"6","0","070","060","cy","n"}, {"1","0","010","090","cy","n"}, {"2","0","040","090","cy","n"}, {"3","0","070","090","cy","n"}, {"\n","1","100","090","or","t"}, {"=","1","100","090","or","t"}, {"0","2","010","120","cy","n"}, {".","0","070","120","cy","p"}}; public void init() { pn.setLayout(new GridLayout(1,1)); pn.add(ta); ps.setLayout(new GridLayout(1,2)); ps.add(bs); ps.add(bc); setLayout(new BorderLayout()); add ("South",ps); add ("North",pn); Dimension w = getSize(); dw = w.width; dh = w.height; img = createImage(dw,dh); wimg = createImage(dw,dh); wg = wimg.getGraphics(); wx = img.getGraphics(); bs.addActionListener(this); bc.addActionListener(this); addKeyListener(this); setBackground(Color.black); requestFocus(); key(); repaint(); } public void paint(Graphics g) { //Print g.drawImage(wimg,40,180,this) ; g.setColor(Color.white); Font f1 = new Font("MS ゴシック",Font.BOLD,14); g.setFont(f1); g.drawString("["+x+"]",0,160); } public void key(){ //keyのレイアウト表示 wx.setColor(Color.black); wx.fillRect(0,0,dw,dh); for (int i=0;i20){s="";return;} if(r0==0){x=""+s;r0=-1;return;} else {x+=s;r0=-1;return;} } if(t[j][5].equals("p")){ if(x==""|x.indexOf(".")!=-1) {s="";return;} if(r0==0){x=""+s;r0=-1;return;} else {x+=s;r0=-1;return;} } if(s.equals(".")){s="";return;} if(t[j][5].equals("t")){s="=";} r1=gd(x); if(ind.equals("+")) {r2=r2+r1;r0=0;r1=0;} if(ind.equals("-")) {r2=r2-r1;r0=0;r1=0;} if(ind.equals("*")) {r2=r2*r1;r0=0;r1=0;} if(ind.equals("/")) {r2=r2/r1;r0=0;r1=0;} if(ind.equals("=")) {r2= r1;r0=0;r1=0;} if(ind.equals("" )) {r2= r1;r0=0;r1=0;} ind=s; x=""+r2; s+="\n"; } double gd(String q){ //数字編集 int ql=q.indexOf("."); if(ql==-1){return(Double.parseDouble(q));} double qa=Double.parseDouble(q.substring(0,ql)); double qb=Double.parseDouble(q.substring(ql+1,q.length())); return( qa+(qb/(Math.pow(10,(q.length()-ql-1))))); } public void actionPerformed(ActionEvent e) { //ボタン押下の処理 if (e.getSource()==bs) { clr(); } if (e.getSource()==bc) { String buf=ta.getText(); clr(); for(int i=0;i