无聊写个十二星座。。
我发现我好像都是无聊的时候学习的。。。
package 十二星座;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class 十二星座 {
public static void main(String args[]){
new Fram();
}
}
class Fram extends JFrame implements ActionListener{
JTextField inputYear,inputMon,inputDay;
JPanel panel1;
JButton button;
JLabel image,text,remind;
String hor[]={"水瓶座","双鱼座","白羊座","金牛座","双子座","巨蟹座","狮子座","处女座","天秤座",
"天蝎座","射手座","摩羯座"};
Fram(){
inputYear=new JTextField(3);
inputMon=new JTextField(3);
inputDay=new JTextField(3);
button=new JButton("确定");
panel1=new JPanel();
remind=new JLabel("请输入年-月-日:");
remind.setForeground(Color.DARK_GRAY);
panel1.add(remind);panel1.add(inputYear);panel1.add(inputMon);panel1.add(inputDay);panel1.add(button);
add(panel1,BorderLayout.NORTH);
image=new JLabel(new ImageIcon("image/十二星座.jpg"));
add(image,BorderLayout.CENTER);
text=new JLabel("***星座***",JLabel.CENTER);
text.setFont(new Font("宋体",Font.BOLD,16));
text.setForeground(Color.green);
add(text,BorderLayout.SOUTH);
button.addActionListener(this);
ImageIcon tubiao=new ImageIcon("image/图标.jpg");
setIconImage(tubiao.getImage());
setResizable(false);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(340,270,320,450);
setTitle("十二星座");
}
public void actionPerformed(ActionEvent e){
try{
Integer year,mon,day,mark;
year=Integer.parseInt(inputYear.getText());
mon=Integer.parseInt(inputMon.getText());
day=Integer.parseInt(inputDay.getText());
if((mon==1&&day>=20)||(mon==2&&day<=18))
mark=0;
else if((mon==2&&day>=19)||(mon==3&&day<=20))
mark=1;
else if((mon==3&&day>=21)||(mon==4&&day<=19))
mark=2;
else if((mon==4&&day>=20)||(mon==5&&day<=20))
mark=3;
else if((mon==5&&day>=21)||(mon==6&&day<=21))
mark=4;
else if((mon==6&&day>=22)||(mon==7&&day<=22))
mark=5;
else if((mon==7&&day>=23)||(mon==8&&day<=22))
mark=6;
else if((mon==8&&day>=23)||(mon==9&&day<=22))
mark=7;
else if((mon==9&&day>=23)||(mon==10&&day<=23))
mark=8;
else if((mon==10&&day>=24)||(mon==11&&day<=22))
mark=9;
else if((mon==11&&day>=23)||(mon==12&&day<=21))
mark=10;
else
mark=11;
image.setIcon(new ImageIcon("image/"+hor[mark]+".jpg"));
text.setText("***"+hor[mark]+"***");
}
catch(Exception exp){
text.setText("请输入数字字符\n");
}
}
}
这是部分运行结
//背景图片需要在工程里建一个文件夹名image在文件夹里存入相应名称的图片,//如果你没有新建image文件夹并存入对应的图片 界面会是空白的注意。果
另外附上我的十二星座图片