hello,大家好,你们的王小白来更新Java课设的最后的一步了,可视化的图形界面,运用了swing的设计进行的(比较丑)但是逻辑简单适合新手操作,由于可视化图已经再上一篇博客中进行展示,这一片就直接放代码了!大家也可直接下载已经打包好的完整源代码(自己写的肯定好用)!
和下文代码相同,只是已经打包好了
先来列表信息
public class Information extends JFrame implements ActionListener{
JButton jb5;
JButton jb4;
JButton jb3;
JButton jb2;
JButton jb1;
JLabel text;
JLabel text2;
JLabel text3;
JLabel text4;
public Information() {
JFrame frame = new JFrame("新窗口");
this.setSize(700,700);
this.setVisible(true);
this.setLayout(new FlowLayout());
this.setLayout(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
text = new JLabel("欢迎来到学生信息管理系统");
jb5=new JButton ("更新学生");
jb4=new JButton ("查询学生");
jb3=new JButton ("删除学生");
jb2=new JButton ("增加学生");
jb1=new JButton ("列表信息");
this.add(jb1);
this.add(jb2);
this.add(jb3);
this.add(jb4);
this.add(jb5);
this.add(text);
jb1.setBounds(50,300, 100, 50);
jb2.setBounds(160,300, 100, 50);
jb3.setBounds(270,300, 100, 50);
jb4.setBounds(380,300, 100, 50);
jb5.setBounds(490,300, 100, 50);
text.setBounds(180,100,400, 50);
text.setFont(new Font("宋体",1,24));
jb1.addActionListener(this);
jb2.addActionListener(this);
jb3.addActionListener(this);
jb4.addActionListener(this);
jb5.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == jb1) {
new Listview();
}else if (e.getSource() == jb2){
new Addview();
}else if (e.getSource() == jb3){
new Deleteview();
}else if (e.getSource() ==jb4){
new Getview();
}else if (e.getSource() == jb5){
new Upateview();
}
}
}
下一个是显示数据库中所有学生的信息(这里运用到Jtable的知识)
```java
import java.awt.*;
import com.stif.dao.StudentDao;
import com.stif.model.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.GroupLayout.Alignment;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
import java.util.List;
import javax.swing.table.DefaultTableModel;
public class Listview extends JFrame{
private JFrame container;
private JTable table;
private String columnName[]=null;
private Object [][]data=null;
private StudentDao stu = new StudentDao();
public Listview(){
columnName = new String[]{
"学号","姓名","性别","年龄","手机号","课程名","分数"
};
table=new JTable();
JScrollPane jScrollPane = new JScrollPane();
jScrollPane.setViewportView(table);
container = new JFrame("Listview");
container.setSize(800,600);
container.setLayout(new BorderLayout());
container.add(jScrollPane,BorderLayout.CENTER);
container.setVisible(true);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
DefaultTableModel tableModel=new DefaultTableModel(List(),columnName);
table.setModel(tableModel);
}
public Object[][] List() {
List<Student> list1= stu.getlist1();
Object[][] data=new Object[list1.size()][columnName.length];
for(int i=0;i<list1.size();i++){
for(int j=0;j<columnName.length;j++){
data[i][0]=list1.get(i).getNum();
data[i][1]=list1.get(i).getName();
data[i][2]=list1.get(i).getCourse();
data[i][3]=list1.get(i).getSex();
data[i][4]=list1.get(i).getAge();
data[i][5]=list1.get(i).getMobile();
data[i][6]=list1.get(i).getGrade();
}
}
return data;
}
}
增删改查的操作就一起给大家送上了,这里并没有什么技术性的难题,大家对于自己的监听事件所理解就可以了(主要运用到set/get方法)
public class Addview extends JFrame implements ActionListener {
JLabel jl1,jl2,jl3,jl4,jl5,jl6,jl7;
JTextField jf1,jf2,jf3,jf4,jf5,jf6,jf7;
JButton jb1,jb2;
StudentDao stu1=new StudentDao();
Student stu2=new Student();
public Addview() {
JFrame frame = new JFrame("新窗口");
this.setSize(420,700);
this.setVisible(true);
this.setLayout(new FlowLayout());
this.setLayout(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jl1 = new JLabel("学号:");
jl2 = new JLabel("姓名:");
jl3 = new JLabel("性别:");
jl4 = new JLabel("年龄:");
jl5 = new JLabel("电话:");
jl6 = new JLabel("课程:");
jl7 = new JLabel("成绩:");
jf1 = new JTextField("");
jf2 = new JTextField();
jf3 = new JTextField();
jf4 = new JTextField();
jf5 = new JTextField();
jf6 = new JTextField();
jf7 = new JTextField();
jb1 = new JButton("添加");
jb2 = new JButton("退出");
this.add(jl1);
this.add(jl2);
this.add(jl3);
this.add(jl4);
this.add(jl5);
this.add(jl6);
this.add(jl7);
this.add(jf1);
this.add(jf2);
this.add(jf3);
this.add(jf4);
this.add(jf5);
this.add(jf6);
this.add(jf7);
this.add(jb1);
this.add(jb2);
jl1.setBounds(25,45,200,100);
jl2.setBounds(25,125,150,100);
jl3.setBounds(25,205,150,100);
jl4.setBounds(25,285,150,100);
jl5.setBounds(25,365,150,100);
jl6.setBounds(25,445,150,100);
jl7.setBounds(25,525,150,100);
jf1.setBounds(75,70,200,50);
jf2.setBounds(75,150,200,50);
jf3.setBounds(75,230,200,50);
jf4.setBounds(75,315,200,50);
jf5.setBounds(75,395,200,50);
jf6.setBounds(75,475,200,50);
jf7.setBounds(75,555,200,50);
jb1.setBounds(300,250,100,100);
jb2.setBounds(300,350,100,100);
jb1.addActionListener(this);
jb2.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==jb1) {
try {
stu2.setNum(jf1.getText());
stu2.setName(jf2.getText());
stu2.setSex(jf3.getText());
stu2.setAge(Integer.parseInt(jf4.getText()));
stu2.setMobile(jf5.getText());
stu2.setCourse(jf6.getText());
stu2.setGrade(jf7.getText());
stu1.add(stu2);
} catch (Exception e1) {
// TODO 自动生成的 catch 块
e1.printStackTrace();
}
}
else if(e.getSource()==jb2) {
this.dispose();
}
}
public class Deleteview extends JFrame implements ActionListener{
JLabel jl1;
JTextField jf1;
JButton jb1,jb2;
StudentDao stu1=new StudentDao();
Student stu2=new Student();
public Deleteview() {
JFrame frame = new JFrame("新窗口");
this.setSize(300,300);
this.setVisible(true);
this.setLayout(new FlowLayout());
this.setLayout(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jl1=new JLabel("删除学生学号:");
jf1=new JTextField();
jb1=new JButton("删除");
jb2=new JButton("退出");
this.add(jf1);
this.add(jl1);
this.add(jb1);
this.add(jb2);
jl1.setBounds(90,30,100,100);
jf1.setBounds(37,100,200,50);
jb1.setBounds(37,160,80,50);
jb2.setBounds(157,160,80,50);
jb1.addActionListener(this);
jb2.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==jb1) {
try {
stu1.delete(jf1.getText());
} catch (Exception e1) {
// TODO 自动生成的 catch 块
e1.printStackTrace();
}
}
else if(e.getSource()==jb2)
{
this.dispose();
}
}
public class Upateview extends JFrame implements ActionListener {
JLabel jl1, jl2, jl3, jl4, jl5, jl6, jl7;
JTextField jf1, jf2, jf3, jf4, jf5, jf6, jf7;
JButton jb1,jb2;
StudentDao stu1 = new StudentDao();
Student stu2 = new Student();
public Upateview() {
JFrame frame = new JFrame("新窗口");
this.setSize(420, 700);
this.setVisible(true);
this.setLayout(new FlowLayout());
this.setLayout(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jl1 = new JLabel("学号:");
jl2 = new JLabel("姓名:");
jl3 = new JLabel("性别:");
jl4 = new JLabel("年龄:");
jl5 = new JLabel("电话:");
jl6 = new JLabel("课程:");
jl7 = new JLabel("成绩:");
jf1 = new JTextField("");
jf2 = new JTextField();
jf3 = new JTextField();
jf4 = new JTextField();
jf5 = new JTextField();
jf6 = new JTextField();
jf7 = new JTextField();
jb1 = new JButton("更新");
jb2 =new JButton("退出");
this.add(jl1);
this.add(jl2);
this.add(jl3);
this.add(jl4);
this.add(jl5);
this.add(jl6);
this.add(jl7);
this.add(jf1);
this.add(jf2);
this.add(jf3);
this.add(jf4);
this.add(jf5);
this.add(jf6);
this.add(jf7);
this.add(jb1);
this.add(jb2);
jl1.setBounds(25, 45, 200, 100);
jl2.setBounds(25, 125, 150, 100);
jl3.setBounds(25, 205, 150, 100);
jl4.setBounds(25, 285, 150, 100);
jl5.setBounds(25, 365, 150, 100);
jl6.setBounds(25, 445, 150, 100);
jl7.setBounds(25, 525, 150, 100);
jf1.setBounds(75, 70, 200, 50);
jf2.setBounds(75, 150, 200, 50);
jf3.setBounds(75, 230, 200, 50);
jf4.setBounds(75, 315, 200, 50);
jf5.setBounds(75, 395, 200, 50);
jf6.setBounds(75, 475, 200, 50);
jf7.setBounds(75, 555, 200, 50);
jb1.setBounds(300, 250, 100, 100);
jb2.setBounds(300,400,100,100);
jb1.addActionListener(this);
jb2.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==jb1)
{
try {
stu2.setNum(jf1.getText());
stu2.setName(jf2.getText());
stu2.setSex(jf3.getText());
stu2.setAge(Integer.parseInt(jf4.getText()));
stu2.setMobile(jf5.getText());
stu2.setCourse(jf6.getText());
stu2.setGrade(jf7.getText());
stu1.upatestu(stu2);
} catch (Exception e1) {
// TODO 自动生成的 catch 块
e1.printStackTrace();
}
}
else if(e.getSource()==jb2)
{
this.dispose();
}
}
public class Getview extends JFrame implements ActionListener{
JLabel jl1;
JTextField jf1;
JButton jb1,jb2;
StudentDao stu1=new StudentDao();
Student stu2=new Student();
public Getview() {
JFrame frame = new JFrame("新窗口");
this.setSize(300,300);
this.setVisible(true);
this.setLayout(new FlowLayout());
this.setLayout(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jl1=new JLabel("查询学生学号:");
jf1=new JTextField();
jb1=new JButton("查询");
jb2 =new JButton("退出");
this.add(jf1);
this.add(jl1);
this.add(jb1);
this.add(jb2);
jl1.setBounds(90,30,100,100);
jf1.setBounds(37,100,200,50);
jb1.setBounds(37,160,80,50);
jb2.setBounds(157,160,80,50);
jb1.addActionListener(this);
jb2.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==jb1) {
try {
stu1.FindById(jf1.getText());
stu2=stu1.FindById(jf1.getText());
System.out.println(" 学号:" + stu2.getNum() + " 姓名:" + stu2.getName() + " 年龄:"+stu2.getAge() +" 性别:" + stu2.getSex()+" 手机号:"+ stu2.getMobile()
+" 课程名:"+ stu2.getCourse()+" 成绩:"+ stu2.getGrade());
} catch (Exception e1) {
// TODO 自动生成的 catch 块
e1.printStackTrace();
}
}
else if(e.getSource()==jb2)
{
this.dispose();
}
}
}
这些就是整个Java课程设计中学生信息管理系统的所有可视化代码了,希望对新手有所帮助,也欢迎大家提出意见批评指正!!
我是王小白,我正在努力学习和上进当中!!!