?? j023231.java
字號:
/******************************************************************************************/
//這是一個java運用程序用于模擬書上的雇員類 的各種功能******************************************/
//程序版本v1.0******************************************************************************/
//完成時間2004年10月28日*********************************************************************/
//作者:計算機系023班苗海泉23號***************************************************************/
//******************************************************************************************/
import java.applet.Applet;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class J023231 extends JFrame implements ActionListener ,ItemListener //實現(xiàn)接口ItemListener和接口ActionListener
{
private JLabel name,no,sex,class1,age,deptment; //聲明一些提示標簽
private JTextField jname,jclass1,jage,jdeptment,jno; //聲明各種輸出對話框
private Button1 jbclear,jbcertain,jbclose; //聲明各種相應(yīng)按鈕
private JComboBox cp1; //聲明選擇下拉表
private JTextArea ta1;
private Student str1,str2,str3,str; //定義學(xué)生對象
J023231()
{
super("學(xué)生信息系統(tǒng)"); //調(diào)用父類方法完成標題顯示
str1=new Student("lou","男",20,"計算機" ,"023"); //定義三個學(xué)生對象
str2=new Student("li","女",23,"計算機","023");
str3=new Student("fei","男",20,"計算機","023");
str=new Student();
name=new JLabel("姓名"); //定義一些組件
no=new JLabel("學(xué)號");
sex=new JLabel("性別");
class1=new JLabel("班級");
age=new JLabel("年齡");
deptment=new JLabel("系別");
jname=new JTextField(8);
jno=new JTextField(8);
jclass1=new JTextField(8);
jage=new JTextField(8);
jdeptment=new JTextField(13);
jbclear=new Button1("清除");
jbcertain=new Button1("修改");
jbclose=new Button1("退出");
jbcertain.setToolTipText("輸入要修改的學(xué)生的學(xué)號"); //定義按鈕上提示標簽的內(nèi)容
String str[]={" 男 "," 女 "}; //定義下拉表單上的內(nèi)容
cp1=new JComboBox(str); //定義下拉表單
cp1.setFont(new Font("宋體",Font.BOLD,20)); //設(shè)置下拉表單字體大小,類型
cp1.setForeground(new Color(3,3,124)); //設(shè)置下拉表單字體顏色
cp1.setBackground(new Color(255,255,255)); //設(shè)置下拉表單背景顏色
ta1=new JTextArea(str1.toString()+str2.toString()+str3.toString()); //定義文本顯示區(qū)及內(nèi)容
ta1.setBounds(new Rectangle(0,0,400,400)); // 設(shè)置文本區(qū)大小
ta1.setFont(new Font("宋體",Font.BOLD,20)); //設(shè)置文本區(qū)字體大小,類型
ta1.setForeground(new Color(3,3,124)); //設(shè)置文本區(qū)字體顏色
ta1.setLineWrap(true); // 設(shè)置文本區(qū)換行操作
ta1.setWrapStyleWord(true); //設(shè)置文本區(qū)每個單詞換行
name.setFont(new Font("宋體",Font.BOLD,20)); //設(shè)置提示字體大小,類型
name.setForeground(new Color(3,3,124)); //設(shè)置提示字體顏色
no.setFont(new Font("宋體",Font.BOLD,20)); //設(shè)置提示字體大小,類型
no.setForeground(new Color(3,3,124)); //設(shè)置提示字體顏色
sex.setFont(new Font("宋體",Font.BOLD,20)); //設(shè)置提示字體大小,類型
sex.setForeground(new Color(3,3,124)); //設(shè)置提示字體顏色
class1.setFont(new Font("宋體",Font.BOLD,20)); //設(shè)置提示字體大小,類型
class1.setForeground(new Color(3,3,124)); //設(shè)置提示字體顏色
age.setFont(new Font("宋體",Font.BOLD,20)); //設(shè)置提示字體大小,類型
age.setForeground(new Color(3,3,124)); //設(shè)置提示字體顏色
deptment.setFont(new Font("宋體",Font.BOLD,20)); //設(shè)置提示字體大小,類型
deptment.setForeground(new Color(3,3,124)); //設(shè)置提示字體顏色
Container container=getContentPane(); //得到容器對象
container.setLayout(new FlowLayout(FlowLayout.LEFT,10,20 )); //設(shè)置容器中的對象排列方式
container.setBackground(new Color(117,224,227)); //設(shè)置容器背景顏色
container.add(no);container.add(jno); //向容器中添加各種組件
container.add(name);container.add(jname);
container.add(sex);container.add(cp1,BorderLayout.EAST);
container.add(class1);container.add(jclass1);
container.add(age); container.add(jage);
container.add(deptment);container.add(jdeptment);
container.add(jbclear);container.add(jbcertain);
container.add(jbclose);container.add(ta1);
jbclear.addActionListener(this); //給各種按鈕添加監(jiān)聽器
jbcertain.addActionListener(this);
jbclose.addActionListener(this);
cp1.addItemListener(this); //為菜單注冊事件,事件的監(jiān)聽者為當(dāng)前類的對象this
setSize(550,400); //設(shè)置窗體大小
setVisible(true); //設(shè)置窗體可見屬性
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==jbclear) //響應(yīng)清除按鈕
{
jname.setText("");
jno.setText("");
jage.setText("");
jdeptment.setText("");
jclass1.setText("");
}
else if(e.getSource()==jbclose) //響應(yīng)關(guān)閉按鈕
{
dispose();
System.exit(0);
}
else if(e.getSource()==jbcertain) //響應(yīng)確定按鈕
{
if((Integer.parseInt(jno.getText())!=10001)&&(Integer.parseInt(jno.getText())!=10002)&&(Integer.parseInt(jno.getText())!=10003))
{
JOptionPane.showMessageDialog(null,"錯誤:學(xué)號不對\n 不可修改"); //提示對話筐
}
else if(Integer.parseInt(jno.getText())==10001) //改變學(xué)生一的屬性
{
fution(str1); //調(diào)用公共方法
}
else if(Integer.parseInt(jno.getText())==10002) //改變學(xué)生二的屬性
{
fution(str2); //調(diào)用公共方法
}
else if(Integer.parseInt(jno.getText())==10003) //改變學(xué)生三的屬性
{
fution(str2); //調(diào)用公共方法
}
}
}
public void itemStateChanged(ItemEvent e) //處理下拉式菜單的單擊事件
{
if(cp1.getSelectedItem()==" 男 ")
{
str.resetSex("男"); //如果選中男將公共學(xué)生的性別置為男
}
else if(cp1.getSelectedItem()==" 女 ")
{
str.resetSex( "女"); //如果選中女將學(xué)生的性別置為女
}
}
public void fution( Student str0 ) //將各種共同操作定義為一方法
{
if(!jname.getText().equals("")) //判斷學(xué)生姓名是否被改變
{
str0.resetName(jname.getText());
}
if(!jclass1.getText().equals("")) // 判斷學(xué)生班級是否被改變
{
str0.resetClass(jclass1.getText());
}
if(!jdeptment.getText().equals("")) //判斷學(xué)生的系別是否被改變
{
str0.resetDeptment(jdeptment.getText());
} //判斷學(xué)生的年齡是否被改變
if(!jage.getText().equals(""))
{
if(! str0.resetAge(Integer.parseInt(jage.getText())))
JOptionPane.showMessageDialog(null,"年齡不可為零"); //用對話框提示用戶
}
str0.resetSex(str.m_Sex); //用公共學(xué)生性別設(shè)置一個學(xué)生的性別
ta1.setText(str1.toString()+str2.toString()+str3.toString());//在輸出區(qū)打印出學(xué)生信息
JOptionPane.showMessageDialog(null,"成功更改"); //成功修改的對話框
}
public static void main(String arg[]) //主函數(shù)
{
J023231 gui=new J023231();
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -