欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Java GUI制作简单的管理系统

程序员文章站 2023-12-17 18:09:40
本文实例为大家分享了java gui管理系统的具体代码,供大家参考,具体内容如下 1.先完成主页面mainui(代码如下) package com.pag_1;...

本文实例为大家分享了java gui管理系统的具体代码,供大家参考,具体内容如下

1.先完成主页面mainui(代码如下)

package com.pag_1; 
import javax.swing.*; 
import java.awt.*; 
import java.awt.event.actionevent; 
import java.awt.event.actionlistener; 

public class mainui extends jframe implements actionlistener { 

 //定义组件 
 jbutton jb1,jb2,jb3=null; 
 jradiobutton jrb1,jrb2=null; 
 jpanel jp1,jp2,jp3,jp4=null; 
 jtextfield jtf=null; 
 jlabel jlb1,jlb2,jlb3=null; 
 jpasswordfield jpf=null; 
 buttongroup bg=null; 

 //设定用户名和密码 
 final string stu_name="王小明"; 
 final string stu_pwd="1"; 
 final string stu_num="14140301"; 
 final string tea_name="王老师"; 
 final string tea_pwd="1"; 
 final string tea_num="00001"; 

 public static void main(string[] args) { 

  mainui mui=new mainui(); 
 } 
 public mainui() 
 { 
   //创建组件 
  jb1=new jbutton("登录"); 
  jb2=new jbutton("重置"); 
  jb3=new jbutton("退出");

  //设置监听 
  jb1.addactionlistener(this); 
  jb2.addactionlistener(this); 
  jb3.addactionlistener(this); 

  jrb1=new jradiobutton("教师"); 
  jrb2=new jradiobutton("学生"); 
  bg=new buttongroup(); 
  bg.add(jrb1); 
  bg.add(jrb2); 
  jrb2.setselected(true); //初始页面默认选择权限为 学生

  jp1=new jpanel(); 
  jp2=new jpanel(); 
  jp3=new jpanel(); 
  jp4=new jpanel();     

  jlb1=new jlabel("用户名:"); 
  jlb2=new jlabel("密 码:"); 
  jlb3=new jlabel("权 限:"); 

  jtf=new jtextfield(10); 
  jpf=new jpasswordfield(10); 
  //加入到jpanel中 
  jp1.add(jlb1); 
  jp1.add(jtf); 

  jp2.add(jlb2); 
  jp2.add(jpf); 

  jp3.add(jlb3);  //添加标签
  jp3.add(jrb1); 
  jp3.add(jrb2); 

  jp4.add(jb1);  //添加按钮
  jp4.add(jb2); 
  jp4.add(jb3);

  //加入jframe中 
  this.add(jp1); 
  this.add(jp2); 
  this.add(jp3); 
  this.add(jp4); 

  this.setlayout(new gridlayout(4,1));   //选择gridlayout布局管理器  
  this.settitle("学生成绩管理系统");   
  this.setsize(300,200);   
  this.setlocation(400, 200);   
  this.setdefaultcloseoperation(jframe.exit_on_close); //设置当关闭窗口时,保证jvm也退出 
  this.setvisible(true); 
  this.setresizable(true); 

 } 

 public void actionperformed(actionevent e) {   //事件判断

  if(e.getactioncommand()=="登录") 
  { 
   //如果选中教师登录 
   if(jrb1.isselected()) 
   { 
     tealogin();        //连接到教师的方法 页面
   }else if(jrb2.isselected()) //学生在登录系统 
   { 
     stulogin();        //连接到学生的方法 页面
   } 

  }else if(e.getactioncommand()=="重置") 
  { 
     clear(); 
  }    

 } 

