Не могли бы нарисовать мну диаграмму классов, а то очень трудно разобраться. Буду благодарен.
Хотябы для одного или двух нарисуйте, а то воше не понимаю как деляется.
import javax.swing.*;
public class main{
public static void main(String[] args){
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
private static void createAndShowGUI() {
JFrame frame = new JFrame("Calculator");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pan p1 = new pan();
p1.setOpaque(true);
frame.setContentPane(p1);
frame.pack();
frame.setVisible(true);
}
}
import java.awt.event.*;
public class pan extends javax.swing.JPanel implements ActionListener {
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton10;
private javax.swing.JButton jButton11;
private javax.swing.JButton jButton12;
private javax.swing.JButton jButton13;
private javax.swing.JButton jButton14;
private javax.swing.JButton jButton15;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JButton jButton6;
private javax.swing.JButton jButton7;
private javax.swing.JButton jButton8;
private javax.swing.JButton jButton9;
private javax.swing.JTextField jTextField1;
private String text = "0";
private atan tg = new atan();
public pan() {
initComponents();
}
private void initComponents() {
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jButton5 = new javax.swing.JButton();
jButton6 = new javax.swing.JButton();
jButton7 = new javax.swing.JButton();
jButton8 = new javax.swing.JButton();
jButton9 = new javax.swing.JButton();
jButton10 = new javax.swing.JButton();
jButton11 = new javax.swing.JButton();
jButton12 = new javax.swing.JButton();
jButton13 = new javax.swing.JButton();
jButton14 = new javax.swing.JButton();
jButton15 = new javax.swing.JButton();
jTextField1 = new javax.swing.JTextField();
jButton1.setText("7");
jButton1.setMnemonic(KeyEvent.VK_D);
jButton1.setActionCommand("7");
jButton1.addActionListener(this);
jButton2.setText("8");
jButton2.setMnemonic(KeyEvent.VK_D);
jButton2.setActionCommand("8");
jButton2.addActionListener(this);
jButton3.setText("9");
jButton3.setMnemonic(KeyEvent.VK_D);
jButton3.setActionCommand("9");
jButton3.addActionListener(this);
jButton4.setText("4");
jButton4.setMnemonic(KeyEvent.VK_D);
jButton4.setActionCommand("4");
jButton4.addActionListener(this);
jButton5.setText("5");
jButton5.setMnemonic(KeyEvent.VK_D);
jButton5.setActionCommand("5");
jButton5.addActionListener(this);
jButton6.setText("6");
jButton6.setMnemonic(KeyEvent.VK_D);
jButton6.setActionCommand("6");
jButton6.addActionListener(this);
jButton7.setText("1");
jButton7.setMnemonic(KeyEvent.VK_D);
jButton7.setActionCommand("1");
jButton7.addActionListener(this);
jButton8.setText("2");
jButton8.setMnemonic(KeyEvent.VK_D);
jButton8.setActionCommand("2");
jButton8.addActionListener(this);
jButton9.setText("3");
jButton9.setMnemonic(KeyEvent.VK_D);
jButton9.setActionCommand("3");
jButton9.addActionListener(this);
jButton10.setText("0");
jButton10.setMnemonic(KeyEvent.VK_D);
jButton10.setActionCommand("0");
jButton10.addActionListener(this);
jButton11.setText(".");
jButton11.setMnemonic(KeyEvent.VK_D);
jButton11.setActionCommand(".");
jButton11.addActionListener(this);
jButton12.setText("+/-");
jButton12.setMnemonic(KeyEvent.VK_D);
jButton12.setActionCommand("+/-");
jButton12.addActionListener(this);
jButton13.setText("c");
jButton13.setMnemonic(KeyEvent.VK_D);
jButton13.setActionCommand("c");
jButton13.addActionListener(this);
jButton14.setText("Del");
jButton14.setMnemonic(KeyEvent.VK_D);
jButton14.setActionCommand("Del");
jButton14.addActionListener(this);
jButton15.setText("arctg(x)");
jButton15.setMnemonic(KeyEvent.VK_D);
jButton15.setActionCommand("arctg(x)");
jButton15.addActionListener(this);
jTextField1.setText(text);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 241, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(jButton10)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(jButton7)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton8)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jButton9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton12, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton15))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jButton4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton13, javax.swing.GroupLayout.DEFAULT_SIZE, 79, Short.MAX_VALUE)
.addComponent(jButton14, javax.swing.GroupLayout.DEFAULT_SIZE, 79, Short.MAX_VALUE)))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(4, 4, 4)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2)
.addComponent(jButton3)
.addComponent(jButton13))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton4)
.addComponent(jButton5)
.addComponent(jButton6)
.addComponent(jButton14))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton7)
.addComponent(jButton8)
.addComponent(jButton9))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton10)
.addComponent(jButton11)
.addComponent(jButton12)
.addComponent(jButton15)))
);
}
private boolean dot = false;
private String ev, gettext;
private int evi;
private double tmp;
public void actionPerformed(ActionEvent e) {
ev = e.getActionCommand();
text = jTextField1.getText();
try{
evi = Integer.parseInt(ev);
if (text.equals("0") || text.equals("ERR")){text = "";}
text += ev;
jTextField1.setText(text);
} catch (NumberFormatException nfe){
if (ev.equals(".") && (dot == false)){
text += ".";
dot = true;
jTextField1.setText(text);
}
if (ev.equals("Del")){
if (text.substring(text.length()-1,text.length()).equals(".")) dot = false;
if (text.length() > 1){
text = text.substring(0,text.length()-1);
} else if (text.length() == 1){
text = "0";
}
jTextField1.setText(text);
}
if (ev.equals("c")){
dot = false;
text = "0";
jTextField1.setText(text);
}
if (ev.equals("+/-")){
if (!text.equals("0") && !text.equals("0.") && !text.equals("ERR")){
tmp = Double.valueOf(text);
if (tmp > 0){text = "-" + text;}
else if (tmp < 0) {text = text.substring(1,text.length());}
jTextField1.setText(text);
}
}
if (ev.equals("arctg(x)")){
if (check()){
float temp = Float.valueOf(text);
temp = tg.arctg(temp);
text = Float.toString(temp);
jTextField1.setText(text);
}
}
}
}
private boolean check(){
try{
float tmpcheck = Float.valueOf(text);
return true;
} catch (NumberFormatException nfe){
text = "ERR";
jTextField1.setText(text);
return false;
}
}
}
public class atan{
private float SQRT3 = (float) 1.732050807569;
public float arctg(float x){
int sta = 0, sp = 0;
float x2, a;
if(x < (float)0) {x = -x; sta|=1; }
if(x > (float)1) {x = (float)1/x; sta|=2; }
while(x > (Math.PI/2)) {
sp++;
a = x + SQRT3;
a = (float)1 / a;
x *= SQRT3;
x -= (float)1;
x *= a;
}
x2 = x*x; a = x2 + (float) 1.4087812;
a = (float) 0.55913709 / a;
a += (float) 0.60310579;
a -= (float) 0.05160454 * x2;
a *= x;
while(sp > 0) {a += (float)Math.PI/6; sp--;}
if((sta&2) > 0) { a = (float) Math.PI / 2 - a; }
if((sta&1) > 0) { a = -a; }
return(a);
}
}