哥们我给你写完了,耽误了我半个小时的时间啊!你直接运行就可以了
import javaawtBorderLayout;
import javaawtFlowLayout;
import javaawteventActionEvent;
import javaawteventActionListener;
import javautilCalendar;
import javaxswingJButton;
import javaxswingJFrame;
import javaxswingJLabel;
import javaxswingJPanel;
import javaxswingJTextField;
public class Constellation implements ActionListener{
private JFrame frame = null;
private JTextField year = null;
private JTextField month = null;
private JTextField day = null;
private JLabel label1 = null;
private JLabel label2 = null;
private JLabel label3 = null;
private JPanel panel1 = null;
private JPanel panel2 = null;
private JButton button = null;
private JTextField output = null;
public static final String[] zodiacArr = { "猴", "鸡", "狗", "猪", "鼠", "牛", "虎", "兔", "龙", "蛇",
"马", "羊" };
public static final String[] constellationArr = { "水瓶座", "双鱼座", "牡羊座", "金牛座", "双子座", "巨蟹座",
"狮子座", "处女座", "天秤座", "天蝎座", "射手座", "魔羯座" };
public static final int[] constellationEdgeDay = { 20, 19, 21, 21, 21, 22, 23, 23, 23, 23, 22,
22 };
/
根据日期获取生肖
@return 11
/
public static String date2Zodica(Calendar time) {
return zodiacArr[timeget(CalendarYEAR) % 12];
}
/
根据日期获取星座
@param time
@return
/
public static String date2Constellation(Calendar time) {
int month = timeget(CalendarMONTH);
int day = timeget(CalendarDAY_OF_MONTH);
if (day < constellationEdgeDay[month]) {
month = month - 1;
}
if (month >= 0) {
return constellationArr[month];
}
// default to return 魔羯
return constellationArr[11];
}
public Constellation(){
frame = new JFrame("计算生肖,星座");
year = new JTextField("",3);
month = new JTextField("",3);
day = new JTextField("",3);
label1 = new JLabel("请输入年份:");
label2 = new JLabel(",请输入月份:");
label3 = new JLabel(",请输入日期:");
button = new JButton("查看结果");
buttonaddActionListener(this);
panel1 = new JPanel();
panel1setLayout(new FlowLayout(FlowLayoutCENTER));
panel1add(label1);
panel1add(year);
panel1add(label2);
panel1add(month);
panel1add(label3);
panel1add(day);
panel1add(button);
framesetLayout(new BorderLayout());
frameadd(panel1,BorderLayoutNORTH);
panel2 = new JPanel();
output = new JTextField("",40);
panel2add(output,JPanelCENTER_ALIGNMENT);
frameadd(panel2,BorderLayoutCENTER);
framesetSize(500, 100);
framesetDefaultCloseOperation(JFrameEXIT_ON_CLOSE);
framesetVisible(true);
}
public void actionPerformed(ActionEvent e) {
outputsetText("");
int y = IntegerparseInt(yeargetText());
int m = IntegerparseInt(monthgetText());
int d = IntegerparseInt(daygetText());
Calendar calendar = CalendargetInstance();
calendarset(CalendarYEAR, y);
calendarset(CalendarMONTH, m);
calendarset(CalendarDAY_OF_MONTH, d);
String zodica = date2Zodica(calendar);
String constellation = date2Constellation(calendar);
String str = "您输入的日期为:"+y+"年-"+m+"-月"+d+"日,得到的生肖:"+zodica+",星座:"+constellation;
outputsetText(str);
}
//testcode
public static void main(String[] args) {
new Constellation();
}
}
以上就是关于《Java语言程序设计基础篇》第六版的练习题和编程题答案全部的内容,包括:《Java语言程序设计基础篇》第六版的练习题和编程题答案、、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)