  //学生登录判断方法 
 public void stulogin() 
 { 
  if(stu_name.equals(jtf.gettext())&&stu_pwd.equals(jpf.gettext())) 
  {   
   joptionpane.showmessagedialog(null,"登录成功!","提示消息",joptionpane.warning_message);   
   dispose();  
   clear();   
   stdui ui=new stdui();  //创建新界面 
  }else if(jtf.gettext().isempty()&&jpf.gettext().isempty()) 
  { 
   joptionpane.showmessagedialog(null,"请输入用户名和密码!","提示消息",joptionpane.warning_message); 
  }else if(jtf.gettext().isempty()) 
  { 
   joptionpane.showmessagedialog(null,"请输入用户名!","提示消息",joptionpane.warning_message); 
  }else if(jpf.gettext().isempty()) 
  { 
   joptionpane.showmessagedialog(null,"请输入密码!","提示消息",joptionpane.warning_message); 
  }else 
  { 
   joptionpane.showmessagedialog(null,"用户名或者密码错误!\n请重新输入","提示消息",joptionpane.error_message); 
   //清空输入框 
   clear(); 
  } 
 } 
 //教师登录判断方法 
 public void tealogin() 
 { 
  if(tea_name.equals(jtf.gettext())&&tea_pwd.equals(jpf.gettext())) 
  { 

    joptionpane.showmessagedialog(null,"登录成功!","提示消息",joptionpane.warning_message); 
    clear();   
    dispose();    
    terui ui=new terui(); //创建一个新界面 
  }else if(jtf.gettext().isempty()&&jpf.gettext().isempty()) 
  { 
   joptionpane.showmessagedialog(null,"请输入用户名和密码!","提示消息",joptionpane.warning_message); 
  }else if(jtf.gettext().isempty()) 
  { 
   joptionpane.showmessagedialog(null,"请输入用户名!","提示消息",joptionpane.warning_message); 
  }else if(jpf.gettext().isempty()) 
  { 
   joptionpane.showmessagedialog(null,"请输入密码!","提示消息",joptionpane.warning_message); 
  }else 
  { 
   joptionpane.showmessagedialog(null,"用户名或者密码错误!\n请重新输入","提示消息",joptionpane.error_message); 
   clear(); //清空输入框 
  } 
 } 
 //清空文本框和密码框 
 public void clear() 
 { 
  jtf.settext(""); 
  jpf.settext(""); 
 } 

} 

运行图1

Java GUI制作简单的管理系统 

用户名和密码如下:

Java GUI制作简单的管理系统

2.完成学生界面stuui,这个页面在mainui界面设置了按钮连接(代码如下)

package com.pag_1;
import java.awt.*; 
import java.awt.event.*; 
import javax.swing.*; 
import javax.swing.jbutton;
import java.awt.color.*;
import javax.swing.joptionpane;
import com.pag_1.mainui; 
public class stdui extends jframe implements actionlistener 
{ 

   //定义组件 
  jbutton jb1=new jbutton();
  jbutton jb2=new jbutton(); 
  jpanel jp1,jp2,jp3,jp4=null; 
  jlabel jlb1,jlb2,jlb3,jlb4,jlb5,jlb6=null; 

  public static void main(string[] args)
  { 
   stdui ui=new stdui(); 
  } 


  //****************************事件判断**********************

  //构造函数 
  public stdui() //不能申明为void!!!!!否则弹不出新界面 
  { 

   //创建组件 
   jb1=new jbutton("课程表"); 
   jb1.setforeground(color.blue);
   jb2=new jbutton("成绩查询"); 
   jb2.setforeground(color.blue);

   jp1=new jpanel(); 
   jp2=new jpanel(); 
   jp3=new jpanel(); 

   jlb1=new jlabel("姓名:"); 
   jlb2=new jlabel("学号:"); 
   jlb3=new jlabel("最新公告:"); 
   jlb3.setforeground(color.red);
   jlb4=new jlabel("我院举行学生体测通知"); 
   jlb5=new jlabel(new mainui().stu_name);
   jlb6=new jlabel(new mainui().stu_num);

   jp1.add(jlb1); 
   jp1.add(jlb5);
   jp1.add(jlb2); 
   jp1.add(jlb6);


   jp2.add(jb1); 
   jp2.add(jb2); 

   jp3.add(jlb3);
   jp3.add(jlb4); 

   this.add(jp1); 
   this.add(jp2); 
   this.add(jp3); 


   //设置布局管理器 
   this.setlayout(new gridlayout(4,3,50,50)); 
   this.settitle("学生成绩管理系统"); 
   this.setsize(400,300); 
   this.setlocation(200, 200);  

   this.setdefaultcloseoperation(jframe.exit_on_close); 

   this.setvisible(true); 
   jb1.addactionlistener(this);
   jb2.addactionlistener(this);


  }

