📄 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 //实现接口ItemListener和接口ActionListener
{
private JLabel name,no,sex,class1,age,deptment; //声明一些提示标签
private JTextField jname,jclass1,jage,jdeptment,jno; //声明各种输出对话框
private Button1 jbclear,jbcertain,jbclose; //声明各种相应按钮
private JComboBox cp1; //声明选择下拉表
private JTextArea ta1;
private Student str1,str2,str3,str; //定义学生对象
J023231()
{
super("学生信息系统"); //调用父类方法完成标题显示
str1=new Student("lou","男",20,"计算机" ,"023"); //定义三个学生对象
str2=new Student("li","女",23,"计算机","023");
str3=new Student("fei","男",20,"计算机","023");
str=new Student();
name=new JLabel("姓名"); //定义一些组件
no=new JLabel("学号");
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("输入要修改的学生的学号"); //定义按钮上提示标签的内容
String str[]={" 男 "," 女 "}; //定义下拉表单上的内容
cp1=new JComboBox(str); //定义下拉表单
cp1.setFont(new Font("宋体",Font.BOLD,20)); //设置下拉表单字体大小,类型
cp1.setForeground(new Color(3,3,124)); //设置下拉表单字体颜色
cp1.setBackground(new Color(255,255,255)); //设置下拉表单背景颜色
ta1=new JTextArea(str1.toString()+str2.toString()+str3.toString()); //定义文本显示区及内容
ta1.setBounds(new Rectangle(0,0,400,400)); // 设置文本区大小
ta1.setFont(new Font("宋体",Font.BOLD,20)); //设置文本区字体大小,类型
ta1.setForeground(new Color(3,3,124)); //设置文本区字体颜色
ta1.setLineWrap(true); // 设置文本区换行操作
ta1.setWrapStyleWord(true); //设置文本区每个单词换行
name.setFont(new Font("宋体",Font.BOLD,20)); //设置提示字体大小,类型
name.setForeground(new Color(3,3,124)); //设置提示字体颜色
no.setFont(new Font("宋体",Font.BOLD,20)); //设置提示字体大小,类型
no.setForeground(new Color(3,3,124)); //设置提示字体颜色
sex.setFont(new Font("宋体",Font.BOLD,20)); //设置提示字体大小,类型
sex.setForeground(new Color(3,3,124)); //设置提示字体颜色
class1.setFont(new Font("宋体",Font.BOLD,20)); //设置提示字体大小,类型
class1.setForeground(new Color(3,3,124)); //设置提示字体颜色
age.setFont(new Font("宋体",Font.BOLD,20)); //设置提示字体大小,类型
age.setForeground(new Color(3,3,124)); //设置提示字体颜色
deptment.setFont(new Font("宋体",Font.BOLD,20)); //设置提示字体大小,类型
deptment.setForeground(new Color(3,3,124)); //设置提示字体颜色
Container container=getContentPane(); //得到容器对象
container.setLayout(new FlowLayout(FlowLayout.LEFT,10,20 )); //设置容器中的对象排列方式
container.setBackground(new Color(117,224,227)); //设置容器背景颜色
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); //给各种按钮添加监听器
jbcertain.addActionListener(this);
jbclose.addActionListener(this);
cp1.addItemListener(this); //为菜单注册事件,事件的监听者为当前类的对象this
setSize(550,400); //设置窗体大小
setVisible(true); //设置窗体可见属性
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==jbclear) //响应清除按钮
{
jname.setText("");
jno.setText("");
jage.setText("");
jdeptment.setText("");
jclass1.setText("");
}
else if(e.getSource()==jbclose) //响应关闭按钮
{
dispose();
System.exit(0);
}
else if(e.getSource()==jbcertain) //响应确定按钮
{
if((Integer.parseInt(jno.getText())!=10001)&&(Integer.parseInt(jno.getText())!=10002)&&(Integer.parseInt(jno.getText())!=10003))
{
JOptionPane.showMessageDialog(null,"错误:学号不对\n 不可修改"); //提示对话筐
}
else if(Integer.parseInt(jno.getText())==10001) //改变学生一的属性
{
fution(str1); //调用公共方法
}
else if(Integer.parseInt(jno.getText())==10002) //改变学生二的属性
{
fution(str2); //调用公共方法
}
else if(Integer.parseInt(jno.getText())==10003) //改变学生三的属性
{
fution(str2); //调用公共方法
}
}
}
public void itemStateChanged(ItemEvent e) //处理下拉式菜单的单击事件
{
if(cp1.getSelectedItem()==" 男 ")
{
str.resetSex("男"); //如果选中男将公共学生的性别置为男
}
else if(cp1.getSelectedItem()==" 女 ")
{
str.resetSex( "女"); //如果选中女将学生的性别置为女
}
}
public void fution( Student str0 ) //将各种共同操作定义为一方法
{
if(!jname.getText().equals("")) //判断学生姓名是否被改变
{
str0.resetName(jname.getText());
}
if(!jclass1.getText().equals("")) // 判断学生班级是否被改变
{
str0.resetClass(jclass1.getText());
}
if(!jdeptment.getText().equals("")) //判断学生的系别是否被改变
{
str0.resetDeptment(jdeptment.getText());
} //判断学生的年龄是否被改变
if(!jage.getText().equals(""))
{
if(! str0.resetAge(Integer.parseInt(jage.getText())))
JOptionPane.showMessageDialog(null,"年龄不可为零"); //用对话框提示用户
}
str0.resetSex(str.m_Sex); //用公共学生性别设置一个学生的性别
ta1.setText(str1.toString()+str2.toString()+str3.toString());//在输出区打印出学生信息
JOptionPane.showMessageDialog(null,"成功更改"); //成功修改的对话框
}
public static void main(String arg[]) //主函数
{
J023231 gui=new J023231();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -