儿童轮滑鞋哪个牌子好:请教JAVA问题

来源:百度文库 编辑:高考问答 时间:2024/04/27 03:41:34
用java做一个:
1.大小,背景颜色自定,标题随便。
2.点“输入偶数”按钮,文本框中依次显示10一内的偶数。
注意:不能使用SetText("2.4.6.8.10").形式的语句。(也就是用一个循环语句。)
界面就是一个一个文本框和一个按钮。用AWT的包

先谢谢大家了~~~~~

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Baidu extends JFrame implements ActionListener
{
private static final long serialVersionUID = 1L;

Container con = null;
JPanel pCenter = null;
JButton btnSet = null;
JTextField pairNum = null;

public Baidu()
{
pairNum = new JTextField(15);
pairNum.setEditable(false);

btnSet = new JButton("输入偶数");
btnSet.addActionListener(this);

con = getContentPane();
pCenter = new JPanel();
pCenter.add(pairNum);
pCenter.add(btnSet);

con.add(pCenter,BorderLayout.CENTER);
con.validate();
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
setVisible(true);

setBounds(100,50,420,380);//大小

setTitle("标题");

setBackground(Color.RED); //背景色

validate();

}

public void actionPerformed(ActionEvent e)
{
if (e.getSource() == btnSet)
{
String str = "";
for (int i = 0; i <= 10; i+=2)
str += i + ",";
pairNum.setText(str.substring(0, str.length() - 1));
}
}

public static void main(String[] args)
{
new Baidu();
}
}