  public void actionperformed(actionevent e) { 
    if(e.getsource() == jb1){
    //关闭当前界面 
     dispose(); 
     new kechengbiaoui();
    }else if(e.getsource() == jb2){
     //关闭当前界面 
     dispose(); 
     new chengjibiaoui();
    }

  } 
} 

运行mainui输入用户学生,会出现下面学生界面,其中界面中的 课程表和成绩查询是两个可以点击的按钮,会连接到下个页面再后面步骤。

Java GUI制作简单的管理系统

3.完成教师界面terui,这个和学生页面一样,在mainui页面有设置按钮事件,连接到mainui页面.(代码如下)

package com.pag_1;
import java.awt.*; 
import java.awt.event.*; 
import javax.swing.*; 
import javax.swing.jbutton;
import com.pag_1.mainui; 
public class terui extends jframe implements actionlistener 
{ 
   //定义组件 
  jbutton jb1,jb2=null; 
  jpanel jp1,jp2,jp3,jp4=null; 
  jlabel jlb1,jlb2,jlb3,jlb4,jlb5,jlb6=null; 

  public static void main(string[] args) {   
   terui ui=new terui(); 
  } 
  public terui() 
  { 
   //创建组件 
   jb1=new jbutton("课程管理");
   jb1.setforeground(color.blue);
   jb2=new jbutton("学生名单"); 
   jb2.setforeground(color.blue);

   jp1=new jpanel(); 
   jp2=new jpanel(); 
   jp3=new jpanel(); 

   jlb1=new jlabel("姓名:"); 
   jlb2=new jlabel("工号:"); 
   jlb3=new jlabel("最新公告:"); 
   jlb3.setforeground(color.red);
   jlb4=new jlabel("我院举行体测的通知"); 
   jlb5=new jlabel(new mainui().tea_name);
   jlb6=new jlabel(new mainui().tea_num);

   jp1.add(jlb1); 
   jp1.add(jlb5);
   jp1.add(jlb2); 
   jp1.add(jlb6);

   jp2.add(jb1); 
   jp2.add(jb2); 

   jp3.add(jlb3);
   jp3.add(jlb4); 

   this.add(jp1); 
   this.add(jp2); 
   this.add(jp3);   
   this.setlayout(new gridlayout(4,3,50,50)); //设置布局管理器 
   this.settitle("学生成绩管理系统"); 
   this.setsize(400,300); 
   this.setlocation(200, 200);  
   this.setdefaultcloseoperation(jframe.exit_on_close); 
   this.setvisible(true);   
   jb1.addactionlistener(this);
   jb2.addactionlistener(this);
} 
  public void actionperformed(actionevent e) { 
    if(e.getsource() == jb1){    
     dispose(); 
     new kechengguanliui();    //创建一个新界面 
    }else if(e.getsource() == jb2){
     dispose(); 
     new xueshengmingdanui();    //创建一个新界面 
    }

  } 
} 

运行mainui输入用户教师,会出现下面教师界面,其中界面中的 课程管理和学生名单是两个可以点击的按钮,会连接到下个页面再后面步骤。

Java GUI制作简单的管理系统

4.完成学生界面的课程表界面(代码如下)

package com.pag_1;

