java求和 1到100之和

package count;

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.*;

public class count{

public static void main(String[] args) {

MyFrame mf=new MyFrame();

}

}

class MyFrame extends JFrame {

JTextField f;

JLabel L1;

JButton b1;

public MyFrame(){

this("count");

}

public MyFrame(String title){

super(title);

setSize(300,280);

setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

b1=new JButton("计算");

f=new JTextField("",11);

L1=new JLabel("1+2+···+100",JLabel.RIGHT);

b1.addActionListener((ActionListener) new inclass());

add(L1);

add(b1);

add(f);

FlowLayout flow=new FlowLayout(FlowLayout.CENTER,18,20);

setLayout(flow);

center(this);

setVisible(true);

}

public void center(JFrame frame){

Toolkit toolkit=Toolkit.getDefaultToolkit();

Dimension dim=toolkit.getScreenSize();

int screenWidth=dim.width;

int screenHeight=dim.height;

int w=frame.getWidth();

int h=frame.getHeight();

int x=(screenWidth-w)/2;

int y=(screenHeight-h)/2;

frame.setLocation(x,y);

}

}

}

相关推荐
相关主题
热门推荐