import javax.swing.*;
import java.awt.event.*;
import java.awt.Container;
import java.awt.*;
import java.text.*;
/*import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.SWT;*/
public class Jsq extends JFrame
{
private static final long serialVersionUID = 1L;
private JFrame mainFrame;
private JTextField tField;
private JButton but1;
private JButton but2;
private JButton but3;
private JButton but4;
private JButton but5;
private JButton but6;
private JButton but7;
private JButton but8;
private JButton but9;
private JButton but10;
private JButton but11;
private JButton but12;
private JButton but13;
private JButton but14;
private JButton but15;
private JButton but16;
private JButton but17;
String instring,instring1,instring2,instring3;
int one=1,point=0;
double in,in1,inp,out;
public Jsq()
{
mainFrame = new JFrame("计算器");
/*Display display = new Display();
Shell shell = new Shell(display);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.makeColumnsEqualWidth = true;
shell.setLayout(layout);
GridData data = new GridData(GridData.FILL_BOTH);
Button but1 = new Button(shell,SWT.PUSH);
but1.setText("0");
but1.setLayoutData(data);
data = new GridData(GridData.FILL_BOTH);
Button but2 = new Button(shell,SWT.PUSH);
but2.setText("1");
but2.setLayoutData(data);
data = new GridData(GridData.FILL_BOTH);
Button but3 = new Button(shell,SWT.PUSH);
but3.setText("2");
but3.setLayoutData(data);
data = new GridData(GridData.FILL_BOTH);
Button but4 = new Button(shell,SWT.PUSH);
but4.setText("3");
but4.setLayoutData(data);
shell.pack();
shell.open();
while(!shell.isDisposed()){
if(!display.readAndDispatch()){
display.sleep();
}
}
display.dispose();*/
tField = new JTextField("欢迎使用自制整数蹩脚计算器: ");
but1 = new JButton("0");
but2 = new JButton("1");
but3 = new JButton("2");
but4 = new JButton("3");
but5 = new JButton("4");
but6 = new JButton("5");
but7 = new JButton("6");
but8 = new JButton("7");
but9 = new JButton("8");
but10 = new JButton("9");
but11 = new JButton("+");
but12 = new JButton("-");
but13 = new JButton("*");
but14 = new JButton("/");
but15 = new JButton("=");
but16 = new JButton("清除");
but17 = new JButton("。");
Container c = mainFrame.getContentPane();
//c.add(tField,BorderLayout.NORTH);
c.add(tField);
c.setLayout(new FlowLayout());
c.add(but1);
c.add(but2);
c.add(but3);
c.add(but4);
c.add(but5);
c.add(but6);
c.add(but7);
c.add(but8);
c.add(but9);
c.add(but10);
c.add(but17);
c.add(but16);
c.add(but11);
c.add(but12);
c.add(but13);
c.add(but14);
c.add(but15);
mainFrame.setSize(350, 200);
//define and register window event handler
mainFrame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e){System.exit(0);}
});
but1Handler m1handler = new but1Handler();
but1.addActionListener(m1handler);
but2Handler m2handler = new but2Handler();
but2.addActionListener(m2handler);
but3Handler m3handler = new but3Handler();
but3.addActionListener(m3handler);
but4Handler m4handler = new but4Handler();
but4.addActionListener(m4handler);
but5Handler m5handler = new but5Handler();
but5.addActionListener(m5handler);
but6Handler m6handler = new but6Handler();
but6.addActionListener(m6handler);
but7Handler m7handler = new but7Handler();
but7.addActionListener(m7handler);
but8Handler m8handler = new but8Handler();
but8.addActionListener(m8handler);
but9Handler m9handler = new but9Handler();
but9.addActionListener(m9handler);
but10Handler m10handler = new but10Handler();
but10.addActionListener(m10handler);
but11Handler m11handler = new but11Handler();
but11.addActionListener(m11handler);
but12Handler m12handler = new but12Handler();
but12.addActionListener(m12handler);
but13Handler m13handler = new but13Handler();
but13.addActionListener(m13handler);
but14Handler m14handler = new but14Handler();
but14.addActionListener(m14handler);
but15Handler m15handler = new but15Handler();
but15.addActionListener(m15handler);
but16Handler m16handler = new but16Handler();
but16.addActionListener(m16handler);
but17.addActionListener(new but17Handler());
// mainFrame.show();
mainFrame.setVisible(true);
}
class but1Handler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if(point==0)
{
if(in==0){
tField.setText("0");
in=0;in1=in;
instring2 = "0";
}
else
{
in=10*in+0;in1=in;
instring2=String.valueOf(in) ;
tField.setText(instring2);
}
}
if(point==1)
{
one=10*one;
if(in==0){
in=0;
in1=in/one;
in1=inp+in1;
instring2=String.valueOf(in1) ;
tField.setText(instring2);
}
else
{
in=10*in+0;
in1=in/one;
in1=inp+in1;
instring2=String.valueOf(in1) ;
tField.setText(instring2);
}
}
}
}
class but2Handler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if(point==0)
{
if(in==0){
tField.setText("1");
in=1;in1=in;
instring2 = "1";
}
else
{
in=10*in+1;in1=in;
instring2=String.valueOf(in) ;
tField.setText(instring2);
}
}
if(point==1)
{
one=10*one;
if(in==0){
in=1;
in1=in/one;
in1=inp+in1;
instring2=String.valueOf(in1) ;
tField.setText(instring2);
}
else
{
in=10*in+1;
in1=in/one;
in1=inp+in1;
instring2=String.valueOf(in1) ;
tField.setText(instring2);
}
}
}
}
class but3Handler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if(point==0)
{
if(in==0){
tField.setText("2");
in=2;in1=in;
instring2 = "2";
}
else
{
in=10*in+2;in1=in;
instring2=String.valueOf(in) ;
tField.setText(instring2);
}
}
if(point==1)
{
one=10*one;
if(in==0){
in=2;
in1=in/one;
in1=inp+in1;
instring2=String.valueOf(in1) ;
tField.setText(instring2);
}
else
{
in=10*in+2;
in1=in/one;
in1=inp+in1;
instring2=String.valueOf(in1) ;
tField.setText(instring2);
}
}
}
}
class but4Handler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if(point==0)
{
if(in==0){
tField.setText("3");
in=3;in1=in;
instring2 = "3";
}
else
{
in=10*in+3;in1=in;
instring2=String.valueOf(in) ;
tField.setText(instring2);
}
}
if(point==1)
{
one=10*one;
if(in==0){
in=3;
in1=in/one;
in1=inp+in1;
instring2=String.valueOf(in1) ;
tField.setText(instring2);
}
else
{
in=10*in+3;
in1=in/one;
in1=inp+in1;
instring2=String.valueOf(in1) ;
tField.setText(instring2);
}
}
}
}
class but5Handler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if(point==0)
{
if(in==0){
tField.setText("4");
in=4;in1=in;
instring2 = "4";
}
else
{
in=10*in+4;in1=in;
instring2=String.valueOf(in) ;
tField.setText(instring2);
}
}
if(point==1)
{
one=10*one;
if(in==0){
in=4;
in1=in/one;
in1=inp+in1;
instring2=String.valueOf(in1) ;
tField.setText(instring2);
}
else
{
in=10*in+4;
in1=in/one;
in1=inp+in1;
instring2=String.valueOf(in1) ;
tField.setText(instring2);
}
&