import javax.swing.jframe;
import javax.swing.jscrollpane;
import javax.swing.jtable;
import javax.swing.table.tablecolumn;

public class kechengbiaoui extends jframe 
{ 

 public kechengbiaoui() 
 { 
  inticomponent(); 
 } 

 private void inticomponent() 
 {  
  string[] columnnames = 
  { "课节数","星期一", "星期二", "星期三", "星期四", "星期五", "星期六","星期日" }; 

  object[][] obj=new object[8][8]; 
  for (int i=0;i<8;i++) 
  { 
   for(int j=0;j<8;j++) 
   { 
    switch (j) 
    { 
    case 0: 
     obj[0][0] = "第一节课";
     obj[0][1] = "光纤通信"; 
     obj[0][2] = "电磁场"; 
     obj[0][3] = "物联网"; 
     obj[0][4] = "dsp实验"; 
     obj[0][5] = " "; 
     obj[0][6] = "手机维修"; 
     obj[0][7] = " "; 
     break; 
    case 1: 
     obj[1][0] = "第二节课";
     obj[1][1] = "光纤通信"; 
     obj[1][2] = "电磁场"; 
     obj[1][3] = "物联网"; 
     obj[1][4] = "dsp实验"; 
     obj[1][5] = " "; 
     obj[1][6] = "手机维修"; 
     obj[1][7] = " "; 
     break; 
    case 2: 
     obj[2][0] = "第三节课";
     obj[2][1] = "android"; 
     obj[2][2] = " "; 
     obj[2][3] = " "; 
     obj[2][4] = "dsp实验"; 
     obj[2][5] = "手机维修"; 
     obj[2][6] = "手机维修"; 
     obj[2][7] = " "; 
     break; 
    case 3: 
     obj[3][0] = "第四节课";
     obj[3][1] = "android"; 
     obj[3][2] = " "; 
     obj[3][3] = " "; 
     obj[3][4] = " "; 
     obj[3][5] = "手机维修"; 
     obj[3][6] = "手机维修"; 
     obj[3][7] = "光纤通信"; 
     break; 
    case 4: 
     obj[4][0] = "第五节课";
     obj[4][1] = "android实验"; 
     obj[4][2] = " "; 
     obj[4][3] = " "; 
     obj[4][4] = " "; 
     obj[4][5] = " "; 
     obj[4][6] = " "; 
     obj[4][7] = " "; 
     break; 
    case 5: 
     obj[5][0] = "第六节课";
     obj[5][1] = "android实验"; 
     obj[5][2] = " "; 
     obj[5][3] = " "; 
     obj[5][4] = " "; 
     obj[5][5] = " "; 
     obj[5][6] = " "; 
     obj[5][7] = " "; 
     break; 
    case 6: 
     obj[6][0] = "第七节课";
     obj[6][1] = "android实验"; 
     obj[6][2] = " "; 
     obj[6][3] = " "; 
     obj[6][4] = " "; 
     obj[6][5] = " "; 
     obj[6][6] = " "; 
     obj[6][7] = " "; 
     break; 
    case 7: 
     obj[7][0] = "第七节课";
     obj[7][1] = ""; 
     obj[7][2] = " "; 
     obj[7][3] = " "; 
     obj[7][4] = " "; 
     obj[7][5] = " "; 
     obj[7][6] = " "; 
     obj[7][7] = " "; 
     break; 
    case 8: 
     obj[8][0] = "第八节课";
     obj[8][1] = " "; 
     obj[8][2] = " "; 
     obj[8][3] = " "; 
     obj[8][4] = " "; 
     obj[8][5] = " "; 
     obj[8][6] = " "; 
     obj[8][7] = " "; 
     break; 
    } 
   } 
  } 

  jtable table=new jtable(obj, columnnames);  
  tablecolumn column=null; 
  int colunms = table.getcolumncount(); 
  for(int i=0;i<colunms;i++) 
  { 
   column = table.getcolumnmodel().getcolumn(i);    
   column.setpreferredwidth(100); 
  }  
  table.setautoresizemode(jtable.auto_resize_off);  
  jscrollpane scroll = new jscrollpane(table); 
  scroll.setsize(300, 50); 

  add(scroll); 

  this.setlocation(450, 200); 
  this.setvisible(true); 
  this.setdefaultcloseoperation(jframe.exit_on_close); 
  this.pack(); 
 } 

