第一个java应用程序的代码

/*
* VALUE.java
*
* Created on 2007年1月10日, 下午6:42
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package star;

/**
*
* @author Amy Show
*/
public final class VALUE {

static String[] constellationName={
new String("AQUARIUS 水瓶座 Jan. 20 - Feb. 18"),new String("PISCES 双鱼座 Feb. 19 - Mar. 20"),new String("MAR 牡羊座 Mar. 21 - April. 19"),
new String("TAURUS 金牛座 April. 20 - May. 20"),new String("GEMINI 双子座 May. 21 - June. 21"),new String("CANCER 巨蟹座 June. 22 - July. 22"),
new String("LEO 狮子座 July. 23 - Aug. 22"),new String("VIRGO 处女座 Aug. 23 - Sept. 22"),new String("LIBRA 天枰座 Sept. 23 - Oct. 23"),
new String("SCORPIO 天蝎座 Oct. 24 - Nov. 21"),new String("SAGITTARIUS 射手座 Nov. 22 - Dec. 21"),new String("CAPRICORN 摩羯座 Dec. 22 - Jan. 19")
};
static int[] startCode = {120,219,321,420,521,622,723,823,923,1024,1122,1222};
static String[] constellationMean={
new String("Aquarius the Water Bearer is an Summer constellation, and can be best viewed in the night sky during the month of September."),
new String("Pisces the Fishes in an Autumn constellation, and can be best viewed in the night sky during the month of October."),
new String("Aries the Ram is an Autumn constellation, and can be best viewed in the night sky during the month of November."),
new String("Taurus the Bull is an Autumn constellation, and can be best viewed in the night sky during the month of December."),
new String("Gemini the Twins is a Winter constellation, and can be best viewed in the night sky during the month of January."),
new String("Cancer the Crab is a Winter Constellation, and can be best viewed in the night sky during the month of February."),
new String("Leo the Lion is a Winter constellation, and can be best viewed in the night during the month of March."),
new String("Virgo the Virgin is a Spring constellation, and can be best viewed during the month of April."),
new String("Libra the Scales is a Spring constellation, and can be best viewed in the night sky during the month of May."),
new String("Scorpio the Scorpion is a Spring constellation with an astronomical name of Scorpius, and can be best viewed in the night sky during the month of June."),
new String("Sagittarius the Archer is a Summer constellation, and can be best viewed in the night sky during the month July."),
new String("Capricorn the Sea Goat is a Summer constellation with an astronomical name of Capricornus, and can be best viewed in the night sky during the month of August.")
};

}

------------------------------------------------------------------------------------------------------

/*
* Constellation.java
*
* Created on 2007年1月10日, 下午6:40
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package star;

/**
*
* @author Amy Show
*/
public class Constellation {

int constellationCode;
int startCode;
String Name;
String Mean;

public Constellation(int i) {
this.constellationCode=i;
this.startCode=VALUE.startCode[i];
this.Name=VALUE.constellationName[i];
this.Mean=VALUE.constellationMean[i];
}

}

------------------------------------------------------------------------------------------------------

/*
* Star.java
*
* Created on 2007年1月10日, 下午6:43
*/

package star;

/**
*
* @author Amy Show
*/
public class Star extends javax.swing.JFrame {

int month = 1,
day = 1;
public Star() {
initComponents();
}

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// //GEN-BEGIN:initComponents
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jComboBox1 = new javax.swing.JComboBox();
jLabel2 = new javax.swing.JLabel();
jComboBox2 = new javax.swing.JComboBox();
jLabel3 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jPanel2 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("u661fu5ea7u67e5u770bu5668 BY Amy Show");
jLabel1.setText("u8bf7u8f93u5165u4f60u7684u751fu65e5:");

jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" }));
jComboBox1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
getMonth(evt);
}
});

jLabel2.setText("u6708");

jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));
jComboBox2.setSelectedItem(jComboBox2.getActionListeners());
jComboBox2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
getDay(evt);
}
});

jLabel3.setText("u65e5");

jButton1.setText("u67e5u770b");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
down(evt);
}
});

org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel1)
.add(jPanel1Layout.createSequentialGroup()
.add(jComboBox1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jLabel2)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jComboBox2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jLabel3)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 53, Short.MAX_VALUE)
.add(jButton1)))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.add(jLabel1)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jComboBox1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jLabel2)
.add(jComboBox2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jLabel3)
.add(jButton1))
.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);

jTextArea1.setBackground(new java.awt.Color(236, 233, 216));
jTextArea1.setColumns(20);
jTextArea1.setEditable(false);
jTextArea1.setLineWrap(true);
jTextArea1.setRows(5);
jTextArea1.setText("*u661fu5ea7u67e5u770bu5668*nBY Amy Shown2007.1.10");
jTextArea1.setWrapStyleWord(true);
jScrollPane1.setViewportView(jTextArea1);

org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 240, Short.MAX_VALUE)
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 116, Short.MAX_VALUE)
);

org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// //GEN-END:initComponents

private void down(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_down
int c = 0;
Constellation constellation[] = new Constellation[12];
for(c=0;c<12;c++){
constellation[c]=new Constellation(c);
};
int d = 0,
i = 0;
d = month*100 + day;

if(d<120){
i = 11;
}
else{
for(i=0;i<11;i++){
if(d>=constellation[i+1].startCode)
continue;
else
break;
}
}

jTextArea1.setText(constellation[i].Name+"nn"+constellation[i].Mean);
}//GEN-LAST:event_down

private void getDay(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_getDay
day = Integer.parseInt(jComboBox2.getSelectedItem().toString());
}//GEN-LAST:event_getDay

private void getMonth(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_getMonth
month = Integer.parseInt(jComboBox1.getSelectedItem().toString());
}//GEN-LAST:event_getMonth

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Star().setVisible(true);
}
});
}

// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JComboBox jComboBox1;
private javax.swing.JComboBox jComboBox2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
// End of variables declaration//GEN-END:variables

}

[@more@]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/7921040/viewspace-889667/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/7921040/viewspace-889667/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值