展开全部
//有窗口的62616964757a686964616fe59b9ee7ad9431333431346339 1+2+3+...+到某一个数
import java.awt.Color;
import java.awt.Font;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.WindowConstants;
public class AbsolutePosition extends JFrame
{
Font F =new Font("宋体",1,20);
int A=1;
int B=0;
int C=0;
int Undo=0;
public void ChangeNum(int X)
{
A=A+X;
C=0;
B=0;
while(C
{
C=C+1;
B=B+C;
}
if(A<0)
{
B=-B;
}
}
public AbsolutePosition()
{
setTitle("算...+一个整数");
setLayout(null);
setResizable(false);
Container container = getContentPane();
JButton B1=new JButton("+1");
JLabel L1=new JLabel("请计算");
JButton B2=new JButton("-1");
JButton B3=new JButton("+10");
JButton B4=new JButton("-10");
JButton B5=new JButton("+100");
JButton B6=new JButton("-100");
JButton B7=new JButton("设数为0");
JButton B8=new JButton("撤销");
L1.setBounds(120, 100, 300, 70);
B1.setBounds(120, 200, 200, 40);
B2.setBounds(320, 200, 200, 40);
B3.setBounds(120, 240, 200, 40);
B4.setBounds(320, 240, 200, 40);
B5.setBounds(120, 280, 200, 40);
B6.setBounds(320, 280, 200, 40);
B7.setBounds(120, 160, 200, 40);
B8.setBounds(320, 160, 200, 40);
B1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent E)
{
Undo=A;
ChangeNum(1);
L1.setText(""+B+"(...+"+A+")");
}
});
B2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent E)
{
Undo=A;
ChangeNum(-1);
L1.setText(""+B+"(...+"+A+")");
}
});
B3.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent E)
{
Undo=A;
ChangeNum(+10);
L1.setText(""+B+"(...+"+A+")");
}
});
B4.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent E)
{
Undo=A;
ChangeNum(-10);
L1.setText(""+B+"(...+"+A+")");
}
});
B5.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent E)
{
Undo=A;
ChangeNum(+100);
L1.setText(""+B+"(...+"+A+")");
}
});
B6.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent E)
{
Undo=A;
ChangeNum(-100);
L1.setText(""+B+"(...+"+A+")");
}
});
B7.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent E)
{
Undo=A;
A=0;
ChangeNum(0);
L1.setText(""+B+"(...+"+A+")");
}
});
B8.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent E)
{
A=Undo;
ChangeNum(0);
L1.setText(""+B+"(...+"+A+")");
}
});
L1.setFont(F);
L1.setForeground(Color.BLUE);
L1.setBackground(Color.WHITE);
container.add(B1);
container.add(L1);
container.add(B2);
container.add(B3);
container.add(B4);
container.add(B5);
container.add(B6);
container.add(B7);
container.add(B8);
setVisible(true);
setSize(660,480);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String [] args)
{
new AbsolutePosition();
}
}