 public static void main(string[] args) 
 { 
  new kechengbiaoui(); 
 } 
} 

课程表界面

Java GUI制作简单的管理系统

5.完成学生的成绩查询界面(代码如下)

package com.pag_1;
import javax.swing.jframe;
import javax.swing.jscrollpane;
import javax.swing.jtable;
import javax.swing.table.tablecolumn;

public class chengjibiaoui extends jframe 
{ 

 public chengjibiaoui() 
 { 
  inticomponent(); 
 } 

 //初始化窗体组件 
 private void inticomponent() 
 { 

  string[] columnnames = 
  { "课程数目","课程名称", "学分", "绩点", "分数", "补考" }; //设置jtable的列名 
  object[][] obj=new object[7][7]; 
  for (int i=0;i<7;i++) 
  { 
   for(int j=0;j<7;j++) 
   { 
    switch (j) 
    { 
    case 0: 
     obj[0][0] = "    1";
     obj[0][1] = "   光纤通信"; 
     obj[0][2] = "    2"; 
     obj[0][3] = "    1.5"; 
     obj[0][4] = "    75"; 
     obj[0][5] = "    否"; 


     break; 
    case 1: 
     obj[1][0] = "    2";
     obj[1][1] = "   android"; 
     obj[1][2] = "    2"; 
     obj[1][3] = "    1.8"; 
     obj[1][4] = "    5"; 
     obj[1][5] = "    否"; 

     break; 
    case 2: 
     obj[2][0] = "    3";
     obj[2][1] = "   物联网"; 
     obj[2][2] = "    1.5"; 
     obj[2][3] = "    1.2"; 
     obj[2][4] = "    70"; 
     obj[2][5] = "    否"; 

     break; 
    case 3: 
     obj[3][0] = "    4";
     obj[3][1] = "   电磁场"; 
     obj[3][2] = "    2"; 
     obj[3][3] = "    1.6"; 
     obj[3][4] = "    78"; 
     obj[3][5] = "    否"; 

     break; 
    case 4: 
     obj[4][0] = "    5";
     obj[4][1] = "   手机维修"; 
     obj[4][2] = "    1.0"; 
     obj[4][3] = "    1.0"; 
     obj[4][4] = "    优秀"; 
     obj[4][5] = "    否"; 

     break; 
    case 5: 
     obj[5][0] = "    6";
     obj[5][1] = "    dsp"; 
     obj[5][2] = "    1.0"; 
     obj[5][3] = "    1.0"; 
     obj[5][4] = "    良好"; 
     obj[5][5] = "    否"; 
     break; 
    case 6: 
     obj[6][0] = "    7";
     obj[6][1] = "  通信原理实验"; 
     obj[6][2] = "    1.0"; 
     obj[6][3] = "    1.0"; 
     obj[6][4] = "    良好"; 
     obj[6][5] = "    否"; 
     break; 

    } 
   } 
  } 

  jtable table=new jtable(obj, columnnames); //jtable的其中一种构造方法 
  tablecolumn column=null;     //设置jtable的列默认的宽度和高度 
  int colunms = table.getcolumncount(); 
  for(int i=0;i<colunms;i++) 
  { 
   column = table.getcolumnmodel().getcolumn(i); 
   column.setpreferredwidth(100);   //将每一列的默认宽度设置为100
  } 
  table.setautoresizemode(jtable.auto_resize_off); //设置jtable自动调整列表的状态,此处设置为关闭 
  jscrollpane scroll = new jscrollpane(table); //用jscrollpane装载jtable,这样超出范围的列就可以通过滚动条来查看
  scroll.setsize(300, 50); 

  add(scroll); 

  this.setlocation(450, 200); 
  this.setvisible(true); 
  this.setdefaultcloseoperation(jframe.exit_on_close); 
  this.pack(); 
 } 

