该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
package homework;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class week {
private JFrame ftame;
private JButton b1[];
private JPanel panel,panel2;
private JTextField text1,text2,text3;
private JLabel label1,label2,label3;
week(){
int i;
String str[]={"星期一","星期二","星期三","星期四","星期五","星期六","星期日","1","2","3","4","5","6","7","8","9","0","="};
ftame=new JFrame("week");
ftame.setLayout(new GridLayout(2,1));
panel = new JPanel(new GridLayout(5,4));
label1=new JLabel(" 请输入星期数");
text1=new JTextField();
text1.setHorizontalAlignment(JTextField.RIGHT);
text1.setEnabled(false);
text1.setText("");
label2=new JLabel(" 请输入天数");
text2=new JTextField();
label3=new JLabel(" 结果");
text3=new JTextField();
JButton b1[]=new JButton[18];
for(i=0;i
{
b1[i]=new JButton(str[i]);
panel.add(b1[i]);
b1[i].addActionListener(new a());
}
ftame.setVisible(true);
ftame.setSize(400,400);
ftame.add(panel);
panel2=new JPanel(new GridLayout(3,1));
panel2.add(label1);
panel2.add(text1);
panel2.add(label2);
panel2.add(text2);
panel2.add(label3);
panel2.add(text3);
ftame.add(panel2);
}
class a implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
String str=b1[0].getText();
text1.setText(str+"ll");
}
}
}
/**
* @param args
*/
public static void main(String[] args) {
new week();
// TODO Auto-generated method stub
}
}