import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.event.*;
@SuppressWarnings({ "unused", "serial" })
public class MainFrame extends JFrame{
public static Container container;
public static JButton button1,button2,button3,button4;//声明4个命令按钮对象
public static JPanel panel1,panel2,panel3,panel4,panel5,panel6,panel7,panel8,panel9,panel10;//声明10个中间容器 public static JLabel label1,label2,label3,label4,label5,label6,label7,label8,label9,label10,label11,label12,label13,label14;
//声明14个label
public static JTextField t1,t2,t3,t4,t5;//声明5个TextField
public static JCheckBox ckb1,ckb2,ckb3,ckb4,ckb5,ckb6,ckb7;//声明7个CheckBox public static JRadioButton rbutton1,rbutton2;//声明2个JRadioButton
@SuppressWarnings("rawtypes")
public static JComboBox fieldComBox1,fieldComBox2,fieldComBox3,fieldComBox4; public static JTextArea jTextArea1;//声明1个文本域
public static JScrollPane centerPanel;//声明滚动面板
public static JMenu fileMenu1,fileMenu6,fileMenu10;//声明菜单文件
public static JMenuBar menuBar;//创建菜单栏
public static JMenuItem fileMenu2,fileMenu3,fileMenu4,fileMenu5,fileMenu7,fileMenu8,fileMenu9,fileMenu11; public static JScrollPane jScrollPane1,jScrollPane2;//声明滚动条
@SuppressWarnings("rawtypes")
public static JList jList;
public static JFileChooser fc;
@SuppressWarnings({ "unchecked", "rawtypes" })
public MainFrame(){
this.setTitle("个人简历设计窗口");//设置标题
container=this.getContentPane();//获取内容窗格
container.setLayout(null);//创建一个标准的命令按钮,
//按钮上的标签提示信息由构造方法中的参数指定
fc=new JFileChooser();
//panel初始化
panel1=new JPanel();
panel2=new JPanel();
panel3=new JPanel();
panel4=new JPanel();
panel5=new JPanel();
panel6=new JPanel();
panel7=new JPanel();
panel8=new JPanel();
panel9=new JPanel();
panel10=new JPanel();
//所有panel左对齐
panel2.setLayout(new FlowLayout(FlowLayout.LEFT));
panel3.setLayout(new FlowLayout(FlowLayout.LEFT));
panel4.setLayout(new FlowLayout(FlowLayout.LEFT));
panel5.setLayout(new FlowLayout(FlowLayout.LEFT));
panel6.setLayout(new FlowLayout(FlowLayout.LEFT));
panel7.setLayout(new FlowLayout(FlowLayout.LEFT));
panel8.setLayout(new FlowLayout(FlowLayout.LEFT));
//创建列表
jList=new JList();
jList.setSelectedIndex(3);
jScrollPane2=new JScrollPane(jList);
panel4.add(BorderLayout.CENTER,jScrollPane2);
jList.setVisibleRowCount(3);
Object data[] ={"Java程序设计","VB.net程序设计","网页制作","Flash动画制作","SQL数据库","数据结构"};
jList.setListData(data);
jList.setSelectedIndex(0);
jList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);//设置列表一次只能选择一个
//菜单文件
menuBar=new JMenuBar();//创建菜单栏
bulidMainMenu(menuBar);//自定义组建菜单的方法
//label初始化
label1=new JLabel("个人简历");//在panel1中
Font font = new Font("",10,30);//字体大小的设置
label1.setFont(font);
label2=new JLabel("姓名:");//在panel2中
label3=new JLabel("性别:");
label4=new JLabel("生日:");//在panel3中
label5=new JLabel("年");
label6=new JLabel("月");
label7=new JLabel("日");
label8=new JLabel("年龄:");
label9=new JLabel("政治面貌:");//在panel4中
label10=new JLabel("所学课程:");
label11=new JLabel("所学专业:");//在panel5中
label12=new JLabel("爱好:");//在panel6中
label13=new JLabel("毕业院校:");//在panel7中
label14=new JLabel("主要事迹:");//在lanel8中
//button初始化
button1=new JButton("提交");
button2=new JButton("保存");
button3=new JButton("退出");
button4=new JButton("清空");
//为事件注册监听者
button1.addActionListener(new tButtonEventHandle());
button2.addActionListener(new SaveActionListener());
button3.addActionListener(new ExitActionListener());
button4.addActionListener(new ClearActionListener());
//JTextField初始化
t1=new JTextField(25);
t2=new JTextField(5);
t2.setEditable(false);
t3=new JTextField(35);
t4=new JTextField(35);
t5=new JTextField(36);
//JCheckBox初始化
ckb1=new JCheckBox("唱歌");
ckb2=new JCheckBox("跳舞");
ckb3=new JCheckBox("乒乓球");
ckb4=new JCheckBox("篮球");
ckb5=new JCheckBox("足球");
ckb6=new JCheckBox("乐器");
ckb7=new JCheckBox("表演");
//文本域中添加滚动条
//文本域组件初始化
jTextArea1=new JTextArea(8,40);
jTextArea1.setEditable(false);//将该文本域设为不可编辑的
jScrollPane1=new JScrollPane(jTextArea1);
jScrollPane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
jScrollPane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
//jTextArea1.add(BorderLayout.CENTER,jScrollPane1);
//JRadioButton初始化
rbutton1=new JRadioButton("女");
rbutton2=new JRadioButton("男");
//将两个RadioButton对象放进ButtonGroup中,以实现二选一
ButtonGroup buttonGroup1=new ButtonGroup();
buttonGroup1.add(rbutton1);
buttonGroup1.add(rbutton2);
//分类下拉列表 //出生年份 fieldComBox1=new JComboBox(); //为年注册监听者 fieldComBox1.addActionListener(new fieldComBox1()); fieldComBox1.addItem("1980"); fieldComBox1.addItem("1981"); fieldComBox1.addItem("1982"); fieldComBox1.addItem("1983"); fieldComBox1.addItem("1984"); fieldComBox1.addItem("1985"); fieldComBox1.addItem("1986"); fieldComBox1.addItem("1987"); fieldComBox1.addItem("1988"); fieldComBox1.addItem("1989"); fieldComBox1.addItem("1990"); fieldComBox1.addItem("1991"); fieldComBox1.addItem("1992"); fieldComBox1.addItem("1993"); fieldComBox1.addItem("1994"); fieldComBox1.addItem("1995"); fieldComBox1.addItem("1996"); fieldComBox1.addItem("1997"); fieldComBox1.addItem("1998"); fieldComBox1.addItem("1999"); fieldComBox1.addItem("2000"); fieldComBox1.addItem("2001"); //月 fieldComBox2=new JComboBox(); //fieldComBox2.addActionListener(new tFieldComBox2()); fieldComBox2.addItem("1"); fieldComBox2.addItem("2"); fieldComBox2.addItem("3"); fieldComBox2.addItem("4"); fieldComBox2.addItem("5"); fieldComBox2.addItem("6"); fieldComBox2.addItem("7"); fieldComBox2.addItem("8"); fieldComBox2.addItem("9"); fieldComBox2.addItem("10"); fieldComBox2.addItem("11"); fieldComBox2.addItem("12"); //日 fieldComBox3=new JComboBox();
fieldComBox3.addItem("1"); fieldComBox3.addItem("2"); fieldComBox3.addItem("3"); fieldComBox3.addItem("4"); fieldComBox3.addItem("5"); fieldComBox3.addItem("6"); fieldComBox3.addItem("7"); fieldComBox3.addItem("8"); fieldComBox3.addItem("9"); fieldComBox3.addItem("10"); fieldComBox3.addItem("11"); fieldComBox3.addItem("12"); fieldComBox3.addItem("13"); fieldComBox3.addItem("14"); fieldComBox3.addItem("15"); fieldComBox3.addItem("16"); fieldComBox3.addItem("17"); fieldComBox3.addItem("18"); fieldComBox3.addItem("19"); fieldComBox3.addItem("20"); fieldComBox3.addItem("21"); fieldComBox3.addItem("22"); fieldComBox3.addItem("23"); fieldComBox3.addItem("24"); fieldComBox3.addItem("25"); fieldComBox3.addItem("26"); fieldComBox3.addItem("27"); fieldComBox3.addItem("28"); fieldComBox3.addItem("29"); fieldComBox3.addItem("30"); fieldComBox3.addItem("31"); //政治面貌 fieldComBox4=new JComboBox(); fieldComBox4.addItem("请选择..."); fieldComBox4.addItem("人民群众"); fieldComBox4.addItem("中国共青团团员"); fieldComBox4.addItem("中国共 产 党党员"); fieldComBox4.addItem("其他民主党派"); //panel中的组件 panel1.add(label1); panel2.add(label2); panel2.add(t1); panel2.add(label3);
panel2.add(rbutton1); panel2.add(rbutton2); panel3.add(label4); panel3.add(fieldComBox1); panel3.add(label5); panel3.add(fieldComBox2); panel3.add(label6); panel3.add(fieldComBox3); panel3.add(label7); panel3.add(label8); panel3.add(t2); panel4.add(label9); panel4.add(fieldComBox4); panel4.add(label10); panel4.add(jScrollPane2); panel5.add(label11); panel5.add(t3); panel6.add(label12); panel6.add(ckb1); panel6.add(ckb2); panel6.add(ckb3); panel6.add(ckb4); panel6.add(ckb5); panel6.add(ckb6); panel6.add(ckb7); panel7.add(label13); panel7.add(t4); panel8.add(label14); panel8.add(t5); panel9.add(jScrollPane1); panel10.add(button1); panel10.add(button2); panel10.add(button3); panel10.add(button4); //设置panel的位置坐标和宽、高 panel1.setBounds(50, 10, 500, 40); panel2.setBounds(50, 60, 500, 40); panel3.setBounds(50, 110, 500, 40); panel4.setBounds(50, 160, 500, 80); panel5.setBounds(50, 270, 500, 40); panel6.setBounds(50, 320, 500, 40); panel7.setBounds(50, 370, 500, 40); panel8.setBounds(50, 420, 500, 40); panel9.setBounds(20, 470, 550, 200);
panel10.setBounds(50, 680, 500, 40); /*将窗口位置放在屏幕中央*/ Dimension screensize=Toolkit.getDefaultToolkit().getScreenSize(); this.setSize(600, 800); Dimension framesize=this.getSize(); int x=(int)screensize.getWidth()/2-(int)framesize.getWidth()/2; int y=(int)screensize.getHeight()/2-(int)framesize.getHeight()/2; setLocation(x,y); container.add(panel1); container.add(panel2); container.add(panel3); container.add(panel4); container.add(panel5); container.add(panel6); container.add(panel7); container.add(panel8); container.add(panel9); container.add(panel10); this.setJMenuBar(menuBar);//将菜单栏挂到该窗口上 this.setVisible(true);//使窗口出来 this.setSize(600, 800);//设置窗口大小 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//关闭窗口时退出系统 } //构建菜单 public void bulidMainMenu(JMenuBar menuBar){ fileMenu1=new JMenu("管理"); fileMenu2=new JMenuItem("提交"); fileMenu3=new JMenuItem("保存"); fileMenu4=new JMenuItem("退出"); fileMenu5=new JMenuItem("清空"); fileMenu6=new JMenu("颜色"); fileMenu7=new JMenuItem("红色"); fileMenu8=new JMenuItem("绿色"); fileMenu9=new JMenuItem("蓝色"); fileMenu10=new JMenu("帮助"); fileMenu11=new JMenuItem("关于"); fileMenu2.addActionListener(new ReferActionListener());//为提交增加监听者 fileMenu3.addActionListener(new SaveActionListener());//为保存增加监听者 fileMenu4.addActionListener(new ExitActionListener());//为退出增加监听者 fileMenu5.addActionListener(new ClearActionListener());//为清空增加监听者 fileMenu7.addActionListener(new RedActionListener());//为红色增加监听者
fileMenu8.addActionListener(new GreenActionListener());//为绿色增加监听者 fileMenu9.addActionListener(new BlueActionListener());//为蓝色增加监听者 fileMenu11.addActionListener(new AboutActionListener());//为关于增加监听者 menuBar.add(fileMenu1); menuBar.add(fileMenu6); menuBar.add(fileMenu10); fileMenu1.add(fileMenu2); fileMenu1.add(fileMenu3); fileMenu1.add(fileMenu4); fileMenu1.add(fileMenu5); fileMenu6.add(fileMenu7); fileMenu6.add(fileMenu8); fileMenu6.add(fileMenu9); fileMenu10.add(fileMenu11); } //年下拉框事件监听者 class fieldComBox1 implements ActionListener{ public void actionPerformed(ActionEvent e){ String str=(String)fieldComBox1.getSelectedItem(); int n; n=2012-Integer.parseInt(str); t2.setText(String.valueOf(n)); } } // public String getsex(){ if(rbutton2.isSelected()) return "男"; return "女"; } // public String getlove(){ String love=""; if(ckb1.isSelected()) love+= "唱歌 "; if(ckb2.isSelected()) love+= "跳舞 "; if(ckb3.isSelected()) love+= "乒乓球 "; if(ckb4.isSelected()) love+= "篮球 "; if(ckb5.isSelected()) love+= "足球 "; if(ckb6.isSelected())
// // // // // //
love+= "乐器 "; if(ckb7.isSelected()) love+= "表演 "; return love; } //提交Button事件监听者 class tButtonEventHandle implements ActionListener{ public void actionPerformed(ActionEvent e){ String str1=t1.getText(); String str2=(String)fieldComBox1.getSelectedItem(); String str3=(String)fieldComBox2.getSelectedItem(); String str4=(String)fieldComBox3.getSelectedItem(); String str5=t2.getText(); String str6=(String)fieldComBox4.getSelectedItem(); String str7=jList.getSelectedValuesList().toString(); @SuppressWarnings("deprecation") Object[] ff=jList.getSelectedValues(); int i; String str7=""; for(i=0;i<ff.length;i++) str7=str7+ff[i].toString()+" "; String str8=t3.getText(); String str9=t4.getText(); String str10=t5.getText(); jTextArea1.append("姓名:"+str1+"\n"); jTextArea1.append("性别:"+getsex()+"\n"); jTextArea1.append("生日:"+str2); jTextArea1.append("年"+str3+"月"); jTextArea1.append(str4+"日"+"\n"); jTextArea1.append("年龄:"+str5+"\n"); jTextArea1.append("政治面貌:"+str6+"\n"); jTextArea1.append("所学课程:"+str7+"\n"); jTextArea1.append("所学专业:"+str8+"\n"); jTextArea1.append("爱好:"+getlove()+"\n"); jTextArea1.append("毕业院校:"+str9+"\n"); jTextArea1.append("主要事迹:"+str10+"\n"); } } //菜单中提交菜单项的事件监听者 class ReferActionListener implements ActionListener{ public void actionPerformed(ActionEvent event){ String str1=t1.getText(); String str2=(String)fieldComBox1.getSelectedItem(); String str3=(String)fieldComBox2.getSelectedItem();
String str4=(String)fieldComBox3.getSelectedItem();
String str5=t2.getText();
String str6=(String)fieldComBox4.getSelectedItem();
String str7=jList.getSelectedValuesList().toString();
String str8=t3.getText();
String str9=t4.getText();
String str10=t5.getText();
if(str1!=null&&!"".equals(str1)&&str2!=null&&!"".equals(str2)&&str3!=null&&!"".equals(str3)&&str4!=null&&!"".equals(str4)&&str5!=null&&!"".equals(str5)&&str6!=null&&!"".equals(str6)&&str7!=null&&!"".equals(str7)&&str8!=null&&!"".equals(str8)&&str9!=null&&!"".equals(str9)&&str10!=null&&!"".equals(str10)){
JOptionPane.showConfirmDialog(container,"是否真的要提交?","提示信息",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE );
jTextArea1.append("姓名:"+str1+"\n");
jTextArea1.append("性别:"+getsex()+"\n");
jTextArea1.append("生日:"+str2);
jTextArea1.append("年"+str3+"月");
jTextArea1.append(str4+"日"+"\n");
jTextArea1.append("年龄:"+str5+"\n");
jTextArea1.append("政治面貌:"+str6+"\n");
jTextArea1.append("所学课程:"+str7+"\n");
jTextArea1.append("所学专业:"+str8+"\n");
jTextArea1.append("爱好:"+getlove()+"\n");
jTextArea1.append("毕业院校:"+str9+"\n");
jTextArea1.append("主要事迹:"+str10+"\n");
}
else
{
JOptionPane.showMessageDialog(container,"提交信息不能为空!","提示信息",JOptionPane.INFORMATION_MESSAGE );
}
}
}
//菜单中保存菜单项事件监听者
class SaveActionListener implements ActionListener{
public void actionPerformed(ActionEvent e){
int select=fc.showSaveDialog(fileMenu3);
if(select==JFileChooser.APPROVE_OPTION){
File file=fc.getSelectedFile();
try{
FileWriter fw=new FileWriter(file);
fw.write(jTextArea1.getText());
fw.close();
} catch(IOException a){} System.out.println("文件"+file.getName()+"被保存"); } } } //菜单中红色菜单项事件监听者 class RedActionListener implements ActionListener{ public void actionPerformed(ActionEvent event){ panel1.setBackground(Color.red); panel2.setBackground(Color.red); panel3.setBackground(Color.red); panel4.setBackground(Color.red); panel5.setBackground(Color.red); panel6.setBackground(Color.red); panel7.setBackground(Color.red); panel8.setBackground(Color.red); panel9.setBackground(Color.red); panel10.setBackground(Color.red); container.setBackground(Color.red); } } //菜单中绿色菜单项事件监听者 class GreenActionListener implements ActionListener{ public void actionPerformed(ActionEvent event){ panel1.setBackground(Color.green); panel2.setBackground(Color.green); panel3.setBackground(Color.green); panel4.setBackground(Color.green); panel5.setBackground(Color.green); panel6.setBackground(Color.green); panel7.setBackground(Color.green); panel8.setBackground(Color.green); panel9.setBackground(Color.green); panel10.setBackground(Color.green); container.setBackground(Color.green); } } //菜单中蓝色菜单项事件监听者 class BlueActionListener implements ActionListener{ public void actionPerformed(ActionEvent event){ panel1.setBackground(Color.blue); panel2.setBackground(Color.blue);
panel3.setBackground(Color.blue);
panel4.setBackground(Color.blue);
panel5.setBackground(Color.blue);
panel6.setBackground(Color.blue);
panel7.setBackground(Color.blue);
panel8.setBackground(Color.blue);
panel9.setBackground(Color.blue);
panel10.setBackground(Color.blue);
container.setBackground(Color.blue);
}
}
//菜单中清空菜单项的事件监听者
class ClearActionListener implements ActionListener{
public void actionPerformed(ActionEvent event){
int result=JOptionPane.showConfirmDialog(container,"是否真的清空?","提示信息",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE );
if(result==0){
jTextArea1.setText("");
}
}
}
//菜单中关于菜单项的事件监听者
class AboutActionListener implements ActionListener{
public void actionPerformed(ActionEvent event){
String msg="个人简历系统 V1.0\n制作日期20xx年5月16日\nBy Auther:赵艳辉";
String title="做个好简历,找到好工作!";
JOptionPane.showMessageDialog(container,
msg,title,JOptionPane.INFORMATION_MESSAGE);
}
}
//菜单中退出菜单项的事件监听者
class ExitActionListener implements ActionListener{
public void actionPerformed(ActionEvent event){
int result=JOptionPane.showConfirmDialog(container,"是否真的退出系统的使用?","提示信息",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE ); if(result==0){
System.exit(0);
}
}
}
public static void main(String[] args){
new MainFrame();
} }