 public static void main(string[] args) 
 { 
  new chengjibiaoui(); 
 } 
} 

学生成绩表界面

Java GUI制作简单的管理系统

6.完成教师的课程管理界面(代码如下)

package com.pag_1;

import javax.swing.jframe;
import javax.swing.jscrollpane;
import javax.swing.jtable;
import javax.swing.table.tablecolumn;

public class kechengguanliui extends jframe 
{ 
 public kechengguanliui() 
 { 
  inticomponent(); 
 } 
 private void inticomponent() 
 {   
  string[] columnnames = 
  { "课节数","星期一", "星期二", "星期三", "星期四", "星期五", "星期六","星期日" };   
  object[][] obj=new object[8][8]; 
  for (int i=0;i<8;i++) 
  { 
   for(int j=0;j<8;j++) 
   { 
    switch (j) 
    { 
    case 0: 
     obj[0][0] = " 第一节课";
     obj[0][1] = "  有课"; 
     obj[0][2] = " "; 
     obj[0][3] = " "; 
     obj[0][4] = "  有课"; 
     obj[0][5] = " "; 
     obj[0][6] = ""; 
     obj[0][7] = " "; 
     break; 
    case 1: 
     obj[1][0] = " 第二节课";
     obj[1][1] = "  有课"; 
     obj[1][2] = ""; 
     obj[1][3] = ""; 
     obj[1][4] = "  有课"; 
     obj[1][5] = " "; 
     obj[1][6] = ""; 
     obj[1][7] = " "; 
     break; 
    case 2: 
     obj[2][0] = " 第三节课";
     obj[2][1] = ""; 
     obj[2][2] = " "; 
     obj[2][3] = "  有课"; 
     obj[2][4] = ""; 
     obj[2][5] = ""; 
     obj[2][6] = ""; 
     obj[2][7] = " "; 
     break; 
    case 3: 
     obj[3][0] =" 第四节课";
     obj[3][1] = ""; 
     obj[3][2] = " "; 
     obj[3][3] = "  有课"; 
     obj[3][4] = " "; 
     obj[3][5] = ""; 
     obj[3][6] = ""; 
     obj[3][7] = ""; 
     break; 
    case 4: 
     obj[4][0] =" 第五节课";
     obj[4][1] = ""; 
     obj[4][2] = " "; 
     obj[4][3] = " "; 
     obj[4][4] = " "; 
     obj[4][5] = " "; 
     obj[4][6] = " "; 
     obj[4][7] = " "; 
     break; 
    case 5: 
     obj[5][0] =" 第六节课";
     obj[5][1] = ""; 
     obj[5][2] = " 开会"; 
     obj[5][3] = " "; 
     obj[5][4] = " "; 
     obj[5][5] = " "; 
     obj[5][6] = " "; 
     obj[5][7] = " "; 
     break; 
    case 6: 
     obj[6][0] =" 第七节课";
     obj[6][1] = ""; 
     obj[6][2] = " 有课"; 
     obj[6][3] = " "; 
     obj[6][4] = " 开会"; 
     obj[6][5] = " "; 
     obj[6][6] = " "; 
     obj[6][7] = " "; 
     break; 
    case 7: 
     obj[7][0] =" 第八节课";
     obj[7][1] = ""; 
     obj[7][2] = " 有课 "; 
     obj[7][3] = " "; 
     obj[7][4] = " "; 
     obj[7][5] = " "; 
     obj[7][6] = " "; 
     obj[7][7] = " "; 
     break; 
    } 
   } 
  }   

  jtable table=new jtable(obj, columnnames); 
  tablecolumn column=null; 
  int colunms = table.getcolumncount(); 
  for(int i=0;i<colunms;i++) 
  { 
   column = table.getcolumnmodel().getcolumn(i);    
   column.setpreferredwidth(100); 
  }   
  table.setautoresizemode(jtable.auto_resize_off);  
  jscrollpane scroll = new jscrollpane(table); 
  scroll.setsize(300, 50); 

  add(scroll); 

  this.setlocation(450, 200); 
  this.setvisible(true); 
  this.setdefaultcloseoperation(jframe.exit_on_close); 
  this.pack(); 
 } 

