001  /*
002   * <applet code="fenix.class" width="350" height="250"<>/applet>
003   *             javac fenix.java
004   */
005  import java.awt.*;
006  import java.awt.event.*;
007  import javax.swing.*; 
008  public class fenix extends JApplet
009  {
010   JButton b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, plus, minus, umn, del, itog, point, cancel, cor, kva, qub; 
011   JPanel west, north, east, center;
012   JTextField display;
013   char select = ' '; 
014   double currentResult = ' '; 
015   double displayValue = ' ';
016   String displayText;
017   public fenix()
018   {
019    setBackground(Color.black); 
020    setLayout(new BorderLayout());
021    display = new JTextField(15);
022    display.setFont(new Font("Verdana", Font.BOLD, 20));
023    b0 = new JButton("<html><h1><font color=\"black\">0"); b0.setBackground(Color.cyan); 
024    b0.addActionListener(new ActionListener()
025    {
026     public void actionPerformed(ActionEvent ae){display.setText(display.getText() + "0");}
027    });
028    b1 = new JButton("<html><h1><font color=\"black\">1"); b1.setBackground(Color.cyan); 
029    b1.addActionListener(new ActionListener()
030    {
031     public void actionPerformed(ActionEvent ae){display.setText(display.getText() + "1");}
032    });
033    b2 = new JButton("<html><h1><font color=\"black\">2"); b2.setBackground(Color.cyan); 
034    b2.addActionListener(new ActionListener()
035    {
036     public void actionPerformed(ActionEvent ae){display.setText(display.getText() + "2");}
037    });
038    b3 = new JButton("<html><h1><font color=\"black\">3"); b3.setBackground(Color.cyan); 
039    b3.addActionListener(new ActionListener()
040    {
041     public void actionPerformed(ActionEvent ae){display.setText(display.getText() + "3");}
042    });
043    b4 = new JButton("<html><h1><font color=\"black\">4"); b4.setBackground(Color.cyan); 
044    b4.addActionListener(new ActionListener()
045    {
046     public void actionPerformed(ActionEvent ae){display.setText(display.getText() + "4");}
047    });
048    b5 = new JButton("<html><h1><font color=\"black\">5"); b5.setBackground(Color.cyan); 
049    b5.addActionListener(new ActionListener()
050    {
051     public void actionPerformed(ActionEvent ae){display.setText(display.getText() + "5");}
052    });
053    b6 = new JButton("<html><h1><font color=\"black\">6"); b6.setBackground(Color.cyan); 
054    b6.addActionListener(new ActionListener()
055    {
056     public void actionPerformed(ActionEvent ae){display.setText(display.getText() + "6");}
057    });
058    b7 = new JButton("<html><h1><font color=\"black\">7"); b7.setBackground(Color.cyan); 
059    b7.addActionListener(new ActionListener()
060    {
061     public void actionPerformed(ActionEvent ae){display.setText(display.getText() + "7");}
062    });
063    b8 = new JButton("<html><h1><font color=\"black\">8"); b8.setBackground(Color.cyan); 
064    b8.addActionListener(new ActionListener()
065    {
066     public void actionPerformed(ActionEvent ae){display.setText(display.getText() + "8");}
067    });
068    b9 = new JButton("<html><h1><font color=\"black\">9"); b9.setBackground(Color.cyan); 
069    b9.addActionListener(new ActionListener()
070    {
071     public void actionPerformed(ActionEvent ae){display.setText(display.getText() + "9");}
072    });
073    point = new JButton("<html><h1><font color=\"white\">."); point.setBackground(Color.blue); 
074    point.addActionListener(new ActionListener()
075    {
076     public void actionPerformed(ActionEvent ae){display.setText(display.getText() + ".");}
077    }); 
078    kva = new JButton("<html><h1><font color=\"black\">n<sup>2"); 
079    kva.setBackground(Color.yellow); kva.addActionListener(new ActionListener()
080    {
081     public void actionPerformed(ActionEvent ae)
082     {
083      displayText = display.getText(); 
084      displayValue = Double.parseDouble(displayText); 
085      currentResult = displayValue * displayValue; 
086      display.setText(" " + currentResult);
087     }
088   }); 
089    qub = new JButton("<html><h1><font color=\"black\">n<sup>3"); 
090    qub.setBackground(Color.yellow); qub.addActionListener(new ActionListener()
091    {
092     public void actionPerformed(ActionEvent ae)
093     {
094      displayText = display.getText(); 
095      displayValue = Double.parseDouble(displayText); 
096      currentResult = displayValue * displayValue * displayValue; 
097      display.setText(" " + currentResult);
098     }
099    });
100    cancel = new JButton("<html><h1><font color=\"black\">C"); cancel.setBackground(Color.yellow); 
101    cancel.addActionListener(new ActionListener()
102    {
103     public void actionPerformed(ActionEvent ae){display.setText(" ");}
104    });
105    cor = new JButton("<html><h1><font color=\"black\">:KK"); cor.setBackground(Color.yellow); 
106    cor.addActionListener(new ActionListener()
107    {
108     public void actionPerformed(ActionEvent ae)
109     {
110      displayText = display.getText(); 
111      displayValue = Double.parseDouble(displayText); 
112      currentResult = Math.sqrt(displayValue); 
113      display.setText(" " + currentResult);
114     }
115    });
116    plus = new JButton(""<html><h1><font color=\"black\">+"); plus.setBackground(Color.yellow);  
117    plus.addActionListener(new ActionListener()
118    {     public void actionPerformed(ActionEvent ae)
119     {
120      displayText = display.getText(); 
121      displayValue = Double.parseDouble(displayText); 
122      select = '+'; 
123      currentResult = displayValue; 
124      display.setText(" ");
125     }
126    });
127    minus = new JButton(""<html><h1><font color=\"black\">-"); minus.setBackground(Color.yellow);  
128    minus.addActionListener(new ActionListener()
129    {
130     public void actionPerformed(ActionEvent ae)
131     {
132      displayText = display.getText(); 
133      displayValue = Double.parseDouble(displayText); 
134      select = '-'; 
135      currentResult = displayValue; 
136      display.setText(" ");
137     }
138    });
139    umn = new JButton("<html><h1><font color=\"black\">*"); umn.setBackground(Color.yellow);  
140    umn.addActionListener(new ActionListener()
141    {
142     public void actionPerformed(ActionEvent ae)
143     {
144      displayText = display.getText(); 
145      displayValue = Double.parseDouble(displayText); 
146      select = '*'; 
147      currentResult = displayValue; 
148      display.setText(" ");
149     }
150    });
151    del = new JButton("<html><h1><font color=\"black\">:"); del.setBackground(Color.yellow);  
152    del.addActionListener(new ActionListener()
153    {
154     public void actionPerformed(ActionEvent ae)
155      displayText = display.getText(); 
156      displayValue = Double.parseDouble(displayText); 
157      select = ':'; 
158      currentResult = displayValue; 
159      display.setText(" ");
160     }
161    });
162    itog = new JButton("<html><h1><font color=\"white\">="); itog.setBackground(Color.blue);  
163    itog.addActionListener(new ActionListener()
164    {
165     public void actionPerformed(ActionEvent ae)
166     {
167      if(select == '+')
168      {
169       displayText = display.getText(); 
170       displayValue = Double.parseDouble(displayText); 
171       currentResult += displayValue; 
172       display.setText(" " + currentResult);
173      }
174      else if(select == '-')
175      {
176       displayText = display.getText(); 
177       displayValue = Double.parseDouble(displayText); 
178       currentResult -= displayValue; 
179       display.setText(" " + currentResult);
180      }
181      else if(select == '*')
182      {
183       displayText = display.getText(); 
184       displayValue = Double.parseDouble(displayText); 
185       currentResult *= displayValue; 
186       display.setText(" " + currentResult);
187      }
188      else if(select == ':')
189      {
190       displayText = display.getText(); 
191       displayValue = Double.parseDouble(displayText);
192       currentResult /= displayValue; 
193       display.setText(" " + currentResult);
194      }
195     }
196    }); 
197    JPanel north = new JPanel(); north.setBackground(Color.gray); 
198    north.add(display); add(north, BorderLayout.NORTH);
199    JPanel east = new JPanel(); east.setLayout(new GridLayout(4, 1)); 
200    east.add(plus); east.add(minus); east.add(umn); east.add(del); add(east, BorderLayout.EAST); 
201    JPanel west = new JPanel(); west.setLayout(new GridLayout(4, 1)); 
202    west.add(qub); west.add(kva); west.add(cor); west.add(cancel); add(west, BorderLayout.WEST);
203    JPanel center = new JPanel(); center.setLayout(new GridLayout(4, 3)); 
204    center.add(b1); center.add(b2); center.add(b3); center.add(b4); center.add(b5); 
205    center.add(b6); center.add(b7); center.add(b8); center.add(b9); center.add(b0); 
206    center.add(point); center.add(itog); add(center, BorderLayout.CENTER);
207   }
208   public Insets getInsets(){return new Insets(2, 2, 2, 2);}    
209   public static void main(String[] args)
210   {
211    JApplet applet = new fenix();                               
212    JFrame frame = new JFrame("Arifmometr by Cupoma_260817");
213    frame.addWindowListener(new WindowAdapter() 
214    {
215     public void windowClosing(WindowEvent we){System.exit(0);}
216    });
217    frame.setSize(350, 250);                                    
218    applet.init();
219    applet.start();
220    frame.setVisible(true); 
221   }
222  }
                          рис.8.1