 public static void main(string[] args) 
 { 
  new kechengguanliui(); 
 } 
} 

教师课程管理

Java GUI制作简单的管理系统

7.完成教师页面的学生名单页面(代码如下)

package com.pag_1;
import javax.swing.jframe;
import javax.swing.jscrollpane;
import javax.swing.jtable;
import javax.swing.table.tablecolumn;

public class xueshengmingdanui extends jframe 
{ 

 public xueshengmingdanui() 
 { 
  inticomponent(); 
 } 

  //初始化窗体组件 
 private void inticomponent() 
 { 
  // 设置jtable的列名 
  string[] columnnames = 
  { "学号","姓名", "专业", "班级"}; 
  object[][] obj=new object[7][7]; 
  for (int i=0;i<7;i++) 
  { 
   for(int j=0;j<7;j++) 
   { 
    switch (j) 
    { 
    case 0: 
     obj[0][0] = "  14140301";
     obj[0][1] = "    王小明"; 
     obj[0][2] = "   通信工程"; 
     obj[0][3] = "     2"; 
     break; 
    case 1: 
     obj[1][0] = "  14140302";
     obj[1][1] = "   王雷"; 
     obj[1][2] = "   通信工程"; 
     obj[1][3] = "     2"; 
     break; 
    case 2: 
     obj[2][0] = "  14140303";
     obj[2][1] = "   李芳"; 
     obj[2][2] = "   通信工程"; 
     obj[2][3] = "     2"; 
     break; 
    case 3: 
     obj[3][0] = "  14140304";
     obj[3][1] = "   张三"; 
     obj[3][2] = "   通信工程"; 
     obj[3][3] = "     2";     
     break; 
    case 4: 
     obj[4][0] = "  14140305";
     obj[4][1] = "   李四"; 
     obj[4][2] = "   通信工程"; 
     obj[4][3] = "     2"; 
     break; 
    case 5: 
     obj[5][0] = "  14140306";
     obj[5][1] = "   文宇"; 
     obj[5][2] = "   通信工程"; 
     obj[5][3] = "    2"; 
     break; 
    case 6: 
     obj[6][0] = "  14140307";
     obj[6][1] = "   王飞"; 
     obj[6][2] = "   通信工程"; 
     obj[6][3] = "     2";     
     break; 

    } 
   } 
  } 

  jtable table=new jtable(obj, columnnames); //jtable的其中一种构造方法 
  tablecolumn column=null;     //设置jtable的列默认的宽度和高度 
  int colunms = table.getcolumncount(); 
  for(int i=0;i<colunms;i++) 
  { 
   column = table.getcolumnmodel().getcolumn(i); 
   column.setpreferredwidth(100);   //将每一列的默认宽度设置为100
  } 
  table.setautoresizemode(jtable.auto_resize_off); //设置jtable自动调整列表的状态,此处设置为关闭     
  jscrollpane scroll = new jscrollpane(table); //用jscrollpane装载jtable,这样超出范围的列就可以通过滚动条来查看 
  scroll.setsize(300, 50);   

  add(scroll); 

  this.setlocation(450, 200); 
  this.setvisible(true); 
  this.setdefaultcloseoperation(jframe.exit_on_close); 
  this.pack(); 
 } 

 public static void main(string[] args) 
 { 
  new xueshengmingdanui(); 
 } 
} 

Java GUI制作简单的管理系统

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

上一篇:

下一篇: